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 if( card
->isapnpc_Node
.ln_Name
!= NULL
)
93 FreeVec( card
->isapnpc_Node
.ln_Name
);
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
)
113 struct ISAPNP_Device
* dev
;
115 dev
= AllocVec( sizeof( *dev
), MEMF_PUBLIC
| MEMF_CLEAR
);
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
);
131 NewList( (struct List
*) &dev
->isapnpd_Resources
);
132 InitSemaphore( &dev
->isapnpd_Lock
);
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
)
151 struct ISAPNP_Identifier
* id
;
152 struct ISAPNP_Resource
* r
;
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 );
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
);
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
)
202 struct ISAPNP_ResourceGroup
* rg
;
204 rg
= AllocVec( sizeof( *rg
), MEMF_PUBLIC
| MEMF_CLEAR
);
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
);
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
)
231 struct ISAPNP_ResourceGroup
* child_rg
;
232 struct ISAPNP_Resource
* r
;
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
);
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
)
269 struct ISAPNP_Resource
* r
;
274 case ISAPNP_NT_IRQ_RESOURCE
:
275 size
= sizeof( struct ISAPNP_IRQResource
);
278 case ISAPNP_NT_DMA_RESOURCE
:
279 size
= sizeof( struct ISAPNP_DMAResource
);
282 case ISAPNP_NT_IO_RESOURCE
:
283 size
= sizeof( struct ISAPNP_IOResource
);
286 case ISAPNP_NT_MEMORY_RESOURCE
:
291 r
= AllocVec( size
, MEMF_PUBLIC
| MEMF_CLEAR
);
295 r
->isapnpr_Type
= type
;
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
)
319 // KPrintF( "Nuking resource %ld.\n", r->isapnpr_Type );