Documented GVF_SAVE_VAR alongside other flags, and removed a query/doubt
[AROS.git] / rom / isapnp / isapnp.c
blobbacbfcfb4609bebbea2209396c0708b26f330028
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 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 <aros/asmcall.h>
25 #include <dos/dos.h>
27 #include <proto/exec.h>
28 #include <proto/dos.h>
30 #include <resources/isapnp.h>
32 #include "isapnp_private.h"
33 #include "pnp_structs.h"
35 #define TEMPLATE "SHOWCONFIG/S,SHOWOPTIONS/S" /*,REMOVE/S"*/
37 /******************************************************************************
38 ** Globals ********************************************************************
39 ******************************************************************************/
41 struct DosLibrary* DOSBase = NULL;
42 struct ExecBase* SysBase = NULL;
44 static void
45 ShowCards( BOOL show_options,
46 struct ISAPNPBase* res );
48 static BOOL
49 OpenLibs( void );
51 static void
52 CloseLibs( void );
54 int
55 ResourceEntry( void );
57 /******************************************************************************
58 ** Startup trampoline *********************************************************
59 ******************************************************************************/
61 AROS_UFH3(__startup static int, Start,
62 AROS_UFHA(char *, argstr, A0),
63 AROS_UFHA(ULONG, argsize, D0),
64 AROS_UFHA(struct ExecBase *, sBase, A6))
66 AROS_USERFUNC_INIT
68 SysBase = sBase;
69 return ResourceEntry();
71 AROS_USERFUNC_EXIT
74 /******************************************************************************
75 ** Resource entry *************************************************************
76 ******************************************************************************/
78 int
79 ResourceEntry( void )
81 struct ISAPNPBase* ISAPNPBase;
82 struct RDArgs* rdargs;
83 int rc = -1;
85 struct
87 IPTR m_ShowConfig;
88 IPTR m_ShowOptions;
89 /* IPTR m_Remove;*/
90 } args = { FALSE, FALSE/*, FALSE*/ };
92 if( ! OpenLibs() )
94 CloseLibs();
95 return RETURN_FAIL;
98 ISAPNPBase = (struct ISAPNPBase* ) OpenResource( ISAPNPNAME );
100 if( ISAPNPBase == NULL )
102 Printf( ISAPNPNAME " not found.\n" );
103 CloseLibs();
104 return RETURN_FAIL;
107 rdargs = ReadArgs(TEMPLATE, (IPTR *)&args, NULL);
109 if( rdargs != NULL )
111 if( ! args.m_ShowConfig && args.m_ShowOptions )
113 Printf( "SHOWOPTIONS can only be used together with SHOWCONFIG\n" );
114 rc = RETURN_ERROR;
116 else
118 if( args.m_ShowConfig )
120 ShowCards( args.m_ShowOptions, ISAPNPBase );
121 rc = RETURN_OK;
124 /* if( args.m_Remove )
126 // Dangerous! Only for debugging
128 FreeISAPNPBase( ISAPNPBase );
130 ISAPNPBase->m_ConfigDev->cd_Flags |= CDF_CONFIGME;
131 ISAPNPBase->m_ConfigDev->cd_Driver = NULL;
132 RemResource( ISAPNPBase );
134 rc = RETURN_OK;
138 FreeArgs( rdargs );
141 if( rc == -1 )
143 Printf( "Usage: ISA-PnP [ SHOWCONFIG [ SHOWOPTIONS ] ] [ REMOVE ]\n" );
144 rc = RETURN_ERROR;
148 CloseLibs();
150 return rc;
154 /******************************************************************************
155 ** Prints information about all cards on a serial port terminal ***************
156 ******************************************************************************/
158 static void
159 ShowResource( struct ISAPNP_Resource* resource,
160 struct ISAPNPBase* res )
162 switch( resource->isapnpr_Type )
164 case ISAPNP_NT_IRQ_RESOURCE:
166 struct ISAPNP_IRQResource* r = (struct ISAPNP_IRQResource*) resource;
167 int b;
169 Printf( "IRQ" );
171 for( b = 0; b < 16; ++b )
173 if( r->isapnpirqr_IRQMask & ( 1 << b ) )
175 Printf( " %ld", b );
179 Printf( ", type" );
181 if( r->isapnpirqr_IRQType & ISAPNP_IRQRESOURCE_ITF_HIGH_EDGE )
183 Printf( " +E" );
186 if( r->isapnpirqr_IRQType & ISAPNP_IRQRESOURCE_ITF_LOW_EDGE )
188 Printf( " -E" );
191 if( r->isapnpirqr_IRQType & ISAPNP_IRQRESOURCE_ITF_HIGH_LEVEL )
193 Printf( " +L" );
196 if( r->isapnpirqr_IRQType & ISAPNP_IRQRESOURCE_ITF_LOW_LEVEL )
198 Printf( " -L" );
201 Printf( "\n" );
202 break;
205 case ISAPNP_NT_DMA_RESOURCE:
207 struct ISAPNP_DMAResource* r = (struct ISAPNP_DMAResource*) resource;
208 int b;
210 Printf( "DMA" );
212 for( b = 0; b < 8; ++b )
214 if( r->isapnpdmar_ChannelMask & ( 1 << b ) )
216 Printf( " %ld", b );
220 Printf( ", " );
221 switch( r->isapnpdmar_Flags & ISAPNP_DMARESOURCE_F_TRANSFER_MASK )
223 case ISAPNP_DMARESOURCE_F_TRANSFER_8BIT:
224 Printf( "8" );
225 break;
227 case ISAPNP_DMARESOURCE_F_TRANSFER_BOTH:
228 Printf( "8 and 16" );
229 break;
231 case ISAPNP_DMARESOURCE_F_TRANSFER_16BIT:
232 Printf( "16" );
233 break;
236 Printf( " bit transfer, " );
238 switch( r->isapnpdmar_Flags & ISAPNP_DMARESOURCE_F_SPEED_MASK )
240 case ISAPNP_DMARESOURCE_F_SPEED_COMPATIBLE:
241 Printf( "compatible" );
242 break;
244 case ISAPNP_DMARESOURCE_F_SPEED_TYPE_A:
245 Printf( "type A" );
246 break;
248 case ISAPNP_DMARESOURCE_F_SPEED_TYPE_B:
249 Printf( "type B" );
250 break;
252 case ISAPNP_DMARESOURCE_F_SPEED_TYPE_F:
253 Printf( "type F" );
254 break;
257 Printf( " speed." );
259 if( r->isapnpdmar_Flags & ISAPNP_DMARESOURCE_FF_BUS_MASTER )
261 Printf( " [Bus master]" );
264 if( r->isapnpdmar_Flags & ISAPNP_DMARESOURCE_FF_BYTE_MODE )
266 Printf( " [Byte mode]" );
269 if( r->isapnpdmar_Flags & ISAPNP_DMARESOURCE_FF_WORD_MODE )
271 Printf( " [Word mode]" );
274 Printf( "\n" );
276 break;
280 case ISAPNP_NT_IO_RESOURCE:
282 struct ISAPNP_IOResource* r = (struct ISAPNP_IOResource*) resource;
284 if( r->isapnpior_MinBase == r->isapnpior_MaxBase )
286 Printf( "IO at 0x%04lx, length 0x%02lx.",
287 r->isapnpior_MinBase, r->isapnpior_Length );
289 else
291 Printf( "IO between 0x%04lx and 0x%04lx, length 0x%02lx, %ld byte aligned.",
292 r->isapnpior_MinBase, r->isapnpior_MaxBase, r->isapnpior_Length, r->isapnpior_Alignment );
295 if( ( r->isapnpior_Flags & ISAPNP_IORESOURCE_FF_FULL_DECODE ) == 0 )
297 Printf( " [10 bit decode only]" );
300 Printf( "\n" );
301 break;
305 case ISAPNP_NT_MEMORY_RESOURCE:
306 Printf( "Memory\n" );
307 break;
309 default:
310 Printf( "Unknown resource!" );
311 break;
315 static void
316 ShowResourceGroup( struct ISAPNP_ResourceGroup* resource_group,
317 struct ISAPNPBase* res )
319 struct ISAPNP_Resource* r;
320 struct ISAPNP_ResourceGroup* rg;
322 for( r = (struct ISAPNP_Resource*) resource_group->isapnprg_Resources.mlh_Head;
323 r->isapnpr_MinNode.mln_Succ != NULL;
324 r = (struct ISAPNP_Resource*) r->isapnpr_MinNode.mln_Succ )
326 Printf( " " );
327 ShowResource( r, res );
330 if( resource_group->isapnprg_ResourceGroups.mlh_Head->mln_Succ != NULL )
332 Printf( " One of\n" );
334 for( rg = (struct ISAPNP_ResourceGroup*) resource_group->isapnprg_ResourceGroups.mlh_Head;
335 rg->isapnprg_MinNode.mln_Succ != NULL;
336 rg = (struct ISAPNP_ResourceGroup*) rg->isapnprg_MinNode.mln_Succ )
338 Printf( " {\n" );
339 ShowResourceGroup( rg, res );
340 Printf( " }\n" );
346 static void
347 ShowCards( BOOL show_options,
348 struct ISAPNPBase* res )
350 struct ISAPNP_Card* card;
352 for( card = (struct ISAPNP_Card*) res->m_Cards.lh_Head;
353 card->isapnpc_Node.ln_Succ != NULL;
354 card = (struct ISAPNP_Card*) card->isapnpc_Node.ln_Succ )
356 struct ISAPNP_Device* dev;
358 Printf( "Card %ld: %s%03lx%lx/%ld ('%s')\n",
359 card->isapnpc_CSN,
360 (ULONG) card->isapnpc_ID.isapnpid_Vendor,
361 card->isapnpc_ID.isapnpid_ProductID,
362 card->isapnpc_ID.isapnpid_Revision,
363 card->isapnpc_SerialNumber,
364 card->isapnpc_Node.ln_Name != NULL ? (ULONG) card->isapnpc_Node.ln_Name
365 : (ULONG) "" );
367 Printf( " PnP version: %ld.%ld\n",
368 card->isapnpc_MajorPnPVersion,
369 card->isapnpc_MinorPnPVersion );
371 Printf( " Vendor specific version number: %ld.%ld\n",
372 card->isapnpc_VendorPnPVersion >> 4,
373 card->isapnpc_VendorPnPVersion & 0x0f );
375 for( dev = (struct ISAPNP_Device*) card->isapnpc_Devices.lh_Head;
376 dev->isapnpd_Node.ln_Succ != NULL;
377 dev = (struct ISAPNP_Device*) dev->isapnpd_Node.ln_Succ )
379 struct ISAPNP_Identifier* id;
380 struct ISAPNP_Resource* r;
382 Printf( " Logical device %ld: ",
383 dev->isapnpd_DeviceNumber );
385 for( id = (struct ISAPNP_Identifier*) dev->isapnpd_IDs.mlh_Head;
386 id->isapnpid_MinNode.mln_Succ != NULL;
387 id = (struct ISAPNP_Identifier*) id->isapnpid_MinNode.mln_Succ )
389 Printf( "%s%03lx%lx ",
390 (ULONG) id->isapnpid_Vendor,
391 id->isapnpid_ProductID,
392 id->isapnpid_Revision );
395 if( dev->isapnpd_Node.ln_Name != NULL )
397 Printf( "('%s')", (ULONG) dev->isapnpd_Node.ln_Name );
400 Printf( "\n" );
402 if( dev->isapnpd_SupportedCommands & ISAPNP_DEVICE_SCF_BOOTABLE )
404 Printf( " Device is capable of participating in the boot process.\n" );
407 if( dev->isapnpd_SupportedCommands & ISAPNP_DEVICE_SCF_RANGE_CHECK )
409 Printf( " Device supports IO range checking.\n" );
412 Printf( " Allocated resources:\n" );
414 if( dev->isapnpd_Resources.mlh_Head->mln_Succ != NULL )
416 for( r = (struct ISAPNP_Resource*) dev->isapnpd_Resources.mlh_Head;
417 r->isapnpr_MinNode.mln_Succ != NULL;
418 r = (struct ISAPNP_Resource*) r->isapnpr_MinNode.mln_Succ )
420 Printf( " " );
421 ShowResource( r, res );
424 else
426 Printf( " None.\n" );
429 if( show_options )
431 Printf( " Requested resources:\n" );
432 ShowResourceGroup( dev->isapnpd_Options, res );
438 /******************************************************************************
439 ** OpenLibs *******************************************************************
440 ******************************************************************************/
442 BOOL
443 OpenLibs( void )
445 /* DOS Library */
447 DOSBase = (struct DosLibrary*) OpenLibrary( "dos.library", 37 );
449 if( DOSBase == NULL )
451 return FALSE;
454 return TRUE;
458 /******************************************************************************
459 ** CloseLibs *******************************************************************
460 ******************************************************************************/
462 void
463 CloseLibs( void )
465 CloseLibrary( (struct Library*) DOSBase );
467 DOSBase = NULL;