iPXE
rsdp.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2017 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., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 /**
00027  * @file
00028  *
00029  * ACPI Root System Description Pointer
00030  *
00031  */
00032 
00033 #include <stdint.h>
00034 #include <realmode.h>
00035 #include <bios.h>
00036 #include <ipxe/acpi.h>
00037 #include <ipxe/rsdp.h>
00038 
00039 /** EBDA RSDP maximum segment */
00040 #define RSDP_EBDA_END_SEG 0xa000
00041 
00042 /** Fixed BIOS area RSDP start address */
00043 #define RSDP_BIOS_START 0xe0000
00044 
00045 /** Fixed BIOS area RSDP length */
00046 #define RSDP_BIOS_LEN 0x20000
00047 
00048 /** Stride at which to search for RSDP */
00049 #define RSDP_STRIDE 16
00050 
00051 /**
00052  * Locate ACPI root system description table within a memory range
00053  *
00054  * @v start             Start address to search
00055  * @v len               Length to search
00056  * @ret rsdt            ACPI root system description table, or UNULL
00057  */
00058 static userptr_t rsdp_find_rsdt_range ( userptr_t start, size_t len ) {
00059         static const char signature[8] = RSDP_SIGNATURE;
00060         struct acpi_rsdp rsdp;
00061         userptr_t rsdt;
00062         size_t offset;
00063         uint8_t sum;
00064         unsigned int i;
00065 
00066         /* Search for RSDP */
00067         for ( offset = 0 ; ( ( offset + sizeof ( rsdp ) ) < len ) ;
00068               offset += RSDP_STRIDE ) {
00069 
00070                 /* Check signature and checksum */
00071                 copy_from_user ( &rsdp, start, offset, sizeof ( rsdp ) );
00072                 if ( memcmp ( rsdp.signature, signature,
00073                               sizeof ( signature ) ) != 0 )
00074                         continue;
00075                 for ( sum = 0, i = 0 ; i < sizeof ( rsdp ) ; i++ )
00076                         sum += *( ( ( uint8_t * ) &rsdp ) + i );
00077                 if ( sum != 0 )
00078                         continue;
00079 
00080                 /* Extract RSDT */
00081                 rsdt = phys_to_user ( le32_to_cpu ( rsdp.rsdt ) );
00082                 DBGC ( rsdt, "RSDT %#08lx found via RSDP %#08lx\n",
00083                        user_to_phys ( rsdt, 0 ),
00084                        user_to_phys ( start, offset ) );
00085                 return rsdt;
00086         }
00087 
00088         return UNULL;
00089 }
00090 
00091 /**
00092  * Locate ACPI root system description table
00093  *
00094  * @ret rsdt            ACPI root system description table, or UNULL
00095  */
00096 static userptr_t rsdp_find_rsdt ( void ) {
00097         static userptr_t rsdt;
00098         uint16_t ebda_seg;
00099         userptr_t ebda;
00100         size_t ebda_len;
00101 
00102         /* Return existing RSDT if already found */
00103         if ( rsdt )
00104                 return rsdt;
00105 
00106         /* Search EBDA */
00107         get_real ( ebda_seg, BDA_SEG, BDA_EBDA );
00108         if ( ebda_seg < RSDP_EBDA_END_SEG ) {
00109              ebda = real_to_user ( ebda_seg, 0 );
00110              ebda_len = ( ( RSDP_EBDA_END_SEG - ebda_seg ) * 16 );
00111              rsdt = rsdp_find_rsdt_range ( ebda, ebda_len );
00112              if ( rsdt )
00113                      return rsdt;
00114         }
00115 
00116         /* Search fixed BIOS area */
00117         rsdt = rsdp_find_rsdt_range ( phys_to_user ( RSDP_BIOS_START ),
00118                                       RSDP_BIOS_LEN );
00119         if ( rsdt )
00120                 return rsdt;
00121 
00122         return UNULL;
00123 }
00124 
00125 PROVIDE_ACPI ( rsdp, acpi_find_rsdt, rsdp_find_rsdt );