append modtype to generated makefiles
[AROS.git] / rom / isapnp / pnp_structs.c
blob6c7afd2585d2fd8c1aa821fe0623c68accedab24
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 if( card->isapnpc_Node.ln_Name != NULL )
93 FreeVec( card->isapnpc_Node.ln_Name );
96 FreeVec( card );
98 AROS_LIBFUNC_EXIT
102 /******************************************************************************
103 ** Allocate a device structure ************************************************
104 ******************************************************************************/
106 // You should set isapnpiod_Node.ln_Name. Allocate the string with AllocVec()!
108 AROS_LH0(struct ISAPNP_Device *, ISAPNP_AllocDevice,
109 struct ISAPNPBase *, res, 20, ISAPNP)
111 AROS_LIBFUNC_INIT
113 struct ISAPNP_Device* dev;
115 dev = AllocVec( sizeof( *dev ), MEMF_PUBLIC | MEMF_CLEAR );
117 if( dev != NULL )
119 dev->isapnpd_Node.ln_Type = ISAPNP_NT_DEVICE;
121 NewList( (struct List*) &dev->isapnpd_IDs );
123 dev->isapnpd_Options = ISAPNP_AllocResourceGroup( ISAPNP_RG_PRI_GOOD, res );
125 if( dev->isapnpd_Options == NULL )
127 ISAPNP_FreeDevice( dev, res );
128 dev = NULL;
131 NewList( (struct List*) &dev->isapnpd_Resources );
132 InitSemaphore( &dev->isapnpd_Lock );
135 return dev;
137 AROS_LIBFUNC_EXIT
141 /******************************************************************************
142 ** Deallocate a device structure **********************************************
143 ******************************************************************************/
145 AROS_LH1(void, ISAPNP_FreeDevice,
146 AROS_LHA(struct ISAPNP_Device *, dev, A0),
147 struct ISAPNPBase *, res, 21, ISAPNP)
149 AROS_LIBFUNC_INIT
151 struct ISAPNP_Identifier* id;
152 struct ISAPNP_Resource* r;
154 if( dev == NULL )
156 return;
159 // KPrintF( "Nuking logical device '%s'\n",
160 // dev->isapnpd_Node.ln_Name != NULL ? dev->isapnpd_Node.ln_Name : "" );
163 while( ( id = (struct ISAPNP_Identifier*)
164 RemHead( (struct List*) &dev->isapnpd_IDs ) ) )
166 // KPrintF( "Nuking (compatible) device %s%03lx%lx\n",
167 // id->isapnpid_Vendor, id->isapnpid_ProductID, id->isapnpid_Revision );
169 FreeVec( id );
172 ISAPNP_FreeResourceGroup( dev->isapnpd_Options, res );
174 while( ( r = (struct ISAPNP_Resource*)
175 RemHead( (struct List*) &dev->isapnpd_Resources ) ) )
177 ISAPNP_FreeResource( r, res );
181 if( dev->isapnpd_Node.ln_Name != NULL )
183 FreeVec( dev->isapnpd_Node.ln_Name );
186 FreeVec( dev );
188 AROS_LIBFUNC_EXIT
192 /******************************************************************************
193 ** Allocate a resource group **************************************************
194 ******************************************************************************/
196 AROS_LH1(struct ISAPNP_ResourceGroup *, ISAPNP_AllocResourceGroup,
197 AROS_LHA(UBYTE, pri, D0),
198 struct ISAPNPBase *, res, 22, ISAPNP)
200 AROS_LIBFUNC_INIT
202 struct ISAPNP_ResourceGroup* rg;
204 rg = AllocVec( sizeof( *rg ), MEMF_PUBLIC | MEMF_CLEAR );
206 if( rg != NULL )
208 rg->isapnprg_Type = ISAPNP_NT_RESOURCE_GROUP;
209 rg->isapnprg_Pri = pri;
211 NewList( (struct List*) &rg->isapnprg_Resources );
212 NewList( (struct List*) &rg->isapnprg_ResourceGroups );
215 return rg;
217 AROS_LIBFUNC_EXIT
221 /******************************************************************************
222 ** Deallocate a resource group ************************************************
223 ******************************************************************************/
225 AROS_LH1(void, ISAPNP_FreeResourceGroup,
226 AROS_LHA(struct ISAPNP_ResourceGroup *, rg, A0),
227 struct ISAPNPBase *, res, 23, ISAPNP)
229 AROS_LIBFUNC_INIT
231 struct ISAPNP_ResourceGroup* child_rg;
232 struct ISAPNP_Resource* r;
234 if( rg == NULL )
236 return;
239 // KPrintF( "Nuking resource group.\n" );
241 while( ( r = (struct ISAPNP_Resource*)
242 RemHead( (struct List*) &rg->isapnprg_Resources ) ) )
244 ISAPNP_FreeResource( r, res );
247 while( ( child_rg = (struct ISAPNP_ResourceGroup*)
248 RemHead( (struct List*) &rg->isapnprg_ResourceGroups ) ) )
250 ISAPNP_FreeResourceGroup( child_rg, res );
253 FreeVec( rg );
255 AROS_LIBFUNC_EXIT
259 /******************************************************************************
260 ** Allocate a resource ********************************************************
261 ******************************************************************************/
263 AROS_LH1(struct ISAPNP_Resource *, ISAPNP_AllocResource,
264 AROS_LHA(UBYTE, type, D0),
265 struct ISAPNPBase *, res, 24, ISAPNP)
267 AROS_LIBFUNC_INIT
269 struct ISAPNP_Resource* r;
270 ULONG size;
272 switch( type )
274 case ISAPNP_NT_IRQ_RESOURCE:
275 size = sizeof( struct ISAPNP_IRQResource );
276 break;
278 case ISAPNP_NT_DMA_RESOURCE:
279 size = sizeof( struct ISAPNP_DMAResource );
280 break;
282 case ISAPNP_NT_IO_RESOURCE:
283 size = sizeof( struct ISAPNP_IOResource );
284 break;
286 case ISAPNP_NT_MEMORY_RESOURCE:
287 default:
288 return NULL;
291 r = AllocVec( size, MEMF_PUBLIC | MEMF_CLEAR );
293 if( r != NULL )
295 r->isapnpr_Type = type;
298 return r;
300 AROS_LIBFUNC_EXIT
304 /******************************************************************************
305 ** Deallocate a resource ******************************************************
306 ******************************************************************************/
308 AROS_LH1(void, ISAPNP_FreeResource,
309 AROS_LHA(struct ISAPNP_Resource *, r, A0),
310 struct ISAPNPBase *, res, 25, ISAPNP)
312 AROS_LIBFUNC_INIT
314 if( r == NULL )
316 return;
319 // KPrintF( "Nuking resource %ld.\n", r->isapnpr_Type );
321 FreeVec( r );
323 AROS_LIBFUNC_EXIT