pnpbios.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020 
00021 #include <stdint.h>
00022 #include <string.h>
00023 #include <errno.h>
00024 #include <realmode.h>
00025 #include <pnpbios.h>
00026 
00027 /** @file
00028  *
00029  * PnP BIOS
00030  *
00031  */
00032 
00033 /** PnP BIOS structure */
00034 struct pnp_bios {
00035         /** Signature
00036          *
00037          * Must be equal to @c PNP_BIOS_SIGNATURE
00038          */
00039         uint32_t signature;
00040         /** Version as BCD (e.g. 1.0 is 0x10) */
00041         uint8_t version;
00042         /** Length of this structure */
00043         uint8_t length;
00044         /** System capabilities */
00045         uint16_t control;
00046         /** Checksum */
00047         uint8_t checksum;
00048 } __attribute__ (( packed ));
00049 
00050 /** Signature for a PnP BIOS structure */
00051 #define PNP_BIOS_SIGNATURE \
00052         ( ( '$' << 0 ) + ( 'P' << 8 ) + ( 'n' << 16 ) + ( 'P' << 24 ) )
00053 
00054 /**
00055  * Test address for PnP BIOS structure
00056  *
00057  * @v offset            Offset within BIOS segment to test
00058  * @ret rc              Return status code
00059  */
00060 static int is_pnp_bios ( unsigned int offset ) {
00061         union {
00062                 struct pnp_bios pnp_bios;
00063                 uint8_t bytes[256]; /* 256 is maximum length possible */
00064         } u;
00065         size_t len;
00066         unsigned int i;
00067         uint8_t sum = 0;
00068 
00069         /* Read start of header and verify signature */
00070         copy_from_real ( &u.pnp_bios, BIOS_SEG, offset, sizeof ( u.pnp_bios ));
00071         if ( u.pnp_bios.signature != PNP_BIOS_SIGNATURE )
00072                 return -EINVAL;
00073 
00074         /* Read whole header and verify checksum */
00075         len = u.pnp_bios.length;
00076         copy_from_real ( &u.bytes, BIOS_SEG, offset, len );
00077         for ( i = 0 ; i < len ; i++ ) {
00078                 sum += u.bytes[i];
00079         }
00080         if ( sum != 0 )
00081                 return -EINVAL;
00082 
00083         DBG ( "Found PnP BIOS at %04x:%04x\n", BIOS_SEG, offset );
00084 
00085         return 0;
00086 }
00087 
00088 /**
00089  * Locate Plug-and-Play BIOS
00090  *
00091  * @ret pnp_offset      Offset of PnP BIOS structure within BIOS segment
00092  *
00093  * The PnP BIOS structure will be at BIOS_SEG:pnp_offset.  If no PnP
00094  * BIOS is found, -1 is returned.
00095  */
00096 int find_pnp_bios ( void ) {
00097         static int pnp_offset = 0;
00098 
00099         if ( pnp_offset )
00100                 return pnp_offset;
00101 
00102         for ( pnp_offset = 0 ; pnp_offset < 0x10000 ; pnp_offset += 0x10 ) {
00103                 if ( is_pnp_bios ( pnp_offset ) == 0 )
00104                         return pnp_offset;
00105         }
00106 
00107         pnp_offset = -1;
00108         return pnp_offset;
00109 }

Generated on Tue Apr 6 20:00:49 2010 for gPXE by  doxygen 1.5.7.1