sfdc: experimental extension which creates
[AROS.git] / rom / isapnp / pnp_structs.c
blobb1641a273038c56f75f62e06e72f5b892dd3f8af
1 /* $Id$ */
3 /*
4 ISA-PnP -- A Plug And Play ISA software layer for AmigaOS.
5 Copyright (C) 2001 Martin Blom <martin@blom.org>
6 Copyright (C) 2009-2013 The AROS Development Team
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public
19 License along with this library; if not, write to the
20 Free Software Foundation, Inc., 59 Temple Place - Suite 330, Cambridge,
21 MA 02139, USA.
24 #include "CompilerSpecific.h"
26 #include <exec/memory.h>
28 #include <clib/alib_protos.h>
29 #include <proto/exec.h>
31 #include <resources/isapnp.h>
32 #include "isapnp_private.h"
34 #include "init.h"
35 #include "pnp_structs.h"
37 /******************************************************************************
38 ** Allocate a card structure **************************************************
39 ******************************************************************************/
41 // You should set isapnpc_Node.ln_Name. Allocate the string with AllocVec()!
43 AROS_LH0(struct ISAPNP_Card *, ISAPNP_AllocCard,
44 struct ISAPNPBase *, res, 18, ISAPNP)
46 AROS_LIBFUNC_INIT
48 struct ISAPNP_Card* card;
50 card = AllocVec( sizeof( *card ), MEMF_PUBLIC | MEMF_CLEAR );
52 if( card != NULL )
54 card->isapnpc_Node.ln_Type = ISAPNP_NT_CARD;
56 NewList( &card->isapnpc_Devices );
57 InitSemaphore( &card->isapnpc_Lock );
60 return card;
62 AROS_LIBFUNC_EXIT
65 /******************************************************************************
66 ** Deallocate a card structure ************************************************
67 ******************************************************************************/
69 AROS_LH1(void, ISAPNP_FreeCard,
70 AROS_LHA(struct ISAPNP_Card *, card, A0),
71 struct ISAPNPBase *, res, 19, ISAPNP)
73 AROS_LIBFUNC_INIT
75 struct ISAPNP_Device* dev;
77 if( card == NULL )
79 return;
82 // KPrintF( "Nuking card %s%03lx%lx ('%s')\n",
83 // card->isapnpc_ID.isapnpid_Vendor, card->isapnpc_ID.isapnpid_ProductID, card->isapnpc_ID.isapnpid_Revision,
84 // card->isapnpc_Node.ln_Name != NULL ? card->isapnpc_Node.ln_Name : "" );
86 while( ( dev = (struct ISAPNP_Device*) RemHead( &card->isapnpc_Devices ) ) )
88 ISAPNP_FreeDevice( dev, res );
91 FreeVec( card->isapnpc_Node.ln_Name );
93 FreeVec( card );
95 AROS_LIBFUNC_EXIT
99 /******************************************************************************
100 ** Allocate a device structure ************************************************
101 ******************************************************************************/
103 // You should set isapnpiod_Node.ln_Name. Allocate the string with AllocVec()!
105 AROS_LH0(struct ISAPNP_Device *, ISAPNP_AllocDevice,
106 struct ISAPNPBase *, res, 20, ISAPNP)
108 AROS_LIBFUNC_INIT
110 struct ISAPNP_Device* dev;
112 dev = AllocVec( sizeof( *dev ), MEMF_PUBLIC | MEMF_CLEAR );
114 if( dev != NULL )
116 dev->isapnpd_Node.ln_Type = ISAPNP_NT_DEVICE;
118 NewList( (struct List*) &dev->isapnpd_IDs );
120 dev->isapnpd_Options = ISAPNP_AllocResourceGroup( ISAPNP_RG_PRI_GOOD, res );
122 if( dev->isapnpd_Options == NULL )
124 ISAPNP_FreeDevice( dev, res );
125 dev = NULL;
128 NewList( (struct List*) &dev->isapnpd_Resources );
129 InitSemaphore( &dev->isapnpd_Lock );
132 return dev;
134 AROS_LIBFUNC_EXIT
138 /******************************************************************************
139 ** Deallocate a device structure **********************************************
140 ******************************************************************************/
142 AROS_LH1(void, ISAPNP_FreeDevice,
143 AROS_LHA(struct ISAPNP_Device *, dev, A0),
144 struct ISAPNPBase *, res, 21, ISAPNP)
146 AROS_LIBFUNC_INIT
148 struct ISAPNP_Identifier* id;
149 struct ISAPNP_Resource* r;
151 if( dev == NULL )
153 return;
156 // KPrintF( "Nuking logical device '%s'\n",
157 // dev->isapnpd_Node.ln_Name != NULL ? dev->isapnpd_Node.ln_Name : "" );
160 while( ( id = (struct ISAPNP_Identifier*)
161 RemHead( (struct List*) &dev->isapnpd_IDs ) ) )
163 // KPrintF( "Nuking (compatible) device %s%03lx%lx\n",
164 // id->isapnpid_Vendor, id->isapnpid_ProductID, id->isapnpid_Revision );
166 FreeVec( id );
169 ISAPNP_FreeResourceGroup( dev->isapnpd_Options, res );
171 while( ( r = (struct ISAPNP_Resource*)
172 RemHead( (struct List*) &dev->isapnpd_Resources ) ) )
174 ISAPNP_FreeResource( r, res );
178 FreeVec( dev->isapnpd_Node.ln_Name );
179 FreeVec( dev );
181 AROS_LIBFUNC_EXIT
185 /******************************************************************************
186 ** Allocate a resource group **************************************************
187 ******************************************************************************/
189 AROS_LH1(struct ISAPNP_ResourceGroup *, ISAPNP_AllocResourceGroup,
190 AROS_LHA(UBYTE, pri, D0),
191 struct ISAPNPBase *, res, 22, ISAPNP)
193 AROS_LIBFUNC_INIT
195 struct ISAPNP_ResourceGroup* rg;
197 rg = AllocVec( sizeof( *rg ), MEMF_PUBLIC | MEMF_CLEAR );
199 if( rg != NULL )
201 rg->isapnprg_Type = ISAPNP_NT_RESOURCE_GROUP;
202 rg->isapnprg_Pri = pri;
204 NewList( (struct List*) &rg->isapnprg_Resources );
205 NewList( (struct List*) &rg->isapnprg_ResourceGroups );
208 return rg;
210 AROS_LIBFUNC_EXIT
214 /******************************************************************************
215 ** Deallocate a resource group ************************************************
216 ******************************************************************************/
218 AROS_LH1(void, ISAPNP_FreeResourceGroup,
219 AROS_LHA(struct ISAPNP_ResourceGroup *, rg, A0),
220 struct ISAPNPBase *, res, 23, ISAPNP)
222 AROS_LIBFUNC_INIT
224 struct ISAPNP_ResourceGroup* child_rg;
225 struct ISAPNP_Resource* r;
227 if( rg == NULL )
229 return;
232 // KPrintF( "Nuking resource group.\n" );
234 while( ( r = (struct ISAPNP_Resource*)
235 RemHead( (struct List*) &rg->isapnprg_Resources ) ) )
237 ISAPNP_FreeResource( r, res );
240 while( ( child_rg = (struct ISAPNP_ResourceGroup*)
241 RemHead( (struct List*) &rg->isapnprg_ResourceGroups ) ) )
243 ISAPNP_FreeResourceGroup( child_rg, res );
246 FreeVec( rg );
248 AROS_LIBFUNC_EXIT
252 /******************************************************************************
253 ** Allocate a resource ********************************************************
254 ******************************************************************************/
256 AROS_LH1(struct ISAPNP_Resource *, ISAPNP_AllocResource,
257 AROS_LHA(UBYTE, type, D0),
258 struct ISAPNPBase *, res, 24, ISAPNP)
260 AROS_LIBFUNC_INIT
262 struct ISAPNP_Resource* r;
263 ULONG size;
265 switch( type )
267 case ISAPNP_NT_IRQ_RESOURCE:
268 size = sizeof( struct ISAPNP_IRQResource );
269 break;
271 case ISAPNP_NT_DMA_RESOURCE:
272 size = sizeof( struct ISAPNP_DMAResource );
273 break;
275 case ISAPNP_NT_IO_RESOURCE:
276 size = sizeof( struct ISAPNP_IOResource );
277 break;
279 case ISAPNP_NT_MEMORY_RESOURCE:
280 default:
281 return NULL;
284 r = AllocVec( size, MEMF_PUBLIC | MEMF_CLEAR );
286 if( r != NULL )
288 r->isapnpr_Type = type;
291 return r;
293 AROS_LIBFUNC_EXIT
297 /******************************************************************************
298 ** Deallocate a resource ******************************************************
299 ******************************************************************************/
301 AROS_LH1(void, ISAPNP_FreeResource,
302 AROS_LHA(struct ISAPNP_Resource *, r, A0),
303 struct ISAPNPBase *, res, 25, ISAPNP)
305 AROS_LIBFUNC_INIT
307 if( r == NULL )
309 return;
312 // KPrintF( "Nuking resource %ld.\n", r->isapnpr_Type );
314 FreeVec( r );
316 AROS_LIBFUNC_EXIT