22
22
//!
23
23
//! **Notes**: <https://wiki.osdev.org/ACPI>
24
24
25
- use aml:: AmlContext ;
26
25
use spin:: Once ;
27
26
28
- use crate :: mem:: paging:: { PhysAddr , VirtAddr } ;
29
-
30
- use crate :: utils:: sync:: { Mutex , MutexGuard } ;
27
+ use crate :: {
28
+ mem:: paging:: { PhysAddr , VirtAddr } ,
29
+ utils:: sync:: { Mutex , MutexGuard } ,
30
+ } ;
31
31
32
32
use self :: { hpet:: Hpet , madt:: Madt , mcfg:: Mcfg , sdt:: Sdt } ;
33
33
@@ -38,8 +38,6 @@ pub mod mcfg;
38
38
pub mod rsdp;
39
39
pub mod sdt;
40
40
41
- static AML_CONTEXT : Once < Mutex < AmlContext > > = Once :: new ( ) ;
42
-
43
41
enum AcpiHeader {
44
42
Rsdt ( & ' static rsdp:: Rsdt < u32 > ) ,
45
43
Xsdt ( & ' static rsdp:: Rsdt < u64 > ) ,
@@ -73,12 +71,19 @@ impl AcpiTable {
73
71
}
74
72
75
73
/// Lookup ACPI table entry with the provided signature.
76
- fn lookup_entry ( & self , signature : & str ) -> Option < & ' static Sdt > {
74
+ pub fn lookup_entry ( & self , signature : & str ) -> Option < & ' static Sdt > {
77
75
match self . header {
78
76
AcpiHeader :: Rsdt ( rsdt) => rsdt. lookup_entry ( signature) ,
79
77
AcpiHeader :: Xsdt ( xsdt) => xsdt. lookup_entry ( signature) ,
80
78
}
81
79
}
80
+
81
+ pub fn revision ( & self ) -> u8 {
82
+ match self . header {
83
+ AcpiHeader :: Rsdt ( rsdt) => rsdt. header . revision ,
84
+ AcpiHeader :: Xsdt ( xsdt) => xsdt. header . revision ,
85
+ }
86
+ }
82
87
}
83
88
84
89
#[ repr( packed) ]
@@ -91,140 +96,21 @@ pub struct GenericAddressStructure {
91
96
pub address : u64 ,
92
97
}
93
98
94
- struct AmlHandler ;
95
-
96
- impl aml:: Handler for AmlHandler {
97
- fn read_u8 ( & self , address : usize ) -> u8 {
98
- log:: trace!( "AML: Reading byte from {:#x}" , address) ;
99
-
100
- unsafe {
101
- PhysAddr :: new ( address as u64 )
102
- . as_hhdm_virt ( )
103
- . as_ptr :: < u8 > ( )
104
- . read_volatile ( )
105
- }
106
- }
107
-
108
- fn read_u16 ( & self , _address : usize ) -> u16 {
109
- todo ! ( )
110
- }
111
-
112
- fn read_u32 ( & self , _address : usize ) -> u32 {
113
- todo ! ( )
114
- }
115
-
116
- fn read_u64 ( & self , _address : usize ) -> u64 {
117
- todo ! ( )
118
- }
119
-
120
- fn write_u8 ( & mut self , _address : usize , _value : u8 ) {
121
- todo ! ( )
122
- }
123
-
124
- fn write_u16 ( & mut self , _address : usize , _value : u16 ) {
125
- todo ! ( )
126
- }
127
-
128
- fn write_u32 ( & mut self , _address : usize , _value : u32 ) {
129
- todo ! ( )
130
- }
131
-
132
- fn write_u64 ( & mut self , _address : usize , _value : u64 ) {
133
- todo ! ( )
134
- }
135
-
136
- fn read_io_u8 ( & self , _port : u16 ) -> u8 {
137
- todo ! ( )
138
- }
139
-
140
- fn read_io_u16 ( & self , _port : u16 ) -> u16 {
141
- todo ! ( )
142
- }
143
-
144
- fn read_io_u32 ( & self , _port : u16 ) -> u32 {
145
- todo ! ( )
146
- }
99
+ static ACPI_TABLE : Once < Mutex < AcpiTable > > = Once :: new ( ) ;
147
100
148
- fn write_io_u8 ( & self , _port : u16 , _value : u8 ) {
149
- todo ! ( )
150
- }
151
-
152
- fn write_io_u16 ( & self , _port : u16 , _value : u16 ) {
153
- todo ! ( )
154
- }
155
-
156
- fn write_io_u32 ( & self , _port : u16 , _value : u32 ) {
157
- todo ! ( )
158
- }
159
-
160
- fn read_pci_u8 ( & self , _segment : u16 , _bus : u8 , _device : u8 , _unction : u8 , _offset : u16 ) -> u8 {
161
- todo ! ( )
162
- }
163
-
164
- fn read_pci_u16 (
165
- & self ,
166
- _segment : u16 ,
167
- _bus : u8 ,
168
- _device : u8 ,
169
- _function : u8 ,
170
- _offset : u16 ,
171
- ) -> u16 {
172
- todo ! ( )
173
- }
174
-
175
- fn read_pci_u32 (
176
- & self ,
177
- _segment : u16 ,
178
- _bus : u8 ,
179
- _device : u8 ,
180
- _function : u8 ,
181
- _offset : u16 ,
182
- ) -> u32 {
183
- todo ! ( )
184
- }
185
-
186
- fn write_pci_u8 (
187
- & self ,
188
- _segment : u16 ,
189
- _bus : u8 ,
190
- _device : u8 ,
191
- _function : u8 ,
192
- _offset : u16 ,
193
- _value : u8 ,
194
- ) {
195
- todo ! ( )
196
- }
197
-
198
- fn write_pci_u16 (
199
- & self ,
200
- _segment : u16 ,
201
- _bus : u8 ,
202
- _device : u8 ,
203
- _function : u8 ,
204
- _offset : u16 ,
205
- _value : u16 ,
206
- ) {
207
- todo ! ( )
208
- }
209
-
210
- fn write_pci_u32 (
211
- & self ,
212
- _segment : u16 ,
213
- _bus : u8 ,
214
- _device : u8 ,
215
- _function : u8 ,
216
- _offset : u16 ,
217
- _value : u32 ,
218
- ) {
219
- todo ! ( )
220
- }
101
+ pub fn get_acpi_table ( ) -> MutexGuard < ' static , AcpiTable > {
102
+ ACPI_TABLE . get ( ) . unwrap ( ) . lock ( )
221
103
}
222
104
223
105
/// Initialize the ACPI tables.
224
- pub fn init ( rsdp_address : PhysAddr ) -> Result < ( ) , aml :: AmlError > {
106
+ pub fn init ( rsdp_address : PhysAddr ) {
225
107
let rsdp_address = rsdp_address. as_hhdm_virt ( ) ;
226
108
let acpi_table = AcpiTable :: new ( rsdp_address) ;
227
109
110
+ ACPI_TABLE . call_once ( || Mutex :: new ( acpi_table) ) ;
111
+
112
+ let acpi_table = get_acpi_table ( ) ;
113
+
228
114
macro init_table( $sig: path => $ty: ty) {
229
115
if let Some ( table) = acpi_table. lookup_entry ( $sig) {
230
116
<$ty>:: new ( table) ;
@@ -233,7 +119,7 @@ pub fn init(rsdp_address: PhysAddr) -> Result<(), aml::AmlError> {
233
119
234
120
if let Some ( header) = acpi_table. lookup_entry ( mcfg:: SIGNATURE ) {
235
121
unsafe {
236
- let mcfg: & ' static Mcfg = header. as_ptr ( ) ;
122
+ let mcfg: & ' static Mcfg = header. as_ref ( ) ;
237
123
mcfg. init ( ) ;
238
124
}
239
125
}
@@ -247,44 +133,11 @@ pub fn init(rsdp_address: PhysAddr) -> Result<(), aml::AmlError> {
247
133
header. data_len( )
248
134
) ;
249
135
} else {
250
- let madt: & ' static Madt = header. as_ptr ( ) ;
136
+ let madt: & ' static Madt = header. as_ref ( ) ;
251
137
madt. init ( ) ;
252
138
}
253
139
}
254
140
}
255
141
256
142
init_table ! ( hpet:: SIGNATURE => Hpet ) ;
257
-
258
- let aml_context = AmlContext :: new ( box AmlHandler , aml:: DebugVerbosity :: None ) ;
259
-
260
- if let Some ( fadt) = acpi_table. lookup_entry ( fadt:: SIGNATURE ) {
261
- let fadt: & ' static fadt:: Fadt = unsafe { fadt. as_ptr ( ) } ;
262
-
263
- // The DSDT table is put inside the FADT table, instead of listing it in another ACPI table. So
264
- // we need to extract the DSDT table from the FADT table.
265
- let _dsdt_stream = unsafe {
266
- let addr = PhysAddr :: new ( fadt. dsdt as u64 ) . as_hhdm_virt ( ) ;
267
- let sdt = Sdt :: from_address ( addr) ;
268
-
269
- core:: slice:: from_raw_parts ( sdt. data_address ( ) as * mut u8 , sdt. data_len ( ) )
270
- } ;
271
-
272
- // aml_context.parse_table(dsdt_stream)?;
273
- }
274
-
275
- // let pci_router =
276
- // PciRoutingTable::from_prt_path(&AmlName::from_str("\\_SB.PCI0._PRT")?, &mut aml_context)?;
277
-
278
- // drivers::pci::init_pci_router(pci_router);
279
-
280
- AML_CONTEXT . call_once ( move || Mutex :: new ( aml_context) ) ;
281
- Ok ( ( ) )
282
- }
283
-
284
- /// Returns an immutable reference to the AML context.
285
- pub fn get_aml_context ( ) -> MutexGuard < ' static , AmlContext > {
286
- AML_CONTEXT
287
- . get ( )
288
- . expect ( "attempted to get AML context before the ACPI initialization" )
289
- . lock ( )
290
143
}
0 commit comments