1 /* $Id: pnp_structs.c,v 1.5 2001/05/07 12:32:42 lcs Exp $ */
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,
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"
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
);
51 card
->isapnpc_Node
.ln_Type
= ISAPNP_NT_CARD
;
53 NewList( &card
->isapnpc_Devices
);
54 InitSemaphore( &card
->isapnpc_Lock
);
60 /******************************************************************************
61 ** Deallocate a card structure ************************************************
62 ******************************************************************************/
65 ISAPNP_FreeCard( REG( a0
, struct ISAPNP_Card
* card
),
66 REG( a6
, struct ISAPNPBase
* res
) )
68 struct ISAPNP_Device
* dev
;
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
);
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
);
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
);
120 NewList( (struct List
*) &dev
->isapnpd_Resources
);
121 InitSemaphore( &dev
->isapnpd_Lock
);
128 /******************************************************************************
129 ** Deallocate a device structure **********************************************
130 ******************************************************************************/
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
;
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 );
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
);
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
);
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
);
200 /******************************************************************************
201 ** Deallocate a resource group ************************************************
202 ******************************************************************************/
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
;
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
);
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
;
247 case ISAPNP_NT_IRQ_RESOURCE
:
248 size
= sizeof( struct ISAPNP_IRQResource
);
251 case ISAPNP_NT_DMA_RESOURCE
:
252 size
= sizeof( struct ISAPNP_DMAResource
);
255 case ISAPNP_NT_IO_RESOURCE
:
256 size
= sizeof( struct ISAPNP_IOResource
);
259 case ISAPNP_NT_MEMORY_RESOURCE
:
264 r
= AllocVec( size
, MEMF_PUBLIC
| MEMF_CLEAR
);
268 r
->isapnpr_Type
= type
;
275 /******************************************************************************
276 ** Deallocate a resource ******************************************************
277 ******************************************************************************/
280 ISAPNP_FreeResource( REG( a0
, struct ISAPNP_Resource
* r
),
281 REG( a6
, struct ISAPNPBase
* res
) )
288 // KPrintF( "Nuking resource %ld.\n", r->isapnpr_Type );