Added missing properties.
[AROS.git] / rom / isapnp / pnp_structs.c
blob0b05f7766a8cf4df8d593f19bade838463c8472d
1 /* $Id$ */
3 /*
4 ISA-PnP -- A Plug And Play ISA software layer for AmigaOS.
5 Copyright (C) 2001 Martin Blom <martin@blom.org>
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with this library; if not, write to the
19 Free Software Foundation, Inc., 59 Temple Place - Suite 330, Cambridge,
20 MA 02139, USA.
23 #include "CompilerSpecific.h"
25 #include <exec/memory.h>
27 #include <clib/alib_protos.h>
28 #include <proto/exec.h>
30 #include <resources/isapnp.h>
31 #include "isapnp_private.h"
33 #include "init.h"
34 #include "pnp_structs.h"
36 /******************************************************************************
37 ** Allocate a card structure **************************************************
38 ******************************************************************************/
40 // You should set isapnpc_Node.ln_Name. Allocate the string with AllocVec()!
42 struct ISAPNP_Card* ASMCALL
43 ISAPNP_AllocCard( REG( a6, struct ISAPNPBase* res ) )
45 struct ISAPNP_Card* card;
47 card = AllocVec( sizeof( *card ), MEMF_PUBLIC | MEMF_CLEAR );
49 if( card != NULL )
51 card->isapnpc_Node.ln_Type = ISAPNP_NT_CARD;
53 NewList( &card->isapnpc_Devices );
54 InitSemaphore( &card->isapnpc_Lock );
57 return card;
60 /******************************************************************************
61 ** Deallocate a card structure ************************************************
62 ******************************************************************************/
64 void ASMCALL
65 ISAPNP_FreeCard( REG( a0, struct ISAPNP_Card* card ),
66 REG( a6, struct ISAPNPBase* res ) )
68 struct ISAPNP_Device* dev;
70 if( card == NULL )
72 return;
75 // KPrintF( "Nuking card %s%03lx%lx ('%s')\n",
76 // card->isapnpc_ID.isapnpid_Vendor, card->isapnpc_ID.isapnpid_ProductID, card->isapnpc_ID.isapnpid_Revision,
77 // card->isapnpc_Node.ln_Name != NULL ? card->isapnpc_Node.ln_Name : "" );
79 while( ( dev = (struct ISAPNP_Device*) RemHead( &card->isapnpc_Devices ) ) )
81 ISAPNP_FreeDevice( dev, res );
84 if( card->isapnpc_Node.ln_Name != NULL )
86 FreeVec( card->isapnpc_Node.ln_Name );
89 FreeVec( card );
93 /******************************************************************************
94 ** Allocate a device structure ************************************************
95 ******************************************************************************/
97 // You should set isapnpiod_Node.ln_Name. Allocate the string with AllocVec()!
99 struct ISAPNP_Device* ASMCALL
100 ISAPNP_AllocDevice( REG( a6, struct ISAPNPBase* res ) )
102 struct ISAPNP_Device* dev;
104 dev = AllocVec( sizeof( *dev ), MEMF_PUBLIC | MEMF_CLEAR );
106 if( dev != NULL )
108 dev->isapnpd_Node.ln_Type = ISAPNP_NT_DEVICE;
110 NewList( (struct List*) &dev->isapnpd_IDs );
112 dev->isapnpd_Options = ISAPNP_AllocResourceGroup( ISAPNP_RG_PRI_GOOD, res );
114 if( dev->isapnpd_Options == NULL )
116 ISAPNP_FreeDevice( dev, res );
117 dev = NULL;
120 NewList( (struct List*) &dev->isapnpd_Resources );
121 InitSemaphore( &dev->isapnpd_Lock );
124 return dev;
128 /******************************************************************************
129 ** Deallocate a device structure **********************************************
130 ******************************************************************************/
132 void ASMCALL
133 ISAPNP_FreeDevice( REG( a0, struct ISAPNP_Device* dev ),
134 REG( a6, struct ISAPNPBase* res ) )
136 struct ISAPNP_Identifier* id;
137 struct ISAPNP_Resource* r;
139 if( dev == NULL )
141 return;
144 // KPrintF( "Nuking logical device '%s'\n",
145 // dev->isapnpd_Node.ln_Name != NULL ? dev->isapnpd_Node.ln_Name : "" );
148 while( ( id = (struct ISAPNP_Identifier*)
149 RemHead( (struct List*) &dev->isapnpd_IDs ) ) )
151 // KPrintF( "Nuking (compatible) device %s%03lx%lx\n",
152 // id->isapnpid_Vendor, id->isapnpid_ProductID, id->isapnpid_Revision );
154 FreeVec( id );
157 ISAPNP_FreeResourceGroup( dev->isapnpd_Options, res );
159 while( ( r = (struct ISAPNP_Resource*)
160 RemHead( (struct List*) &dev->isapnpd_Resources ) ) )
162 ISAPNP_FreeResource( r, res );
166 if( dev->isapnpd_Node.ln_Name != NULL )
168 FreeVec( dev->isapnpd_Node.ln_Name );
171 FreeVec( dev );
175 /******************************************************************************
176 ** Allocate a resource group **************************************************
177 ******************************************************************************/
179 struct ISAPNP_ResourceGroup* ASMCALL
180 ISAPNP_AllocResourceGroup( REG( d0, UBYTE pri ),
181 REG( a6, struct ISAPNPBase* res ) )
183 struct ISAPNP_ResourceGroup* rg;
185 rg = AllocVec( sizeof( *rg ), MEMF_PUBLIC | MEMF_CLEAR );
187 if( rg != NULL )
189 rg->isapnprg_Type = ISAPNP_NT_RESOURCE_GROUP;
190 rg->isapnprg_Pri = pri;
192 NewList( (struct List*) &rg->isapnprg_Resources );
193 NewList( (struct List*) &rg->isapnprg_ResourceGroups );
196 return rg;
200 /******************************************************************************
201 ** Deallocate a resource group ************************************************
202 ******************************************************************************/
204 void ASMCALL
205 ISAPNP_FreeResourceGroup( REG( a0, struct ISAPNP_ResourceGroup* rg ),
206 REG( a6, struct ISAPNPBase* res ) )
208 struct ISAPNP_ResourceGroup* child_rg;
209 struct ISAPNP_Resource* r;
211 if( rg == NULL )
213 return;
216 // KPrintF( "Nuking resource group.\n" );
218 while( ( r = (struct ISAPNP_Resource*)
219 RemHead( (struct List*) &rg->isapnprg_Resources ) ) )
221 ISAPNP_FreeResource( r, res );
224 while( ( child_rg = (struct ISAPNP_ResourceGroup*)
225 RemHead( (struct List*) &rg->isapnprg_ResourceGroups ) ) )
227 ISAPNP_FreeResourceGroup( child_rg, res );
230 FreeVec( rg );
234 /******************************************************************************
235 ** Allocate a resource ********************************************************
236 ******************************************************************************/
238 struct ISAPNP_Resource* ASMCALL
239 ISAPNP_AllocResource( REG( d0, UBYTE type ),
240 REG( a6, struct ISAPNPBase* res ) )
242 struct ISAPNP_Resource* r;
243 ULONG size;
245 switch( type )
247 case ISAPNP_NT_IRQ_RESOURCE:
248 size = sizeof( struct ISAPNP_IRQResource );
249 break;
251 case ISAPNP_NT_DMA_RESOURCE:
252 size = sizeof( struct ISAPNP_DMAResource );
253 break;
255 case ISAPNP_NT_IO_RESOURCE:
256 size = sizeof( struct ISAPNP_IOResource );
257 break;
259 case ISAPNP_NT_MEMORY_RESOURCE:
260 default:
261 return NULL;
264 r = AllocVec( size, MEMF_PUBLIC | MEMF_CLEAR );
266 if( r != NULL )
268 r->isapnpr_Type = type;
271 return r;
275 /******************************************************************************
276 ** Deallocate a resource ******************************************************
277 ******************************************************************************/
279 void ASMCALL
280 ISAPNP_FreeResource( REG( a0, struct ISAPNP_Resource* r ),
281 REG( a6, struct ISAPNPBase* res ) )
283 if( r == NULL )
285 return;
288 // KPrintF( "Nuking resource %ld.\n", r->isapnpr_Type );
290 FreeVec( r );