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,
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"
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
)
48 struct ISAPNP_Card
* card
;
50 card
= AllocVec( sizeof( *card
), MEMF_PUBLIC
| MEMF_CLEAR
);
54 card
->isapnpc_Node
.ln_Type
= ISAPNP_NT_CARD
;
56 NewList( &card
->isapnpc_Devices
);
57 InitSemaphore( &card
->isapnpc_Lock
);
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
)
75 struct ISAPNP_Device
* dev
;
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
);
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
)
110 struct ISAPNP_Device
* dev
;
112 dev
= AllocVec( sizeof( *dev
), MEMF_PUBLIC
| MEMF_CLEAR
);
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
);
128 NewList( (struct List
*) &dev
->isapnpd_Resources
);
129 InitSemaphore( &dev
->isapnpd_Lock
);
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
)
148 struct ISAPNP_Identifier
* id
;
149 struct ISAPNP_Resource
* r
;
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 );
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
);
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
)
195 struct ISAPNP_ResourceGroup
* rg
;
197 rg
= AllocVec( sizeof( *rg
), MEMF_PUBLIC
| MEMF_CLEAR
);
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
);
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
)
224 struct ISAPNP_ResourceGroup
* child_rg
;
225 struct ISAPNP_Resource
* r
;
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
);
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
)
262 struct ISAPNP_Resource
* r
;
267 case ISAPNP_NT_IRQ_RESOURCE
:
268 size
= sizeof( struct ISAPNP_IRQResource
);
271 case ISAPNP_NT_DMA_RESOURCE
:
272 size
= sizeof( struct ISAPNP_DMAResource
);
275 case ISAPNP_NT_IO_RESOURCE
:
276 size
= sizeof( struct ISAPNP_IOResource
);
279 case ISAPNP_NT_MEMORY_RESOURCE
:
284 r
= AllocVec( size
, MEMF_PUBLIC
| MEMF_CLEAR
);
288 r
->isapnpr_Type
= type
;
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
)
312 // KPrintF( "Nuking resource %ld.\n", r->isapnpr_Type );