2 * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 /** PnP BIOS structure */
35 * Must be equal to @c PNP_BIOS_SIGNATURE
38 /** Version as BCD (e.g. 1.0 is 0x10) */
40 /** Length of this structure */
42 /** System capabilities */
46 } __attribute__ (( packed ));
48 /** Signature for a PnP BIOS structure */
49 #define PNP_BIOS_SIGNATURE \
50 ( ( '$' << 0 ) + ( 'P' << 8 ) + ( 'n' << 16 ) + ( 'P' << 24 ) )
53 * Test address for PnP BIOS structure
55 * @v offset Offset within BIOS segment to test
56 * @ret rc Return status code
58 static int is_pnp_bios ( unsigned int offset ) {
60 struct pnp_bios pnp_bios;
61 uint8_t bytes[256]; /* 256 is maximum length possible */
67 /* Read start of header and verify signature */
68 copy_from_real ( &u.pnp_bios, BIOS_SEG, offset, sizeof ( u.pnp_bios ));
69 if ( u.pnp_bios.signature != PNP_BIOS_SIGNATURE )
72 /* Read whole header and verify checksum */
73 len = u.pnp_bios.length;
74 copy_from_real ( &u.bytes, BIOS_SEG, offset, len );
75 for ( i = 0 ; i < len ; i++ ) {
81 DBG ( "Found PnP BIOS at %04x:%04x\n", BIOS_SEG, offset );
87 * Locate Plug-and-Play BIOS
89 * @ret pnp_offset Offset of PnP BIOS structure within BIOS segment
91 * The PnP BIOS structure will be at BIOS_SEG:pnp_offset. If no PnP
92 * BIOS is found, -1 is returned.
94 int find_pnp_bios ( void ) {
95 static int pnp_offset = 0;
100 for ( pnp_offset = 0 ; pnp_offset < 0x10000 ; pnp_offset += 0x10 ) {
101 if ( is_pnp_bios ( pnp_offset ) == 0 )