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
24FILE_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 <string.h>
35#include <realmode.h>
36#include <bios.h>
37#include <ipxe/acpi.h>
38#include <ipxe/rsdp.h>
39
40/** EBDA RSDP maximum segment */
41#define RSDP_EBDA_END_SEG 0xa000
42
43/** Fixed BIOS area RSDP start address */
44#define RSDP_BIOS_START 0xe0000
45
46/** Fixed BIOS area RSDP length */
47#define RSDP_BIOS_LEN 0x20000
48
49/** Stride at which to search for RSDP */
50#define RSDP_STRIDE 16
51
52/**
53 * Locate ACPI root system description table within a memory range
54 *
55 * @v start Start address to search
56 * @v len Length to search
57 * @ret rsdt ACPI root system description table, or NULL
58 */
59static const struct acpi_rsdt * rsdp_find_rsdt_range ( const void *start,
60 size_t len ) {
61 static const char signature[8] = RSDP_SIGNATURE;
62 const struct acpi_rsdp *rsdp;
63 const struct acpi_rsdt *rsdt;
64 size_t offset;
65 uint8_t sum;
66 unsigned int i;
67
68 /* Search for RSDP */
69 for ( offset = 0 ; ( ( offset + sizeof ( *rsdp ) ) < len ) ;
70 offset += RSDP_STRIDE ) {
71
72 /* Check signature and checksum */
73 rsdp = ( start + offset );
74 if ( memcmp ( rsdp->signature, signature,
75 sizeof ( signature ) ) != 0 )
76 continue;
77 for ( sum = 0, i = 0 ; i < sizeof ( *rsdp ) ; i++ )
78 sum += *( ( ( uint8_t * ) rsdp ) + i );
79 if ( sum != 0 )
80 continue;
81
82 /* Extract RSDT */
83 rsdt = phys_to_virt ( le32_to_cpu ( rsdp->rsdt ) );
84 DBGC ( rsdt, "RSDT %#08lx found via RSDP %#08lx\n",
85 virt_to_phys ( rsdt ),
86 ( virt_to_phys ( start ) + offset ) );
87 return rsdt;
88 }
89
90 return NULL;
91}
92
93/**
94 * Locate ACPI root system description table
95 *
96 * @ret rsdt ACPI root system description table, or NULL
97 */
98static const struct acpi_rsdt * rsdp_find_rsdt ( void ) {
99 static const struct acpi_rsdt *rsdt;
100 const void *ebda;
101 uint16_t ebda_seg;
102 size_t ebda_len;
103
104 /* Return existing RSDT if already found */
105 if ( rsdt )
106 return rsdt;
107
108 /* Search EBDA */
109 get_real ( ebda_seg, BDA_SEG, BDA_EBDA );
110 if ( ebda_seg < RSDP_EBDA_END_SEG ) {
111 ebda = real_to_virt ( ebda_seg, 0 );
112 ebda_len = ( ( RSDP_EBDA_END_SEG - ebda_seg ) * 16 );
113 rsdt = rsdp_find_rsdt_range ( ebda, ebda_len );
114 if ( rsdt )
115 return rsdt;
116 }
117
118 /* Search fixed BIOS area */
119 rsdt = rsdp_find_rsdt_range ( phys_to_virt ( RSDP_BIOS_START ),
121 if ( rsdt )
122 return rsdt;
123
124 return NULL;
125}
126
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
u8 signature
CPU signature.
Definition CIB_PRM.h:7
unsigned short uint16_t
Definition stdint.h:11
unsigned char uint8_t
Definition stdint.h:10
#define BDA_SEG
Definition bios.h:6
#define BDA_EBDA
Definition bios.h:7
uint16_t offset
Offset to command line.
Definition bzimage.h:3
ring len
Length.
Definition dwmac.h:226
static EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER * rsdp
ACPI configuration table.
Definition efi_acpi.c:41
#define DBGC(...)
Definition compiler.h:505
uint32_t start
Starting offset.
Definition netvsc.h:1
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define le32_to_cpu(value)
Definition byteswap.h:114
ACPI data structures.
#define RSDP_SIGNATURE
Root System Description Pointer signature.
Definition acpi.h:230
const struct acpi_rsdt * acpi_find_rsdt(void)
Locate ACPI root system description table.
#define PROVIDE_ACPI(_subsys, _api_func, _func)
Provide an ACPI API implementation.
Definition acpi.h:363
#define PROVIDE_ACPI_INLINE(_subsys, _api_func)
Provide a static inline ACPI API implementation.
Definition acpi.h:372
String functions.
#define get_real
Definition libkir.h:151
static __always_inline void * real_to_virt(unsigned int segment, unsigned int offset)
Convert segment:offset address to virtual address.
Definition realmode.h:77
#define RSDP_STRIDE
Stride at which to search for RSDP.
Definition rsdp.c:50
#define RSDP_EBDA_END_SEG
EBDA RSDP maximum segment.
Definition rsdp.c:41
static const struct acpi_rsdt * rsdp_find_rsdt_range(const void *start, size_t len)
Locate ACPI root system description table within a memory range.
Definition rsdp.c:59
static const struct acpi_rsdt * rsdp_find_rsdt(void)
Locate ACPI root system description table.
Definition rsdp.c:98
#define RSDP_BIOS_LEN
Fixed BIOS area RSDP length.
Definition rsdp.c:47
#define RSDP_BIOS_START
Fixed BIOS area RSDP start address.
Definition rsdp.c:44
Standard PC-BIOS ACPI RSDP interface.
static acpi_find(uint32_t signature, unsigned int index)
Locate ACPI table.
Definition rsdp.h:27
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115
Root System Description Pointer.
Definition acpi.h:233
ACPI Root System Description Table (RSDT)
Definition acpi.h:250