소스 검색

[acpi] Make acpi_find_rsdt() a per-platform method

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 년 전
부모
커밋
933e6dadc0

+ 12
- 0
src/arch/arm/include/bits/acpi.h 파일 보기

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_ACPI_H
2
+#define _BITS_ACPI_H
3
+
4
+/** @file
5
+ *
6
+ * ARM-specific ACPI API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#endif /* _BITS_ACPI_H */

+ 14
- 0
src/arch/x86/include/bits/acpi.h 파일 보기

@@ -0,0 +1,14 @@
1
+#ifndef _BITS_ACPI_H
2
+#define _BITS_ACPI_H
3
+
4
+/** @file
5
+ *
6
+ * x86-specific ACPI API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#include <ipxe/rsdp.h>
13
+
14
+#endif /* _BITS_ACPI_H */

+ 18
- 0
src/arch/x86/include/ipxe/rsdp.h 파일 보기

@@ -0,0 +1,18 @@
1
+#ifndef _IPXE_RSDP_H
2
+#define _IPXE_RSDP_H
3
+
4
+/** @file
5
+ *
6
+ * Standard PC-BIOS ACPI RSDP interface
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#ifdef ACPI_RSDP
13
+#define ACPI_PREFIX_rsdp
14
+#else
15
+#define ACPI_PREFIX_rsdp __rsdp_
16
+#endif
17
+
18
+#endif /* _IPXE_RSDP_H */

+ 2
- 16
src/arch/x86/interface/pcbios/acpipwr.c 파일 보기

@@ -26,8 +26,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
26 26
 #include <unistd.h>
27 27
 #include <errno.h>
28 28
 #include <byteswap.h>
29
-#include <realmode.h>
30
-#include <bios.h>
31 29
 #include <ipxe/io.h>
32 30
 #include <ipxe/acpi.h>
33 31
 #include <ipxe/acpipwr.h>
@@ -51,8 +49,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
51 49
  */
52 50
 int acpi_poweroff ( void ) {
53 51
 	struct acpi_fadt fadtab;
54
-	uint16_t ebda;
55
-	userptr_t rsdt;
56 52
 	userptr_t fadt;
57 53
 	unsigned int pm1a_cnt_blk;
58 54
 	unsigned int pm1b_cnt_blk;
@@ -63,18 +59,8 @@ int acpi_poweroff ( void ) {
63 59
 	int s5;
64 60
 	int rc;
65 61
 
66
-	/* Locate EBDA */
67
-	get_real ( ebda, BDA_SEG, BDA_EBDA );
68
-
69
-	/* Locate RSDT */
70
-	rsdt = acpi_find_rsdt ( real_to_user ( ebda, 0 ) );
71
-	if ( ! rsdt ) {
72
-		DBGC ( colour, "ACPI could not find RSDT (EBDA %04x)\n", ebda );
73
-		return -ENOENT;
74
-	}
75
-
76 62
 	/* Locate FADT */
77
-	fadt = acpi_find ( rsdt, FADT_SIGNATURE, 0 );
63
+	fadt = acpi_find ( FADT_SIGNATURE, 0 );
78 64
 	if ( ! fadt ) {
79 65
 		DBGC ( colour, "ACPI could not find FADT\n" );
80 66
 		return -ENOENT;
@@ -88,7 +74,7 @@ int acpi_poweroff ( void ) {
88 74
 	pm1b_cnt = ( pm1b_cnt_blk + ACPI_PM1_CNT );
89 75
 
90 76
 	/* Extract \_S5 from DSDT or any SSDT */
91
-	s5 = acpi_sx ( rsdt, S5_SIGNATURE );
77
+	s5 = acpi_sx ( S5_SIGNATURE );
92 78
 	if ( s5 < 0 ) {
93 79
 		rc = s5;
94 80
 		DBGC ( colour, "ACPI could not extract \\_S5: %s\n",

+ 125
- 0
src/arch/x86/interface/pcbios/rsdp.c 파일 보기

@@ -0,0 +1,125 @@
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
+ */
58
+static userptr_t rsdp_find_rsdt_range ( userptr_t start, size_t len ) {
59
+	static const char signature[8] = RSDP_SIGNATURE;
60
+	struct acpi_rsdp rsdp;
61
+	userptr_t rsdt;
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 */
117
+	rsdt = rsdp_find_rsdt_range ( phys_to_user ( RSDP_BIOS_START ),
118
+				      RSDP_BIOS_LEN );
119
+	if ( rsdt )
120
+		return rsdt;
121
+
122
+	return UNULL;
123
+}
124
+
125
+PROVIDE_ACPI ( rsdp, acpi_find_rsdt, rsdp_find_rsdt );

+ 1
- 0
src/config/defaults/efi.h 파일 보기

@@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
21 21
 #define ENTROPY_EFI
22 22
 #define TIME_EFI
23 23
 #define REBOOT_EFI
24
+#define ACPI_NULL
24 25
 
25 26
 #define DOWNLOAD_PROTO_FILE	/* Local filesystem access */
26 27
 

+ 1
- 0
src/config/defaults/pcbios.h 파일 보기

@@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
21 21
 #define ENTROPY_RTC
22 22
 #define TIME_RTC
23 23
 #define REBOOT_PCBIOS
24
+#define ACPI_RSDP
24 25
 
25 26
 #ifdef __x86_64__
26 27
 #define IOMAP_PAGES

+ 20
- 71
src/core/acpi.c 파일 보기

@@ -57,88 +57,30 @@ void acpi_fix_checksum ( struct acpi_header *acpi ) {
57 57
 	acpi->checksum -= sum;
58 58
 }
59 59
 
60
-/**
61
- * Locate ACPI root system description table within a memory range
62
- *
63
- * @v start		Start address to search
64
- * @v len		Length to search
65
- * @ret rsdt		ACPI root system description table, or UNULL
66
- */
67
-static userptr_t acpi_find_rsdt_range ( userptr_t start, size_t len ) {
68
-	static const char signature[8] = RSDP_SIGNATURE;
69
-	struct acpi_rsdp rsdp;
70
-	userptr_t rsdt;
71
-	size_t offset;
72
-	uint8_t sum;
73
-	unsigned int i;
74
-
75
-	/* Search for RSDP */
76
-	for ( offset = 0 ; ( ( offset + sizeof ( rsdp ) ) < len ) ;
77
-	      offset += RSDP_STRIDE ) {
78
-
79
-		/* Check signature and checksum */
80
-		copy_from_user ( &rsdp, start, offset, sizeof ( rsdp ) );
81
-		if ( memcmp ( rsdp.signature, signature,
82
-			      sizeof ( signature ) ) != 0 )
83
-			continue;
84
-		for ( sum = 0, i = 0 ; i < sizeof ( rsdp ) ; i++ )
85
-			sum += *( ( ( uint8_t * ) &rsdp ) + i );
86
-		if ( sum != 0 )
87
-			continue;
88
-
89
-		/* Extract RSDT */
90
-		rsdt = phys_to_user ( le32_to_cpu ( rsdp.rsdt ) );
91
-		DBGC ( rsdt, "RSDT %#08lx found via RSDP %#08lx\n",
92
-		       user_to_phys ( rsdt, 0 ),
93
-		       user_to_phys ( start, offset ) );
94
-		return rsdt;
95
-	}
96
-
97
-	return UNULL;
98
-}
99
-
100
-/**
101
- * Locate ACPI root system description table
102
- *
103
- * @v ebda		Extended BIOS data area, or UNULL
104
- * @ret rsdt		ACPI root system description table, or UNULL
105
- */
106
-userptr_t acpi_find_rsdt ( userptr_t ebda ) {
107
-	userptr_t rsdt;
108
-
109
-	/* Search EBDA, if applicable */
110
-	if ( ebda ) {
111
-		rsdt = acpi_find_rsdt_range ( ebda, RSDP_EBDA_LEN );
112
-		if ( rsdt )
113
-			return rsdt;
114
-	}
115
-
116
-	/* Search fixed BIOS area */
117
-	rsdt = acpi_find_rsdt_range ( phys_to_user ( RSDP_BIOS_START ),
118
-				      RSDP_BIOS_LEN );
119
-	if ( rsdt )
120
-		return rsdt;
121
-
122
-	return UNULL;
123
-}
124
-
125 60
 /**
126 61
  * Locate ACPI table
127 62
  *
128
- * @v rsdt		ACPI root system description table
129 63
  * @v signature		Requested table signature
130 64
  * @v index		Requested index of table with this signature
131 65
  * @ret table		Table, or UNULL if not found
132 66
  */
133
-userptr_t acpi_find ( userptr_t rsdt, uint32_t signature, unsigned int index ) {
67
+userptr_t acpi_find ( uint32_t signature, unsigned int index ) {
134 68
 	struct acpi_header acpi;
135 69
 	struct acpi_rsdt *rsdtab;
136 70
 	typeof ( rsdtab->entry[0] ) entry;
71
+	userptr_t rsdt;
137 72
 	userptr_t table;
138 73
 	size_t len;
139 74
 	unsigned int count;
140 75
 	unsigned int i;
141 76
 
77
+	/* Locate RSDT */
78
+	rsdt = acpi_find_rsdt();
79
+	if ( ! rsdt ) {
80
+		DBG ( "RSDT not found\n" );
81
+		return UNULL;
82
+	}
83
+
142 84
 	/* Read RSDT header */
143 85
 	copy_from_user ( &acpi, rsdt, 0, sizeof ( acpi ) );
144 86
 	if ( acpi.signature != cpu_to_le32 ( RSDT_SIGNATURE ) ) {
@@ -278,20 +220,27 @@ static int acpi_sx_zsdt ( userptr_t zsdt, uint32_t signature ) {
278 220
 /**
279 221
  * Extract \_Sx value from DSDT/SSDT
280 222
  *
281
- * @v rsdt		ACPI root system description table
282 223
  * @v signature		Signature (e.g. "_S5_")
283 224
  * @ret sx		\_Sx value, or negative error
284 225
  */
285
-int acpi_sx ( userptr_t rsdt, uint32_t signature ) {
226
+int acpi_sx ( uint32_t signature ) {
286 227
 	struct acpi_fadt fadtab;
228
+	userptr_t rsdt;
287 229
 	userptr_t fadt;
288 230
 	userptr_t dsdt;
289 231
 	userptr_t ssdt;
290 232
 	unsigned int i;
291 233
 	int sx;
292 234
 
235
+	/* Locate RSDT */
236
+	rsdt = acpi_find_rsdt();
237
+	if ( ! rsdt ) {
238
+		DBG ( "RSDT not found\n" );
239
+		return -ENOENT;
240
+	}
241
+
293 242
 	/* Try DSDT first */
294
-	fadt = acpi_find ( rsdt, FADT_SIGNATURE, 0 );
243
+	fadt = acpi_find ( FADT_SIGNATURE, 0 );
295 244
 	if ( fadt ) {
296 245
 		copy_from_user ( &fadtab, fadt, 0, sizeof ( fadtab ) );
297 246
 		dsdt = phys_to_user ( fadtab.dsdt );
@@ -301,7 +250,7 @@ int acpi_sx ( userptr_t rsdt, uint32_t signature ) {
301 250
 
302 251
 	/* Try all SSDTs */
303 252
 	for ( i = 0 ; ; i++ ) {
304
-		ssdt = acpi_find ( rsdt, SSDT_SIGNATURE, i );
253
+		ssdt = acpi_find ( SSDT_SIGNATURE, i );
305 254
 		if ( ! ssdt )
306 255
 			break;
307 256
 		if ( ( sx = acpi_sx_zsdt ( ssdt, signature ) ) >= 0 )

+ 3
- 0
src/core/null_acpi.c 파일 보기

@@ -0,0 +1,3 @@
1
+#include <ipxe/acpi.h>
2
+
3
+PROVIDE_ACPI_INLINE ( null, acpi_find_rsdt );

+ 46
- 16
src/include/ipxe/acpi.h 파일 보기

@@ -16,6 +16,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
16 16
 #include <ipxe/interface.h>
17 17
 #include <ipxe/uaccess.h>
18 18
 #include <ipxe/tables.h>
19
+#include <ipxe/api.h>
20
+#include <config/general.h>
19 21
 
20 22
 /**
21 23
  * An ACPI description header
@@ -89,18 +91,6 @@ struct acpi_rsdp {
89 91
 	uint32_t rsdt;
90 92
 } __attribute__ (( packed ));
91 93
 
92
-/** EBDA RSDP length */
93
-#define RSDP_EBDA_LEN 0x400
94
-
95
-/** Fixed BIOS area RSDP start address */
96
-#define RSDP_BIOS_START 0xe0000
97
-
98
-/** Fixed BIOS area RSDP length */
99
-#define RSDP_BIOS_LEN 0x20000
100
-
101
-/** Stride at which to search for RSDP */
102
-#define RSDP_STRIDE 16
103
-
104 94
 /** Root System Description Table (RSDT) signature */
105 95
 #define RSDT_SIGNATURE ACPI_SIGNATURE ( 'R', 'S', 'D', 'T' )
106 96
 
@@ -194,16 +184,56 @@ struct acpi_model {
194 184
 /** Declare an ACPI model */
195 185
 #define __acpi_model __table_entry ( ACPI_MODELS, 01 )
196 186
 
187
+/**
188
+ * Calculate static inline ACPI API function name
189
+ *
190
+ * @v _prefix		Subsystem prefix
191
+ * @v _api_func		API function
192
+ * @ret _subsys_func	Subsystem API function
193
+ */
194
+#define ACPI_INLINE( _subsys, _api_func ) \
195
+	SINGLE_API_INLINE ( ACPI_PREFIX_ ## _subsys, _api_func )
196
+
197
+/**
198
+ * Provide an ACPI API implementation
199
+ *
200
+ * @v _prefix		Subsystem prefix
201
+ * @v _api_func		API function
202
+ * @v _func		Implementing function
203
+ */
204
+#define PROVIDE_ACPI( _subsys, _api_func, _func ) \
205
+	PROVIDE_SINGLE_API ( ACPI_PREFIX_ ## _subsys, _api_func, _func )
206
+
207
+/**
208
+ * Provide a static inline ACPI API implementation
209
+ *
210
+ * @v _prefix		Subsystem prefix
211
+ * @v _api_func		API function
212
+ */
213
+#define PROVIDE_ACPI_INLINE( _subsys, _api_func ) \
214
+	PROVIDE_SINGLE_API_INLINE ( ACPI_PREFIX_ ## _subsys, _api_func )
215
+
216
+/* Include all architecture-independent ACPI API headers */
217
+#include <ipxe/null_acpi.h>
218
+
219
+/* Include all architecture-dependent ACPI API headers */
220
+#include <bits/acpi.h>
221
+
222
+/**
223
+ * Locate ACPI root system description table
224
+ *
225
+ * @ret rsdt		ACPI root system description table, or UNULL
226
+ */
227
+userptr_t acpi_find_rsdt ( void );
228
+
197 229
 extern struct acpi_descriptor *
198 230
 acpi_describe ( struct interface *interface );
199 231
 #define acpi_describe_TYPE( object_type )				\
200 232
 	typeof ( struct acpi_descriptor * ( object_type ) )
201 233
 
202 234
 extern void acpi_fix_checksum ( struct acpi_header *acpi );
203
-extern userptr_t acpi_find_rsdt ( userptr_t ebda );
204
-extern userptr_t acpi_find ( userptr_t rsdt, uint32_t signature,
205
-			     unsigned int index );
206
-extern int acpi_sx ( userptr_t rsdt, uint32_t signature );
235
+extern userptr_t acpi_find ( uint32_t signature, unsigned int index );
236
+extern int acpi_sx ( uint32_t signature );
207 237
 extern void acpi_add ( struct acpi_descriptor *desc );
208 238
 extern void acpi_del ( struct acpi_descriptor *desc );
209 239
 extern int acpi_install ( int ( * install ) ( struct acpi_header *acpi ) );

+ 23
- 0
src/include/ipxe/null_acpi.h 파일 보기

@@ -0,0 +1,23 @@
1
+#ifndef _IPXE_NULL_ACPI_H
2
+#define _IPXE_NULL_ACPI_H
3
+
4
+/** @file
5
+ *
6
+ * Standard do-nothing ACPI interface
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#ifdef ACPI_NULL
13
+#define ACPI_PREFIX_null
14
+#else
15
+#define ACPI_PREFIX_null __null_
16
+#endif
17
+
18
+static inline __always_inline userptr_t
19
+ACPI_INLINE ( null, acpi_find_rsdt ) ( void ) {
20
+	return UNULL;
21
+}
22
+
23
+#endif /* _IPXE_NULL_ACPI_H */

Loading…
취소
저장