iPXE
rsdp.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Michael Brown <mbrown@fensystems.co.uk>.
3  *
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.
8  *
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.
13  *
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., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 /**
27  * @file
28  *
29  * ACPI Root System Description Pointer
30  *
31  */
32 
33 #include <stdint.h>
34 #include <realmode.h>
35 #include <bios.h>
36 #include <ipxe/acpi.h>
37 #include <ipxe/rsdp.h>
38 
39 /** EBDA RSDP maximum segment */
40 #define RSDP_EBDA_END_SEG 0xa000
41 
42 /** Fixed BIOS area RSDP start address */
43 #define RSDP_BIOS_START 0xe0000
44 
45 /** Fixed BIOS area RSDP length */
46 #define RSDP_BIOS_LEN 0x20000
47 
48 /** Stride at which to search for RSDP */
49 #define RSDP_STRIDE 16
50 
51 /**
52  * Locate ACPI root system description table within a memory range
53  *
54  * @v start Start address to search
55  * @v len Length to search
56  * @ret rsdt ACPI root system description table, or UNULL
57  */
59  static const char signature[8] = RSDP_SIGNATURE;
60  struct acpi_rsdp rsdp;
62  size_t offset;
63  uint8_t sum;
64  unsigned int i;
65 
66  /* Search for RSDP */
67  for ( offset = 0 ; ( ( offset + sizeof ( rsdp ) ) < len ) ;
68  offset += RSDP_STRIDE ) {
69 
70  /* Check signature and checksum */
71  copy_from_user ( &rsdp, start, offset, sizeof ( rsdp ) );
72  if ( memcmp ( rsdp.signature, signature,
73  sizeof ( signature ) ) != 0 )
74  continue;
75  for ( sum = 0, i = 0 ; i < sizeof ( rsdp ) ; i++ )
76  sum += *( ( ( uint8_t * ) &rsdp ) + i );
77  if ( sum != 0 )
78  continue;
79 
80  /* Extract RSDT */
81  rsdt = phys_to_user ( le32_to_cpu ( rsdp.rsdt ) );
82  DBGC ( rsdt, "RSDT %#08lx found via RSDP %#08lx\n",
83  user_to_phys ( rsdt, 0 ),
84  user_to_phys ( start, offset ) );
85  return rsdt;
86  }
87 
88  return UNULL;
89 }
90 
91 /**
92  * Locate ACPI root system description table
93  *
94  * @ret rsdt ACPI root system description table, or UNULL
95  */
96 static userptr_t rsdp_find_rsdt ( void ) {
97  static userptr_t rsdt;
98  uint16_t ebda_seg;
99  userptr_t ebda;
100  size_t ebda_len;
101 
102  /* Return existing RSDT if already found */
103  if ( rsdt )
104  return rsdt;
105 
106  /* Search EBDA */
107  get_real ( ebda_seg, BDA_SEG, BDA_EBDA );
108  if ( ebda_seg < RSDP_EBDA_END_SEG ) {
109  ebda = real_to_user ( ebda_seg, 0 );
110  ebda_len = ( ( RSDP_EBDA_END_SEG - ebda_seg ) * 16 );
111  rsdt = rsdp_find_rsdt_range ( ebda, ebda_len );
112  if ( rsdt )
113  return rsdt;
114  }
115 
116  /* Search fixed BIOS area */
118  RSDP_BIOS_LEN );
119  if ( rsdt )
120  return rsdt;
121 
122  return UNULL;
123 }
124 
unsigned short uint16_t
Definition: stdint.h:11
#define le32_to_cpu(value)
Definition: byteswap.h:113
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
Definition: uaccess.h:337
#define get_real
Definition: libkir.h:151
unsigned long user_to_phys(userptr_t userptr, off_t offset)
Convert user pointer to physical address.
#define DBGC(...)
Definition: compiler.h:505
#define RSDP_STRIDE
Stride at which to search for RSDP.
Definition: rsdp.c:49
userptr_t phys_to_user(unsigned long phys_addr)
Convert physical address to user pointer.
#define RSDP_EBDA_END_SEG
EBDA RSDP maximum segment.
Definition: rsdp.c:40
#define RSDP_BIOS_START
Fixed BIOS area RSDP start address.
Definition: rsdp.c:43
uint32_t start
Starting offset.
Definition: netvsc.h:12
u8 signature
Definition: CIB_PRM.h:35
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define RSDP_BIOS_LEN
Fixed BIOS area RSDP length.
Definition: rsdp.c:46
Standard PC-BIOS ACPI RSDP interface.
static userptr_t rsdp_find_rsdt_range(userptr_t start, size_t len)
Locate ACPI root system description table within a memory range.
Definition: rsdp.c:58
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER * rsdp
ACPI configuration table.
Definition: efi_acpi.c:39
ACPI data structures.
unsigned char uint8_t
Definition: stdint.h:10
userptr_t acpi_find_rsdt(void)
Locate ACPI root system description table.
#define BDA_SEG
Definition: bios.h:6
#define RSDP_SIGNATURE
Root System Description Pointer signature.
Definition: acpi.h:78
#define BDA_EBDA
Definition: bios.h:7
#define UNULL
Equivalent of NULL for user pointers.
Definition: uaccess.h:36
uint32_t len
Length.
Definition: ena.h:14
uint32_t rsdt
Physical address of RSDT.
Definition: acpi.h:91
static __always_inline userptr_t real_to_user(unsigned int segment, unsigned int offset)
Convert segment:offset address to user buffer.
Definition: realmode.h:75
Root System Description Pointer.
Definition: acpi.h:81
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:98
static userptr_t rsdp_find_rsdt(void)
Locate ACPI root system description table.
Definition: rsdp.c:96
PROVIDE_ACPI(rsdp, acpi_find_rsdt, rsdp_find_rsdt)
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33