Bladeren bron

Merge branch 'task-async' of akucxy/oceanic into master

Go!
akucxy 1 jaar geleden
bovenliggende
commit
9fb6ab324b
100 gewijzigde bestanden met toevoegingen van 2607 en 23523 verwijderingen
  1. 4 0
      Cargo.toml
  2. 1 1
      h2o/boot/src/outp.rs
  3. 2 2
      h2o/kernel/.cargo/config.toml
  4. 1 1
      h2o/kernel/Cargo.toml
  5. 9 0
      h2o/kernel/entry/x86_64/stub.asm
  6. 9 3
      h2o/kernel/src/cpu/intr/imp.rs
  7. 1 1
      h2o/kernel/src/cpu/time/timer.rs
  8. 1 1
      h2o/kernel/src/cpu/x86_64/intr.rs
  9. 1 5
      h2o/kernel/src/cpu/x86_64/tsc.rs
  10. 1 2
      h2o/kernel/src/kmain.rs
  11. 1 1
      h2o/kernel/src/log.rs
  12. 11 2
      h2o/kernel/src/mem/space.rs
  13. 143 103
      h2o/kernel/src/mem/space/phys.rs
  14. 235 0
      h2o/kernel/src/mem/space/phys/contiguous.rs
  15. 528 0
      h2o/kernel/src/mem/space/phys/extensible.rs
  16. 22 9
      h2o/kernel/src/mem/space/virt.rs
  17. 110 36
      h2o/kernel/src/mem/syscall.rs
  18. 39 11
      h2o/kernel/src/sched/imp.rs
  19. 51 14
      h2o/kernel/src/sched/imp/waiter.rs
  20. 59 17
      h2o/kernel/src/sched/ipc.rs
  21. 62 0
      h2o/kernel/src/sched/ipc/arsc.rs
  22. 10 0
      h2o/kernel/src/sched/ipc/basic.rs
  23. 3 98
      h2o/kernel/src/sched/ipc/channel.rs
  24. 3 97
      h2o/kernel/src/sched/ipc/channel/syscall.rs
  25. 7 4
      h2o/kernel/src/sched/task.rs
  26. 6 2
      h2o/kernel/src/sched/task/boot.rs
  27. 5 3
      h2o/kernel/src/sched/task/ctx.rs
  28. 16 3
      h2o/kernel/src/sched/task/ctx/x86_64.rs
  29. 24 8
      h2o/kernel/src/sched/task/elf.rs
  30. 6 2
      h2o/kernel/src/sched/task/excep.rs
  31. 2 2
      h2o/kernel/src/sched/task/hdl.rs
  32. 16 2
      h2o/kernel/src/sched/task/hdl/node.rs
  33. 2 1
      h2o/kernel/src/sched/task/idle.rs
  34. 8 3
      h2o/kernel/src/sched/task/sm.rs
  35. 19 0
      h2o/kernel/src/sched/task/space.rs
  36. 31 21
      h2o/kernel/src/sched/task/syscall.rs
  37. 47 6
      h2o/kernel/src/sched/task/tid.rs
  38. 1 3
      h2o/kernel/src/sched/wait.rs
  39. 3 3
      h2o/kernel/src/sched/wait/futex.rs
  40. 28 22
      h2o/kernel/src/syscall/user_ptr.rs
  41. 49 102
      h2o/kernel/syscall/channel.json
  42. 61 56
      h2o/kernel/syscall/dispatcher.json
  43. 45 0
      h2o/kernel/syscall/event.json
  44. 59 56
      h2o/kernel/syscall/futex.json
  45. 25 22
      h2o/kernel/syscall/integer.json
  46. 53 48
      h2o/kernel/syscall/interrupt.json
  47. 19 16
      h2o/kernel/syscall/log.json
  48. 274 206
      h2o/kernel/syscall/memory.json
  49. 65 58
      h2o/kernel/syscall/object.json
  50. 85 78
      h2o/kernel/syscall/resource.json
  51. 144 129
      h2o/kernel/syscall/task.json
  52. 44 39
      h2o/kernel/syscall/time.json
  53. 29 33
      h2o/libs/archop/src/x86_64/lock.rs
  54. 0 2
      h2o/libs/collection_ex/src/lib.rs
  55. 3 1
      h2o/libs/minfo/src/lib.rs
  56. 3 1
      h2o/libs/syscall/build.rs
  57. 1 6
      h2o/libs/syscall/src/call.rs
  58. 82 94
      h2o/libs/syscall/src/error.rs
  59. 4 6
      h2o/libs/syscall/src/ipc.rs
  60. 2 0
      h2o/libs/syscall/src/lib.rs
  61. 28 0
      h2o/libs/syscall/src/mem.rs
  62. 1 6
      h2o/libs/syscall/src/stub.rs
  63. 3 3
      h2o/libs/syscall/syscall.ld
  64. 0 9
      h2o/localdep/acpica.h
  65. 0 440
      h2o/localdep/acpica/dispatcher/dsargs.c
  66. 0 418
      h2o/localdep/acpica/dispatcher/dscontrol.c
  67. 0 257
      h2o/localdep/acpica/dispatcher/dsdebug.c
  68. 0 884
      h2o/localdep/acpica/dispatcher/dsfield.c
  69. 0 274
      h2o/localdep/acpica/dispatcher/dsinit.c
  70. 0 934
      h2o/localdep/acpica/dispatcher/dsmethod.c
  71. 0 778
      h2o/localdep/acpica/dispatcher/dsmthdat.c
  72. 0 590
      h2o/localdep/acpica/dispatcher/dsobject.c
  73. 0 840
      h2o/localdep/acpica/dispatcher/dsopcode.c
  74. 0 594
      h2o/localdep/acpica/dispatcher/dspkginit.c
  75. 0 940
      h2o/localdep/acpica/dispatcher/dsutils.c
  76. 0 791
      h2o/localdep/acpica/dispatcher/dswexec.c
  77. 0 625
      h2o/localdep/acpica/dispatcher/dswload.c
  78. 0 763
      h2o/localdep/acpica/dispatcher/dswload2.c
  79. 0 233
      h2o/localdep/acpica/dispatcher/dswscope.c
  80. 0 842
      h2o/localdep/acpica/dispatcher/dswstate.c
  81. 0 341
      h2o/localdep/acpica/events/evevent.c
  82. 0 379
      h2o/localdep/acpica/events/evglock.c
  83. 0 946
      h2o/localdep/acpica/events/evgpe.c
  84. 0 565
      h2o/localdep/acpica/events/evgpeblk.c
  85. 0 469
      h2o/localdep/acpica/events/evgpeinit.c
  86. 0 398
      h2o/localdep/acpica/events/evgpeutil.c
  87. 0 606
      h2o/localdep/acpica/events/evhandler.c
  88. 0 332
      h2o/localdep/acpica/events/evmisc.c
  89. 0 939
      h2o/localdep/acpica/events/evregion.c
  90. 0 663
      h2o/localdep/acpica/events/evrgnini.c
  91. 0 282
      h2o/localdep/acpica/events/evsci.c
  92. 0 1268
      h2o/localdep/acpica/events/evxface.c
  93. 0 451
      h2o/localdep/acpica/events/evxfevnt.c
  94. 0 1182
      h2o/localdep/acpica/events/evxfgpe.c
  95. 0 280
      h2o/localdep/acpica/events/evxfregn.c
  96. 0 461
      h2o/localdep/acpica/executer/exconcat.c
  97. 0 621
      h2o/localdep/acpica/executer/exconfig.c
  98. 0 774
      h2o/localdep/acpica/executer/exconvrt.c
  99. 0 550
      h2o/localdep/acpica/executer/excreate.c
  100. 0 353
      h2o/localdep/acpica/executer/exdebug.c

+ 4 - 0
Cargo.toml

@@ -7,6 +7,10 @@ members = [
   "src/bin/*",
   "src/lib/*",
   "src/lib/libc/ldso",
+  "src/lib/h2o_std/core",
+  "src/lib/h2o_rpc/core",
+  "src/lib/h2o_rpc/macros",
+  "src/lib/h2o_rpc/gen",
   "xtask",
 ]
 

+ 1 - 1
h2o/boot/src/outp.rs

@@ -78,7 +78,7 @@ pub fn draw_logo(syst: &SystemTable<Boot>) {
     let (blt_buffer, dims) = get_logo_data();
 
     let res = unsafe { RESOLUTION.expect("Unset resolution (should it be initialized?)") };
-    let dest = ((res.0 - dims.0 as usize) / 2, (res.1 - dims.1 as usize) / 2);
+    let dest = ((res.0 - dims.0) / 2, (res.1 - dims.1) / 2);
 
     unsafe { self::gop(syst).as_mut() }
         .blt(BltOp::BufferToVideo {

+ 2 - 2
h2o/kernel/.cargo/config.toml

@@ -12,6 +12,6 @@ panic = 'abort'
 
 [profile.release]
 incremental = true
-lto = 'thin'
-opt-level = 2
+lto = 'fat'
+opt-level = 3
 panic = 'abort'

+ 1 - 1
h2o/kernel/Cargo.toml

@@ -40,6 +40,6 @@ log = "0.4"
 modular-bitfield = "0.11"
 paste = "1.0"
 raw-cpuid = "10"
-scopeguard = {version = "1.1", default-features = false}
 spin = {version = "0.9", features = ["use_ticket_mutex"]}
 static_assertions = "1.1"
+memoffset = "0.6"

+ 9 - 0
h2o/kernel/entry/x86_64/stub.asm

@@ -244,6 +244,8 @@ switch_kframe:
       push  r14
       push  r15
       pushfq
+      push  qword [rdx]
+      push  qword [rcx]
       xor   rax, rax
       mov   ax, cs
       push  rax
@@ -259,6 +261,8 @@ switch_kframe:
       push  .pop_regs
       retfq
 .pop_regs:
+      pop   qword [rcx]
+      pop   qword [rdx]
       popfq
       pop   r15
       pop   r14
@@ -272,6 +276,8 @@ global task_fresh:function
 extern switch_finishing
 ; The entry into the interrupt context of a new task.
 task_fresh:
+      xor   rdi, rdi
+      xor   rsi, rsi
       align_call switch_finishing, r12
       cli
       jmp   intr_exit
@@ -426,6 +432,9 @@ rout_syscall:
       test  dword [rsp + 4], 0xFFFF8000 ; test if the return address is on the higher half
       jnz   .fault_iret
 
+      cmp   qword [rsp + 8], 0x8 ; test if the return segment is kernel.
+      je    .fault_iret
+
       pop   rcx                                       ; rip
       add   rsp, 8                                    ; cs
       pop   r11                                       ; rflags

+ 9 - 3
h2o/kernel/src/cpu/intr/imp.rs

@@ -30,15 +30,16 @@ impl Event for Interrupt {
         self.wait_impl(waiter);
     }
 
-    fn notify(&self, clear: usize, set: usize) {
+    fn notify(&self, clear: usize, set: usize) -> usize {
         PREEMPT.scope(|| *self.last_time.lock() = Some(Instant::now()));
 
-        self.notify_impl(clear, set);
+        let signal = self.notify_impl(clear, set);
 
         if self.level_triggered {
             MANAGER.mask(self.gsi, true).unwrap();
         }
         MANAGER.eoi(self.gsi).unwrap();
+        signal
     }
 }
 
@@ -141,7 +142,12 @@ mod syscall {
         }
 
         if timeout_us > 0 {
-            let blocker = crate::sched::Blocker::new(&(Arc::clone(&intr) as _), false, SIG_GENERIC);
+            let blocker = crate::sched::Blocker::new(
+                &(Arc::clone(&intr) as _),
+                intr.level_triggered,
+                false,
+                SIG_GENERIC,
+            );
             blocker.wait(Some(pree), time::from_us(timeout_us))?;
             if !blocker.detach().0 {
                 return Err(ETIME);

+ 1 - 1
h2o/kernel/src/cpu/time/timer.rs

@@ -105,7 +105,7 @@ impl Callback {
             Callback::Task(task) => SCHED.unblock(task, true),
             Callback::Event(event) => {
                 if let Some(event) = event.upgrade() {
-                    event.notify(0, SIG_TIMER)
+                    event.notify(0, SIG_TIMER);
                 }
             }
         }

+ 1 - 1
h2o/kernel/src/cpu/x86_64/intr.rs

@@ -137,7 +137,7 @@ unsafe fn exception(frame_ptr: *mut Frame, vec: def::ExVec) {
                     });
                 }
                 // Kill the fucking task.
-                SCHED.exit_current(sv_call::EFAULT.into_retval())
+                SCHED.exit_current(sv_call::EFAULT.into_retval(), true)
             }
             // unreachable!()
         }

+ 1 - 5
h2o/kernel/src/cpu/x86_64/tsc.rs

@@ -18,11 +18,7 @@ pub static TSC_CLOCK: Azy<TscClock> = Azy::new(|| {
     let initial = rdtsc();
     let (mul, sft) = factor_from_freq(khz);
     log::info!("CPU Timestamp frequency: {} KHz", khz);
-    TscClock {
-        initial,
-        mul: mul as u128,
-        sft: sft as u128,
-    }
+    TscClock { initial, mul, sft }
 });
 
 pub struct TscClock {

+ 1 - 2
h2o/kernel/src/kmain.rs

@@ -11,18 +11,17 @@
 #![feature(box_into_inner)]
 #![feature(box_syntax)]
 #![feature(coerce_unsized)]
-#![feature(const_btree_new)]
 #![feature(core_intrinsics)]
 #![feature(downcast_unchecked)]
 #![feature(drain_filter)]
 #![feature(int_log)]
 #![feature(layout_for_ptr)]
 #![feature(linked_list_cursors)]
-#![feature(map_first_last)]
 #![feature(map_try_insert)]
 #![feature(new_uninit)]
 #![feature(nonnull_slice_from_raw_parts)]
 #![feature(once_cell)]
+#![feature(pointer_byte_offsets)]
 #![feature(ptr_metadata)]
 #![feature(receiver_trait)]
 #![feature(result_option_inspect)]

+ 1 - 1
h2o/kernel/src/log.rs

@@ -105,7 +105,7 @@ mod syscall {
     };
 
     #[syscall]
-    fn log(buffer: UserPtr<In, u8>, len: usize) -> Result {
+    fn log(buffer: UserPtr<In>, len: usize) -> Result {
         buffer.check_slice(len)?;
         let string =
             core::str::from_utf8(unsafe { core::slice::from_raw_parts(buffer.as_ptr(), len) })?;

+ 11 - 2
h2o/kernel/src/mem/space.rs

@@ -25,6 +25,7 @@ use archop::Azy;
 use paging::LAddr;
 use spin::Mutex;
 pub use sv_call::mem::Flags;
+use sv_call::mem::PhysOptions;
 
 pub use self::{arch::init_pgc, phys::*, virt::*};
 use crate::sched::{task, PREEMPT};
@@ -104,7 +105,15 @@ impl Deref for Space {
 }
 
 pub(crate) fn allocate(size: usize, flags: Flags, zeroed: bool) -> sv_call::Result<NonNull<[u8]>> {
-    let phys = Phys::allocate(size, zeroed)?;
+    let phys = Phys::allocate(
+        size,
+        if zeroed {
+            PhysOptions::ZEROED
+        } else {
+            Default::default()
+        },
+        false,
+    )?;
     let len = phys.len();
 
     KRL.root
@@ -136,7 +145,7 @@ pub fn init_stack(virt: &Arc<Virt>, size: usize) -> sv_call::Result<LAddr> {
     let virt = virt.allocate(None, unsafe {
         Layout::from_size_align_unchecked(paging::PAGE_SIZE * 2 + size, paging::PAGE_SIZE)
     })?;
-    let phys = Phys::allocate(size, false)?;
+    let phys = Phys::allocate(size, Default::default(), false)?;
     let ret = virt.upgrade().unwrap().map(
         Some(paging::PAGE_SIZE),
         phys,

+ 143 - 103
h2o/kernel/src/mem/space/phys.rs

@@ -1,148 +1,188 @@
-use alloc::alloc::Global;
-use core::alloc::{Allocator, Layout};
+mod contiguous;
+mod extensible;
 
-use bitop_ex::BitOpEx;
-use paging::{LAddr, PAddr, PAGE_SHIFT, PAGE_SIZE};
-use sv_call::{Feature, Result};
+use alloc::sync::Weak;
 
-use crate::sched::{task::hdl::DefaultFeature, Arsc};
+use paging::PAddr;
+use sv_call::{mem::PhysOptions, Feature, Result, EPERM};
 
-#[derive(Debug)]
-struct PhysInner {
-    from_allocator: bool,
-    base: PAddr,
-    size: usize,
-}
+use crate::{
+    sched::{task::hdl::DefaultFeature, BasicEvent, Event},
+    syscall::{In, Out, UserPtr},
+};
 
-impl PhysInner {
-    unsafe fn new_manual(from_allocator: bool, base: PAddr, size: usize) -> PhysInner {
-        PhysInner {
-            from_allocator,
-            base,
-            size,
-        }
-    }
-}
+type Cont = self::contiguous::Phys;
+type PinnedCont = self::contiguous::PinnedPhys;
 
-impl Drop for PhysInner {
-    fn drop(&mut self) {
-        if self.from_allocator {
-            let ptr = unsafe { self.base.to_laddr(minfo::ID_OFFSET).as_non_null_unchecked() };
-            let layout =
-                unsafe { Layout::from_size_align_unchecked(self.size, PAGE_SIZE) }.pad_to_align();
-            unsafe { Global.deallocate(ptr, layout) };
-        }
-    }
-}
+use self::extensible::*;
 
-#[derive(Debug, Clone)]
-pub struct Phys {
-    offset: usize,
-    len: usize,
-    inner: Arsc<PhysInner>,
+#[derive(Debug, Clone, PartialEq)]
+pub enum Phys {
+    Contiguous(Cont),
+    Static(Static),
+    Dynamic(Dynamic),
 }
 
-impl From<Arsc<PhysInner>> for Phys {
-    fn from(inner: Arsc<PhysInner>) -> Self {
-        Phys {
-            offset: 0,
-            len: inner.size,
-            inner,
-        }
-    }
+#[derive(Debug)]
+pub enum PinnedPhys {
+    Contiguous(PinnedCont),
+    Static(PinnedStatic),
+    Dynamic(PinnedDynamic),
 }
 
 impl Phys {
     #[inline]
     pub fn new(base: PAddr, size: usize) -> Result<Self> {
-        unsafe { Arsc::try_new(PhysInner::new_manual(false, base, size)) }
-            .map_err(sv_call::Error::from)
-            .map(Self::from)
+        Ok(Phys::Contiguous(Cont::new(base, size)?))
     }
 
     /// # Errors
     ///
     /// Returns error if the heap memory is exhausted or the size is zero.
-    pub fn allocate(size: usize, zeroed: bool) -> Result<Self> {
-        if size == 0 {
-            return Err(sv_call::ENOMEM);
-        }
-
-        let mut inner = Arsc::try_new_uninit()?;
-        let layout = unsafe { Layout::from_size_align_unchecked(size, PAGE_SIZE) }.pad_to_align();
-        let mem = if zeroed {
-            Global.allocate_zeroed(layout)
+    pub fn allocate(size: usize, options: PhysOptions, contiguous: bool) -> Result<Self> {
+        let resizable = options.contains(PhysOptions::RESIZABLE);
+        Ok(if contiguous {
+            if resizable {
+                return Err(EPERM);
+            }
+            Phys::Contiguous(Cont::allocate(size, options.contains(PhysOptions::ZEROED))?)
         } else {
-            Global.allocate(layout)
-        };
-
-        mem.map(|ptr| unsafe {
-            Arsc::get_mut_unchecked(&mut inner).write(PhysInner::new_manual(
-                true,
-                LAddr::from(ptr).to_paddr(minfo::ID_OFFSET),
-                size,
-            ));
-            Arsc::assume_init(inner)
+            let zeroed = options.contains(PhysOptions::ZEROED);
+            if resizable {
+                Phys::Dynamic(Dynamic::allocate(size, zeroed)?)
+            } else {
+                Phys::Static(Static::allocate(size, zeroed)?)
+            }
         })
-        .map_err(sv_call::Error::from)
-        .map(Self::from)
     }
 
+    pub fn event(&self) -> Weak<dyn Event> {
+        match self {
+            Phys::Dynamic(d) => d.event(),
+            _ => Weak::<BasicEvent>::new() as _,
+        }
+    }
+
+    #[inline]
+    #[allow(clippy::len_without_is_empty)]
     pub fn len(&self) -> usize {
-        self.len
+        match self {
+            Phys::Contiguous(cont) => cont.len(),
+            Phys::Static(s) => s.len(),
+            Phys::Dynamic(d) => d.len(),
+        }
     }
 
-    pub fn is_empty(&self) -> bool {
-        self.len == 0
+    #[inline]
+    pub fn pin(this: Self) -> Result<PinnedPhys> {
+        match this {
+            Phys::Contiguous(cont) => Ok(PinnedPhys::Contiguous(Cont::pin(cont))),
+            Phys::Static(ext) => Ok(PinnedPhys::Static(Static::pin(ext))),
+            Phys::Dynamic(ext) => Ok(PinnedPhys::Dynamic(Dynamic::pin(ext)?)),
+        }
     }
 
+    #[inline]
     pub fn create_sub(&self, offset: usize, len: usize, copy: bool) -> Result<Self> {
-        if offset.contains_bit(PAGE_SHIFT) || len.contains_bit(PAGE_SHIFT) {
-            return Err(sv_call::EALIGN);
+        match self {
+            Phys::Contiguous(cont) => cont.create_sub(offset, len, copy).map(Phys::Contiguous),
+            Phys::Static(ext) => ext.create_sub(offset, len, copy).map(Phys::Static),
+            Phys::Dynamic(_) => Err(EPERM),
         }
+    }
 
-        let new_offset = self.offset.wrapping_add(offset);
-        let end = new_offset.wrapping_add(len);
-        if self.offset <= new_offset && new_offset < end && end <= self.offset + self.len {
-            if copy {
-                let child = Self::allocate(len, true)?;
-                let dst = child.raw_ptr();
-                unsafe {
-                    let src = self.raw_ptr().add(offset);
-                    dst.copy_from_nonoverlapping(src, len);
-                }
-                Ok(child)
-            } else {
-                Ok(Phys {
-                    offset: new_offset,
-                    len,
-                    inner: Arsc::clone(&self.inner),
-                })
-            }
-        } else {
-            Err(sv_call::ERANGE)
+    #[inline]
+    pub fn base(&self) -> PAddr {
+        match self {
+            Phys::Contiguous(cont) => cont.base(),
+            _ => unimplemented!("Extensible phys have multiple bases"),
         }
     }
 
-    pub fn base(&self) -> PAddr {
-        PAddr::new(*self.inner.base + self.offset)
+    #[inline]
+    pub fn resize(&self, new_len: usize, zeroed: bool) -> Result {
+        match self {
+            Phys::Dynamic(d) => d.resize(new_len, zeroed),
+            _ => Err(EPERM),
+        }
+    }
+
+    #[inline]
+    pub fn read(&self, offset: usize, len: usize, buffer: UserPtr<Out>) -> Result<usize> {
+        match self {
+            Phys::Contiguous(cont) => cont.read(offset, len, buffer),
+            Phys::Static(s) => s.read(offset, len, buffer),
+            Phys::Dynamic(d) => d.read(offset, len, buffer),
+        }
     }
 
-    pub fn raw_ptr(&self) -> *mut u8 {
-        unsafe { self.inner.base.to_laddr(minfo::ID_OFFSET).add(self.offset) }
+    #[inline]
+    pub fn write(&self, offset: usize, len: usize, buffer: UserPtr<In>) -> Result<usize> {
+        match self {
+            Phys::Contiguous(cont) => cont.write(offset, len, buffer),
+            Phys::Static(s) => s.write(offset, len, buffer),
+            Phys::Dynamic(d) => d.write(offset, len, buffer),
+        }
+    }
+
+    #[inline]
+    pub fn read_vectored(&self, offset: usize, bufs: &[(UserPtr<Out>, usize)]) -> Result<usize> {
+        match self {
+            Phys::Contiguous(cont) => cont.read_vectored(offset, bufs),
+            Phys::Static(s) => s.read_vectored(offset, bufs),
+            Phys::Dynamic(d) => d.read_vectored(offset, bufs),
+        }
+    }
+
+    #[inline]
+    pub fn write_vectored(&self, offset: usize, bufs: &[(UserPtr<In>, usize)]) -> Result<usize> {
+        match self {
+            Phys::Contiguous(cont) => cont.write_vectored(offset, bufs),
+            Phys::Static(s) => s.write_vectored(offset, bufs),
+            Phys::Dynamic(d) => d.write_vectored(offset, bufs),
+        }
     }
 }
 
-impl PartialEq for Phys {
-    fn eq(&self, other: &Self) -> bool {
-        self.offset == other.offset
-            && self.len == other.len
-            && Arsc::ptr_eq(&self.inner, &other.inner)
+impl PinnedPhys {
+    #[inline]
+    pub fn map_iter(&self, offset: usize, len: usize) -> impl Iterator<Item = (PAddr, usize)> + '_ {
+        enum OneOf<A, B, C> {
+            A(A),
+            B(B),
+            C(C),
+        }
+        impl<A, B, C, T> Iterator for OneOf<A, B, C>
+        where
+            A: Iterator<Item = T>,
+            B: Iterator<Item = T>,
+            C: Iterator<Item = T>,
+        {
+            type Item = T;
+            fn next(&mut self) -> Option<Self::Item> {
+                match self {
+                    OneOf::A(a) => a.next(),
+                    OneOf::B(b) => b.next(),
+                    OneOf::C(c) => c.next(),
+                }
+            }
+        }
+
+        match self {
+            PinnedPhys::Contiguous(cont) => OneOf::A(cont.map_iter(offset, len)),
+            PinnedPhys::Static(s) => OneOf::B(s.map_iter(offset, len)),
+            PinnedPhys::Dynamic(d) => OneOf::C(d.map_iter(offset, len)),
+        }
     }
 }
 
 unsafe impl DefaultFeature for Phys {
     fn default_features() -> Feature {
-        Feature::SEND | Feature::SYNC | Feature::READ | Feature::WRITE | Feature::EXECUTE
+        Feature::SEND
+            | Feature::SYNC
+            | Feature::READ
+            | Feature::WRITE
+            | Feature::EXECUTE
+            | Feature::WAIT
     }
 }

+ 235 - 0
h2o/kernel/src/mem/space/phys/contiguous.rs

@@ -0,0 +1,235 @@
+use alloc::alloc::Global;
+use core::{
+    alloc::{Allocator, Layout},
+    slice,
+};
+
+use bitop_ex::BitOpEx;
+use paging::{LAddr, PAddr, PAGE_SHIFT, PAGE_SIZE};
+use sv_call::Result;
+
+use crate::{
+    sched::Arsc,
+    syscall::{In, InPtrType, Out, OutPtrType, UserPtr},
+};
+
+#[derive(Debug)]
+struct PhysInner {
+    from_allocator: bool,
+    base: PAddr,
+    size: usize,
+}
+
+impl PhysInner {
+    unsafe fn new_manual(from_allocator: bool, base: PAddr, size: usize) -> PhysInner {
+        PhysInner {
+            from_allocator,
+            base,
+            size,
+        }
+    }
+}
+
+impl Drop for PhysInner {
+    fn drop(&mut self) {
+        if self.from_allocator {
+            let ptr = unsafe { self.base.to_laddr(minfo::ID_OFFSET).as_non_null_unchecked() };
+            let layout =
+                unsafe { Layout::from_size_align_unchecked(self.size, PAGE_SIZE) }.pad_to_align();
+            unsafe { Global.deallocate(ptr, layout) };
+        }
+    }
+}
+
+#[derive(Debug, Clone)]
+pub struct Phys {
+    offset: usize,
+    len: usize,
+    inner: Arsc<PhysInner>,
+}
+
+pub type PinnedPhys = Phys;
+
+impl From<Arsc<PhysInner>> for Phys {
+    fn from(inner: Arsc<PhysInner>) -> Self {
+        Phys {
+            offset: 0,
+            len: inner.size,
+            inner,
+        }
+    }
+}
+
+impl Phys {
+    #[inline]
+    pub fn new(base: PAddr, size: usize) -> Result<Self> {
+        unsafe { Arsc::try_new(PhysInner::new_manual(false, base, size)) }
+            .map_err(sv_call::Error::from)
+            .map(Self::from)
+    }
+
+    /// # Errors
+    ///
+    /// Returns error if the heap memory is exhausted or the size is zero.
+    pub fn allocate(size: usize, zeroed: bool) -> Result<Self> {
+        if size == 0 {
+            return Err(sv_call::ENOMEM);
+        }
+        let size = size.round_up_bit(PAGE_SHIFT);
+
+        let mut inner = Arsc::try_new_uninit()?;
+        let layout = unsafe { Layout::from_size_align_unchecked(size, PAGE_SIZE) }.pad_to_align();
+        let mem = if zeroed {
+            Global.allocate_zeroed(layout)
+        } else {
+            Global.allocate(layout)
+        };
+
+        mem.map(|ptr| unsafe {
+            Arsc::get_mut_unchecked(&mut inner).write(PhysInner::new_manual(
+                true,
+                LAddr::from(ptr).to_paddr(minfo::ID_OFFSET),
+                size,
+            ));
+            Arsc::assume_init(inner)
+        })
+        .map_err(sv_call::Error::from)
+        .map(Self::from)
+    }
+
+    #[inline]
+    pub fn len(&self) -> usize {
+        self.len
+    }
+
+    #[inline]
+    pub fn is_empty(&self) -> bool {
+        self.len == 0
+    }
+
+    #[inline]
+    pub fn pin(this: Self) -> PinnedPhys {
+        this
+    }
+
+    pub fn create_sub(&self, offset: usize, len: usize, copy: bool) -> Result<Self> {
+        if offset.contains_bit(PAGE_SHIFT) || len.contains_bit(PAGE_SHIFT) {
+            return Err(sv_call::EALIGN);
+        }
+
+        let new_offset = self.offset.wrapping_add(offset);
+        let end = new_offset.wrapping_add(len);
+        if self.offset <= new_offset && new_offset < end && end <= self.offset + self.len {
+            if copy {
+                let child = Self::allocate(len, true)?;
+                let dst = child.raw();
+                unsafe {
+                    let src = self.raw().add(offset);
+                    dst.copy_from_nonoverlapping(src, len);
+                }
+                Ok(child)
+            } else {
+                Ok(Phys {
+                    offset: new_offset,
+                    len,
+                    inner: Arsc::clone(&self.inner),
+                })
+            }
+        } else {
+            Err(sv_call::ERANGE)
+        }
+    }
+
+    pub fn base(&self) -> PAddr {
+        PAddr::new(*self.inner.base + self.offset)
+    }
+
+    #[inline]
+    pub fn map_iter(&self, offset: usize, len: usize) -> impl Iterator<Item = (PAddr, usize)> {
+        let base = PAddr::new(*self.inner.base + self.offset + offset);
+        let len = self.len.saturating_sub(offset).min(len);
+        (len > 0).then_some((base, len)).into_iter()
+    }
+
+    fn raw(&self) -> *mut u8 {
+        unsafe { self.inner.base.to_laddr(minfo::ID_OFFSET).add(self.offset) }
+    }
+
+    pub fn read(&self, offset: usize, len: usize, buffer: UserPtr<Out>) -> Result<usize> {
+        let offset = self.len.min(offset);
+        let len = self.len.saturating_sub(offset).min(len);
+        unsafe {
+            let ptr = self.raw().add(offset);
+            let slice = slice::from_raw_parts(ptr, len);
+            buffer.write_slice(slice)?;
+        }
+        Ok(len)
+    }
+
+    pub fn write(&self, offset: usize, len: usize, buffer: UserPtr<In>) -> Result<usize> {
+        let offset = self.len.min(offset);
+        let len = self.len.saturating_sub(offset).min(len);
+        unsafe {
+            let ptr = self.raw().add(offset);
+            buffer.read_slice(ptr, len)?;
+        }
+        Ok(len)
+    }
+
+    pub fn read_vectored<T: OutPtrType>(
+        &self,
+        mut offset: usize,
+        bufs: &[(UserPtr<T>, usize)],
+    ) -> sv_call::Result<usize> {
+        let mut read_len = 0;
+        for buf in bufs {
+            let actual_offset = self.len.min(offset);
+            let len = self.len.saturating_sub(actual_offset).min(buf.1);
+
+            let buffer = buf.0.out();
+            unsafe {
+                let ptr = self.raw().add(offset);
+                let slice = slice::from_raw_parts(ptr, len);
+                buffer.write_slice(slice)?;
+            }
+            read_len += len;
+            offset += len;
+            if len < buf.1 {
+                break;
+            }
+        }
+        Ok(read_len)
+    }
+
+    pub fn write_vectored<T: InPtrType>(
+        &self,
+        mut offset: usize,
+        bufs: &[(UserPtr<T>, usize)],
+    ) -> sv_call::Result<usize> {
+        let mut written_len = 0;
+        for buf in bufs {
+            let actual_offset = self.len.min(offset);
+            let len = self.len.saturating_sub(actual_offset).min(buf.1);
+
+            let buffer = buf.0.r#in();
+            unsafe {
+                let ptr = self.raw().add(offset);
+                buffer.read_slice(ptr, len)?;
+            }
+            written_len += len;
+            offset += len;
+            if len < buf.1 {
+                break;
+            }
+        }
+        Ok(written_len)
+    }
+}
+
+impl PartialEq for Phys {
+    fn eq(&self, other: &Self) -> bool {
+        self.offset == other.offset
+            && self.len == other.len
+            && Arsc::ptr_eq(&self.inner, &other.inner)
+    }
+}

+ 528 - 0
h2o/kernel/src/mem/space/phys/extensible.rs

@@ -0,0 +1,528 @@
+use alloc::{
+    alloc::Global,
+    collections::BTreeMap,
+    sync::{Arc, Weak},
+};
+use core::{
+    alloc::{AllocError, Allocator, Layout},
+    mem, slice,
+};
+
+use bitop_ex::BitOpEx;
+use paging::{LAddr, PAddr, PAGE_SHIFT, PAGE_SIZE};
+use spin::RwLock;
+use sv_call::{
+    ipc::{SIG_READ, SIG_WRITE},
+    EAGAIN,
+};
+
+use crate::{
+    sched::{Arsc, BasicEvent, Event, PREEMPT},
+    syscall::{In, InPtrType, Out, OutPtrType, UserPtr},
+};
+
+#[derive(Debug)]
+struct Block {
+    from_allocator: bool,
+    base: PAddr,
+    len: usize,
+    capacity: usize,
+}
+
+impl Block {
+    unsafe fn new_manual(from_allocator: bool, base: PAddr, len: usize, capacity: usize) -> Block {
+        Block {
+            from_allocator,
+            base,
+            len,
+            capacity,
+        }
+    }
+
+    fn allocate(len: usize, zeroed: bool) -> Result<Block, AllocError> {
+        let capacity = len.round_up_bit(PAGE_SHIFT);
+        let layout = unsafe { Layout::from_size_align_unchecked(capacity, PAGE_SIZE) };
+        let memory = if zeroed {
+            Global.allocate_zeroed(layout)
+        } else {
+            Global.allocate(layout)
+        }?;
+        Ok(unsafe {
+            Block::new_manual(
+                true,
+                LAddr::from(memory).to_paddr(minfo::ID_OFFSET),
+                len,
+                capacity,
+            )
+        })
+    }
+}
+
+impl Drop for Block {
+    fn drop(&mut self) {
+        if self.from_allocator {
+            let ptr = unsafe { self.base.to_laddr(minfo::ID_OFFSET).as_non_null_unchecked() };
+            let layout = unsafe { Layout::from_size_align_unchecked(self.capacity, PAGE_SIZE) }
+                .pad_to_align();
+            unsafe { Global.deallocate(ptr, layout) };
+        }
+    }
+}
+
+#[derive(Debug)]
+struct PhysInner {
+    map: BTreeMap<usize, Block>,
+    len: usize,
+}
+
+impl PhysInner {
+    fn range(&self, offset: usize, len: usize) -> impl Iterator<Item = (PAddr, usize)> + '_ {
+        let end = offset + len;
+        let first = self.map.range(..offset).next_back();
+        let first = first.and_then(|(&base, block)| {
+            let offset = offset - base;
+            let len = block.len.saturating_sub(offset).min(len);
+            (len > 0).then_some((PAddr::new(*block.base + offset), len))
+        });
+        let next = self
+            .map
+            .range(offset..end)
+            .filter_map(move |(&base, block)| {
+                let len = block.len.min(end.saturating_sub(base));
+                (len > 0).then_some((block.base, len))
+            });
+        first.into_iter().chain(next)
+    }
+
+    fn iter(&self) -> impl Iterator<Item = (PAddr, usize)> + '_ {
+        self.map.values().map(|block| (block.base, block.len))
+    }
+
+    fn allocate(len: usize, zeroed: bool) -> Result<Self, AllocError> {
+        let mut map = BTreeMap::new();
+
+        let mut acc = len;
+        let mut offset = 0;
+        while acc > PAGE_SIZE {
+            let part = 1 << (usize::BITS - acc.leading_zeros() - 1);
+
+            let new = Block::allocate(part, zeroed)?;
+            map.insert(offset, new);
+
+            offset += part;
+            acc -= part;
+        }
+        if acc > 0 {
+            let new = Block::allocate(acc, zeroed)?;
+            map.insert(offset, new);
+        }
+        Ok(PhysInner { map, len })
+    }
+
+    fn truncate(&mut self, new_len: usize) {
+        self.map.split_off(&new_len);
+        if let Some(mut ent) = self.map.last_entry() {
+            if *ent.key() < new_len && ent.get().len + ent.key() > new_len {
+                ent.get_mut().len = new_len - ent.key();
+            }
+        }
+        self.len = new_len;
+    }
+
+    fn extend(&mut self, new_len: usize, zeroed: bool) -> Result<(), AllocError> {
+        let start = self.len;
+        let mut len = new_len.saturating_sub(start);
+        if let Some(mut last) = self.map.last_entry() {
+            let delta = (last.get().capacity - last.get().len).min(len);
+            len -= delta;
+            last.get_mut().len += delta;
+            self.len += delta;
+        }
+        if len > 0 {
+            let new = Block::allocate(len, zeroed)?;
+            self.map.insert(self.len, new);
+            self.len += len;
+        }
+        Ok(())
+    }
+
+    fn resize(&mut self, new_len: usize, zeroed: bool) -> Result<(), AllocError> {
+        if self.len < new_len {
+            self.extend(new_len, zeroed)
+        } else {
+            self.truncate(new_len);
+            Ok(())
+        }
+    }
+}
+
+#[derive(Debug, Clone)]
+pub struct Static {
+    offset: usize,
+    len: usize,
+    inner: Arsc<PhysInner>,
+}
+
+impl Static {
+    pub fn allocate(len: usize, zeroed: bool) -> Result<Self, AllocError> {
+        PhysInner::allocate(len, zeroed).and_then(|inner| {
+            Ok(Static {
+                offset: 0,
+                len: inner.len,
+                inner: Arsc::try_new(inner)?,
+            })
+        })
+    }
+
+    #[inline]
+    pub fn len(&self) -> usize {
+        self.len
+    }
+
+    #[inline]
+    pub fn is_empty(&self) -> bool {
+        self.len == 0
+    }
+
+    #[inline]
+    pub fn pin(this: Self) -> PinnedStatic {
+        PinnedStatic(this)
+    }
+
+    pub fn create_sub(&self, offset: usize, len: usize, copy: bool) -> sv_call::Result<Self> {
+        if offset.contains_bit(PAGE_SHIFT) || len.contains_bit(PAGE_SHIFT) {
+            return Err(sv_call::EALIGN);
+        }
+        let cloned = Arsc::clone(&self.inner);
+
+        let new_offset = self.offset.wrapping_add(offset);
+        let end = new_offset.wrapping_add(len);
+        if self.offset <= new_offset && new_offset < end && end <= self.offset + self.len() {
+            if copy {
+                let child = Self::allocate(len, false)?;
+
+                let (dst, _) = child.inner.iter().next().expect("Inconsistent map");
+                let mut dst = *dst.to_laddr(minfo::ID_OFFSET);
+
+                for (src, sl) in self.inner.range(new_offset, len) {
+                    let src = *src.to_laddr(minfo::ID_OFFSET);
+                    unsafe {
+                        dst.copy_from_nonoverlapping(src, sl);
+                        dst = dst.add(sl);
+                    }
+                }
+
+                Ok(child)
+            } else {
+                Ok(Static {
+                    offset: new_offset,
+                    len,
+                    inner: cloned,
+                })
+            }
+        } else {
+            Err(sv_call::ERANGE)
+        }
+    }
+
+    pub fn read(&self, offset: usize, len: usize, buffer: UserPtr<Out>) -> sv_call::Result<usize> {
+        let mut buffer = buffer;
+        let offset = self.len.min(offset);
+        let len = self.len.saturating_sub(offset).min(len);
+
+        for (base, len) in self.inner.range(self.offset + offset, len) {
+            let src = *base.to_laddr(minfo::ID_OFFSET);
+            unsafe {
+                let src = slice::from_raw_parts(src, len);
+                buffer.write_slice(src)?;
+                buffer = UserPtr::new(buffer.as_ptr().add(len));
+            }
+        }
+        Ok(len)
+    }
+
+    pub fn write(&self, offset: usize, len: usize, buffer: UserPtr<In>) -> sv_call::Result<usize> {
+        let mut buffer = buffer;
+        let offset = self.len.min(offset);
+        let len = self.len.saturating_sub(offset).min(len);
+
+        for (base, len) in self.inner.range(self.offset + offset, len) {
+            let dst = *base.to_laddr(minfo::ID_OFFSET);
+            unsafe {
+                buffer.read_slice(dst, len)?;
+                buffer = UserPtr::new(buffer.as_ptr().add(len));
+            }
+        }
+        Ok(len)
+    }
+
+    pub fn read_vectored<T: OutPtrType>(
+        &self,
+        mut offset: usize,
+        bufs: &[(UserPtr<T>, usize)],
+    ) -> sv_call::Result<usize> {
+        let mut read_len = 0;
+
+        for buf in bufs {
+            let actual_offset = self.len.min(offset);
+            let len = self.len.saturating_sub(actual_offset).min(buf.1);
+
+            let mut buffer = buf.0.out();
+            for (base, len) in self.inner.range(self.offset + actual_offset, len) {
+                let src = *base.to_laddr(minfo::ID_OFFSET);
+                unsafe {
+                    let src = slice::from_raw_parts(src, len);
+                    buffer.write_slice(src)?;
+                    buffer = UserPtr::new(buffer.as_ptr().add(len));
+                }
+            }
+            read_len += len;
+            offset += len;
+            if len < buf.1 {
+                break;
+            }
+        }
+
+        Ok(read_len)
+    }
+
+    pub fn write_vectored<T: InPtrType>(
+        &self,
+        mut offset: usize,
+        bufs: &[(UserPtr<T>, usize)],
+    ) -> sv_call::Result<usize> {
+        let mut written_len = 0;
+
+        for buf in bufs {
+            let actual_offset = self.len.min(offset);
+            let len = self.len.saturating_sub(actual_offset).min(buf.1);
+
+            let mut buffer = buf.0.r#in();
+            for (base, len) in self.inner.range(self.offset + actual_offset, len) {
+                let dst = *base.to_laddr(minfo::ID_OFFSET);
+                unsafe {
+                    buffer.read_slice(dst, len)?;
+                    buffer = UserPtr::new(buffer.as_ptr().add(len));
+                }
+            }
+            written_len += len;
+            offset += len;
+            if len < buf.1 {
+                break;
+            }
+        }
+
+        Ok(written_len)
+    }
+}
+
+impl PartialEq for Static {
+    fn eq(&self, other: &Self) -> bool {
+        self.offset == other.offset
+            && self.len == other.len
+            && Arsc::ptr_eq(&self.inner, &other.inner)
+    }
+}
+
+#[derive(Debug)]
+pub struct PinnedStatic(Static);
+
+impl PinnedStatic {
+    #[inline]
+    pub fn map_iter(&self, offset: usize, len: usize) -> impl Iterator<Item = (PAddr, usize)> + '_ {
+        self.0.inner.range(self.0.offset + offset, len)
+    }
+}
+
+#[derive(Debug, Clone)]
+pub struct Dynamic {
+    inner: Arsc<RwLock<PhysInner>>,
+    event: Arc<BasicEvent>,
+}
+
+impl Dynamic {
+    pub fn allocate(len: usize, zeroed: bool) -> Result<Self, AllocError> {
+        PhysInner::allocate(len, zeroed).and_then(|inner| {
+            Ok(Dynamic {
+                inner: Arsc::try_new(RwLock::new(inner))?,
+                event: BasicEvent::new(0),
+            })
+        })
+    }
+
+    pub fn event(&self) -> Weak<dyn Event> {
+        Arc::downgrade(&self.event) as _
+    }
+
+    #[inline]
+    pub fn len(&self) -> usize {
+        // FIXME: For now, just let this slip.
+        unsafe { (*self.inner.as_mut_ptr()).len }
+    }
+
+    #[inline]
+    pub fn pin(this: Self) -> sv_call::Result<PinnedDynamic> {
+        mem::forget(this.inner.try_read().ok_or(EAGAIN)?);
+        Ok(PinnedDynamic(this))
+    }
+
+    fn notify_read(&self) {
+        if self.inner.reader_count() > 0 {
+            self.event.notify(0, SIG_READ);
+        } else {
+            self.event.notify(0, SIG_READ | SIG_WRITE);
+        }
+    }
+
+    fn notify_write(&self) {
+        self.event.notify(0, SIG_READ | SIG_WRITE);
+    }
+
+    pub fn resize(&self, new_len: usize, zeroed: bool) -> sv_call::Result {
+        PREEMPT.scope(|| {
+            let mut this = self.inner.try_write().ok_or(EAGAIN)?;
+            this.resize(new_len, zeroed)?;
+            Ok::<_, sv_call::Error>(())
+        })?;
+        self.notify_write();
+        Ok(())
+    }
+
+    pub fn read(&self, offset: usize, len: usize, buffer: UserPtr<Out>) -> sv_call::Result<usize> {
+        let mut buffer = buffer;
+        let len = PREEMPT.scope(|| {
+            let this = self.inner.try_read().ok_or(EAGAIN)?;
+
+            let offset = this.len.min(offset);
+            let len = this.len.saturating_sub(offset).min(len);
+
+            for (base, len) in this.range(offset, len) {
+                let src = *base.to_laddr(minfo::ID_OFFSET);
+                unsafe {
+                    let src = slice::from_raw_parts(src, len);
+                    buffer.write_slice(src)?;
+                    buffer = UserPtr::new(buffer.as_ptr().add(len));
+                }
+            }
+            Ok::<_, sv_call::Error>(len)
+        })?;
+        self.notify_read();
+        Ok(len)
+    }
+
+    pub fn write(&self, offset: usize, len: usize, buffer: UserPtr<In>) -> sv_call::Result<usize> {
+        let mut buffer = buffer;
+        let len = PREEMPT.scope(|| {
+            let this = self.inner.try_write().ok_or(EAGAIN)?;
+
+            let offset = this.len.min(offset);
+            let len = this.len.saturating_sub(offset).min(len);
+
+            for (base, len) in this.range(offset, len) {
+                let dst = *base.to_laddr(minfo::ID_OFFSET);
+                unsafe {
+                    buffer.read_slice(dst, len)?;
+                    buffer = UserPtr::new(buffer.as_ptr().add(len));
+                }
+            }
+            Ok::<_, sv_call::Error>(len)
+        })?;
+        self.notify_write();
+        Ok(len)
+    }
+
+    pub fn read_vectored<T: OutPtrType>(
+        &self,
+        mut offset: usize,
+        bufs: &[(UserPtr<T>, usize)],
+    ) -> sv_call::Result<usize> {
+        let mut read_len = 0;
+        PREEMPT.scope(|| {
+            let this = self.inner.try_read().ok_or(EAGAIN)?;
+            let self_len = this.len;
+            for buf in bufs {
+                let actual_offset = self_len.min(offset);
+                let len = self_len.saturating_sub(actual_offset).min(buf.1);
+
+                let mut buffer = buf.0.out();
+                for (base, len) in this.range(actual_offset, len) {
+                    let src = *base.to_laddr(minfo::ID_OFFSET);
+                    unsafe {
+                        let src = slice::from_raw_parts(src, len);
+                        buffer.write_slice(src)?;
+                        buffer = UserPtr::new(buffer.as_ptr().add(len));
+                    }
+                }
+                read_len += len;
+                offset += len;
+                if len < buf.1 {
+                    break;
+                }
+            }
+            Ok::<_, sv_call::Error>(())
+        })?;
+        self.notify_read();
+        Ok(read_len)
+    }
+
+    pub fn write_vectored<T: InPtrType>(
+        &self,
+        mut offset: usize,
+        bufs: &[(UserPtr<T>, usize)],
+    ) -> sv_call::Result<usize> {
+        let mut written_len = 0;
+        PREEMPT.scope(|| {
+            let this = self.inner.try_write().ok_or(EAGAIN)?;
+            let self_len = this.len;
+            for buf in bufs {
+                let actual_offset = self_len.min(offset);
+                let len = self_len.saturating_sub(actual_offset).min(buf.1);
+
+                let mut buffer = buf.0.r#in();
+                for (base, len) in this.range(actual_offset, len) {
+                    let dst = *base.to_laddr(minfo::ID_OFFSET);
+                    unsafe {
+                        buffer.read_slice(dst, len)?;
+                        buffer = UserPtr::new(buffer.as_ptr().add(len));
+                    }
+                }
+                written_len += len;
+                offset += len;
+                if len < buf.1 {
+                    break;
+                }
+            }
+            Ok::<_, sv_call::Error>(())
+        })?;
+        self.notify_write();
+        Ok(written_len)
+    }
+}
+
+impl PartialEq for Dynamic {
+    #[inline]
+    fn eq(&self, other: &Self) -> bool {
+        Arsc::ptr_eq(&self.inner, &other.inner)
+    }
+}
+
+#[derive(Debug)]
+pub struct PinnedDynamic(Dynamic);
+
+impl PinnedDynamic {
+    pub fn map_iter(&self, offset: usize, len: usize) -> impl Iterator<Item = (PAddr, usize)> + '_ {
+        assert!(self.0.inner.writer_count() == 0 && self.0.inner.reader_count() > 0);
+
+        unsafe {
+            let ptr = self.0.inner.as_mut_ptr();
+            (*ptr).range(offset, len)
+        }
+    }
+}
+
+impl Drop for PinnedDynamic {
+    fn drop(&mut self) {
+        assert!(self.0.inner.reader_count() > 0);
+        unsafe { self.0.inner.force_read_decrement() }
+    }
+}

+ 22 - 9
h2o/kernel/src/mem/space/virt.rs

@@ -5,11 +5,11 @@ use alloc::{
 use core::{alloc::Layout, mem, ops::Range};
 
 use bitop_ex::BitOpEx;
-use paging::{LAddr, PAddr, PAGE_SHIFT, PAGE_SIZE};
+use paging::{LAddr, PAGE_SHIFT, PAGE_SIZE};
 use spin::Mutex;
 use sv_call::{error::*, mem::Flags, Feature, Result};
 
-use super::{paging_error, ty_to_range, Phys, Space};
+use super::{paging_error, ty_to_range, Phys, PinnedPhys, Space};
 use crate::sched::{
     task,
     task::{hdl::DefaultFeature, VDSO},
@@ -19,7 +19,7 @@ use crate::sched::{
 #[derive(Debug)]
 pub(super) enum Child {
     Virt(Arc<Virt>),
-    Phys(Phys, Flags, usize),
+    Phys(PinnedPhys, Flags, usize),
 }
 
 impl Child {
@@ -140,6 +140,8 @@ impl Virt {
             return Err(ERANGE);
         }
 
+        let phys = Phys::pin(phys)?;
+
         let _pree = PREEMPT.lock();
         let mut children = self.children.lock();
         let space = self.space.upgrade().ok_or(EKILLED)?;
@@ -155,13 +157,24 @@ impl Virt {
         let virt = find_range(&children, &self.range, offset, layout)?;
         let base = virt.start;
 
-        let phys_base = PAddr::new(*phys.base() + phys_offset);
-        let _ = children.insert(base, Child::Phys(phys, flags, layout.size()));
+        {
+            let mut end = base;
+            let phys = phys.map_iter(phys_offset, virt.end.val() - base.val());
+            for (phys_base, len) in phys {
+                let next = LAddr::from(end.val() + len);
+                let virt = end..next;
+                if let Err(err) = space.arch.maps(virt, phys_base, flags) {
+                    if base < end {
+                        let _ = space.arch.unmaps(base..end);
+                    }
+                    return Err(paging_error(err));
+                }
+                end = next;
+            }
+            assert!(end == virt.end);
+        }
 
-        space.arch.maps(virt, phys_base, flags).map_err(|err| {
-            let _ = children.remove(&base);
-            paging_error(err)
-        })?;
+        let _ = children.insert(base, Child::Phys(phys, flags, layout.size()));
 
         if set_vdso {
             *space.vdso.lock() = Some(base);

+ 110 - 36
h2o/kernel/src/mem/syscall.rs

@@ -1,10 +1,13 @@
-use alloc::sync::{Arc, Weak};
-use core::{alloc::Layout, slice};
+use alloc::{
+    sync::{Arc, Weak},
+    vec::Vec,
+};
+use core::{alloc::Layout, ptr};
 
 use bitop_ex::BitOpEx;
 use paging::LAddr;
 use sv_call::{
-    mem::{Flags, MemInfo, VirtMapInfo},
+    mem::{Flags, IoVec, MemInfo, PhysOptions, VirtMapInfo},
     *,
 };
 
@@ -15,7 +18,7 @@ use crate::{
         task::{hdl::DefaultFeature, Space as TaskSpace, VDSO},
         PREEMPT, SCHED,
     },
-    syscall::{In, Out, UserPtr},
+    syscall::{In, InOut, Out, PtrType, UserPtr},
 };
 
 fn check_flags(flags: Flags) -> Result<Flags> {
@@ -40,9 +43,12 @@ fn features_to_flags(feat: Feature) -> Flags {
 }
 
 #[syscall]
-fn phys_alloc(size: usize, zeroed: bool) -> Result<Handle> {
-    let phys = PREEMPT.scope(|| space::Phys::allocate(size, zeroed))?;
-    SCHED.with_current(|cur| unsafe { cur.space().handles().insert(phys, None) })
+fn phys_alloc(size: usize, options: PhysOptions) -> Result<Handle> {
+    let phys = PREEMPT.scope(|| space::Phys::allocate(size, options, false))?;
+    SCHED.with_current(|cur| {
+        let event = phys.event();
+        cur.space().handles().insert(phys, Some(event))
+    })
 }
 
 #[syscall]
@@ -68,57 +74,98 @@ fn phys_check(hdl: Handle, offset: usize, len: usize) -> Result<(Feature, space:
             .get::<space::Phys>(hdl)
             .map(|obj| (obj.features(), space::Phys::clone(&obj)))
     })?;
-    if offset_end > phys.len() {
-        return Err(ERANGE);
+    if phys == VDSO.1 {
+        return Err(EACCES);
     }
     Ok((feat, phys))
 }
 
 #[syscall]
-fn phys_read(hdl: Handle, offset: usize, len: usize, buffer: UserPtr<Out, u8>) -> Result {
+fn phys_read(hdl: Handle, offset: usize, len: usize, buffer: UserPtr<Out>) -> Result<usize> {
     buffer.check_slice(len)?;
     let (feat, phys) = phys_check(hdl, offset, len)?;
-    if phys == VDSO.1 {
-        return Err(EACCES);
-    }
     if !feat.contains(Feature::READ) {
         return Err(EPERM);
     }
     if len > 0 {
-        unsafe {
-            let ptr = phys.raw_ptr().add(offset);
-            let slice = slice::from_raw_parts(ptr, len);
-            buffer.write_slice(slice)?;
-        }
+        phys.read(offset, len, buffer)
+    } else {
+        Ok(0)
     }
-    Ok(())
 }
 
 #[syscall]
-fn phys_write(hdl: Handle, offset: usize, len: usize, buffer: UserPtr<In, u8>) -> Result {
+fn phys_write(hdl: Handle, offset: usize, len: usize, buffer: UserPtr<In>) -> Result<usize> {
     buffer.check_slice(len)?;
     let (feat, phys) = phys_check(hdl, offset, len)?;
-    if phys == VDSO.1 {
-        return Err(EACCES);
-    }
     if !feat.contains(Feature::WRITE) {
         return Err(EPERM);
     }
     if len > 0 {
+        phys.write(offset, len, buffer)
+    } else {
+        Ok(0)
+    }
+}
+
+static_assertions::const_assert!({
+    let a = Layout::new::<IoVec>();
+    let b = Layout::new::<(UserPtr<In>, usize)>();
+    a.size() == b.size() && a.align() == b.align()
+});
+
+#[allow(clippy::type_complexity)]
+fn check_physv<T: PtrType>(
+    hdl: Handle,
+    bufs: UserPtr<In, IoVec>,
+    count: usize,
+) -> Result<(Feature, space::Phys, Vec<(UserPtr<T>, usize)>)> {
+    hdl.check_null()?;
+    bufs.check_slice(count)?;
+    let (feat, phys) = SCHED.with_current(|cur| {
+        cur.space()
+            .handles()
+            .get::<space::Phys>(hdl)
+            .map(|obj| (obj.features(), space::Phys::clone(&obj)))
+    })?;
+    let bufs = {
+        let mut vec = Vec::<(UserPtr<T>, usize)>::with_capacity(count);
+        let mem = vec.spare_capacity_mut();
         unsafe {
-            let ptr = phys.raw_ptr().add(offset);
-            buffer.read_slice(ptr, len)?;
+            bufs.read_slice(mem.as_mut_ptr() as _, count)?;
+            vec.set_len(count);
         }
+        vec
+    };
+    Ok((feat, phys, bufs))
+}
+
+#[syscall]
+fn phys_readv(hdl: Handle, offset: usize, bufs: UserPtr<In, IoVec>, count: usize) -> Result<usize> {
+    let (feat, phys, bufs) = check_physv(hdl, bufs, count)?;
+    if !feat.contains(Feature::READ) {
+        return Err(EPERM);
+    }
+    phys.read_vectored(offset, &bufs)
+}
+
+#[syscall]
+fn phys_writev(
+    hdl: Handle,
+    offset: usize,
+    bufs: UserPtr<In, IoVec>,
+    count: usize,
+) -> Result<usize> {
+    let (feat, phys, bufs) = check_physv(hdl, bufs, count)?;
+    if !feat.contains(Feature::WRITE) {
+        return Err(EPERM);
     }
-    Ok(())
+    phys.write_vectored(offset, &bufs)
 }
 
 #[syscall]
 fn phys_sub(hdl: Handle, offset: usize, len: usize, copy: bool) -> Result<Handle> {
     let (feat, phys) = phys_check(hdl, offset, len)?;
-    if phys == VDSO.1 {
-        return Err(EACCES);
-    }
     if !feat.contains(Feature::READ) {
         return Err(EPERM);
     }
@@ -126,14 +173,35 @@ fn phys_sub(hdl: Handle, offset: usize, len: usize, copy: bool) -> Result<Handle
     let sub = phys.create_sub(offset, len, copy)?;
     SCHED.with_current(|cur| {
         let handles = cur.space().handles();
+        let event = sub.event();
         if copy {
-            handles.insert(sub, None)
+            handles.insert(sub, Some(event))
         } else {
-            unsafe { handles.insert_unchecked(sub, feat, None) }
+            unsafe { handles.insert_unchecked(sub, feat, Some(event)) }
         }
     })
 }
 
+#[syscall]
+fn phys_resize(hdl: Handle, new_len: usize, zeroed: bool) -> Result {
+    if new_len == 0 {
+        return Err(EINVAL);
+    }
+    let (feat, phys) = SCHED.with_current(|cur| {
+        cur.space()
+            .handles()
+            .get::<space::Phys>(hdl)
+            .map(|obj| (obj.features(), space::Phys::clone(&obj)))
+    })?;
+    if phys == VDSO.1 {
+        return Err(EACCES);
+    }
+    if !feat.contains(Feature::READ | Feature::WRITE | Feature::EXECUTE) {
+        return Err(EPERM);
+    }
+    phys.resize(new_len, zeroed)
+}
+
 #[syscall]
 fn space_new(root_virt: UserPtr<Out, Handle>) -> Result<Handle> {
     root_virt.check()?;
@@ -192,9 +260,9 @@ fn virt_drop(hdl: Handle) -> Result {
 }
 
 #[syscall]
-fn virt_map(hdl: Handle, mi: UserPtr<In, VirtMapInfo>) -> Result<*mut u8> {
+fn virt_map(hdl: Handle, mi_ptr: UserPtr<InOut, VirtMapInfo>) -> Result<*mut u8> {
     hdl.check_null()?;
-    let mi = unsafe { mi.read() }?;
+    let mi = unsafe { mi_ptr.read() }?;
     let flags = check_flags(mi.flags)?;
     SCHED.with_current(|cur| {
         let virt = cur.space().handles().get::<Weak<space::Virt>>(hdl)?;
@@ -205,19 +273,25 @@ fn virt_map(hdl: Handle, mi: UserPtr<In, VirtMapInfo>) -> Result<*mut u8> {
             return Err(EPERM);
         }
 
+        let size = if mi.len == 0 { phys.len() } else { mi.len };
+        let layout = Layout::from_size_align(size, mi.align)?;
         let addr = virt.map(
             offset,
             space::Phys::clone(&phys),
             mi.phys_offset,
-            space::page_aligned(mi.len),
+            layout,
             flags,
         )?;
+        unsafe {
+            let len = UserPtr::<Out, _>::new(ptr::addr_of_mut!((*mi_ptr.as_ptr()).len));
+            len.write(size)?;
+        }
         Ok(*addr)
     })
 }
 
 #[syscall]
-fn virt_reprot(hdl: Handle, base: UserPtr<In, u8>, len: usize, flags: Flags) -> Result {
+fn virt_reprot(hdl: Handle, base: UserPtr<In>, len: usize, flags: Flags) -> Result {
     hdl.check_null()?;
     base.check()?;
     let flags = check_flags(flags)?;
@@ -229,7 +303,7 @@ fn virt_reprot(hdl: Handle, base: UserPtr<In, u8>, len: usize, flags: Flags) ->
 }
 
 #[syscall]
-fn virt_unmap(hdl: Handle, base: UserPtr<In, u8>, len: usize, drop_child: bool) -> Result {
+fn virt_unmap(hdl: Handle, base: UserPtr<In>, len: usize, drop_child: bool) -> Result {
     hdl.check_null()?;
     base.check()?;
     SCHED.with_current(|cur| {

+ 39 - 11
h2o/kernel/src/sched/imp.rs

@@ -6,7 +6,7 @@ use alloc::vec::Vec;
 use core::{
     assert_matches::assert_matches,
     cell::UnsafeCell,
-    hint, mem,
+    hint,
     sync::atomic::{AtomicU64, Ordering::*},
     time::Duration,
 };
@@ -83,7 +83,7 @@ impl Scheduler {
     fn enqueue(&self, task: task::Ready, pree: PreemptStateGuard, preempt: bool) {
         SCHED_INFO[self.cpu]
             .expected_runtime
-            .fetch_add(task.time_slice.as_millis() as u64, Release);
+            .fetch_add(task.time_slice.as_micros() as u64, Release);
         // SAFETY: We have `pree`, which means preemption is disabled.
         match unsafe { &*self.current.get() } {
             Some(ref cur) if preempt && Self::should_preempt(cur, &task) => {
@@ -166,7 +166,7 @@ impl Scheduler {
     /// # Panics
     ///
     /// Panics if the scheduler unexpectedly returns.
-    pub fn exit_current(&self, retval: usize) -> ! {
+    pub fn exit_current(&self, retval: usize, kill_all: bool) -> ! {
         self.canary.assert();
         let pree = PREEMPT.lock();
 
@@ -181,6 +181,10 @@ impl Scheduler {
             SCHED_INFO[self.cpu]
                 .expected_runtime
                 .fetch_sub(current.time_slice.as_micros() as u64, Release);
+
+            if kill_all {
+                current.space().try_stop(&current.tid);
+            }
         }
 
         let _ = self.schedule_impl(Instant::now(), pree, None, |task| {
@@ -221,6 +225,25 @@ impl Scheduler {
             None => return Some(pree),
         };
         log::trace!("Checking task {:?}'s pending signal", cur.tid.raw());
+
+        if cur.space().has_to_stop() {
+            log::trace!(
+                "Killing task {:?}, P{} due to main task stopped",
+                cur.tid.raw(),
+                PREEMPT.raw()
+            );
+
+            SCHED_INFO[self.cpu]
+                .expected_runtime
+                .fetch_sub(cur.time_slice.as_micros() as u64, Release);
+
+            let _ = self.schedule_impl(cur_time, pree, None, |task| {
+                task::Ready::exit(task, sv_call::EKILLED.into_retval());
+                Ok(())
+            });
+            unreachable!("Dead task");
+        }
+
         let ti = &*cur.tid;
 
         if ti.ty() == task::Type::Kernel {
@@ -234,6 +257,7 @@ impl Scheduler {
                 SCHED_INFO[self.cpu]
                     .expected_runtime
                     .fetch_sub(cur.time_slice.as_micros() as u64, Release);
+                cur.space().try_stop(&cur.tid);
 
                 let _ = self.schedule_impl(cur_time, pree, None, |task| {
                     task::Ready::exit(task, sv_call::EKILLED.into_retval());
@@ -272,7 +296,7 @@ impl Scheduler {
 
         match cur.running_state.start_time() {
             Some(start_time) => {
-                // FIXME: Some platform like QEMU doesn't support invariant TSC, so the assert
+                // FIXME: Some platforms like QEMU don't support invariant TSC, so the assert
                 // below can really fail. By far, comment it out to avoid kernel panic.
                 //
                 // debug_assert!(cur_time > start_time);
@@ -346,9 +370,7 @@ impl Scheduler {
         }
         .unzip();
 
-        // We will enable preemption in `switch_ctx`.
-        mem::forget(pree);
-        unsafe { task::ctx::switch_ctx(old, new) };
+        unsafe { task::ctx::switch_ctx(old, new, pree) };
         ret.transpose().and_then(|res| res.ok_or(sv_call::ESRCH))
     }
 }
@@ -360,8 +382,9 @@ fn select_cpu(
 ) -> Option<usize> {
     let mut iter = affinity.iter_ones();
     let mut ret = iter.next()?;
+    let mut rret = SCHED_INFO[ret].expected_runtime();
 
-    if ret == cur_cpu && SCHED_INFO[ret].expected_runtime() == 0 {
+    if ret == cur_cpu && rret == 0 {
         return Some(ret);
     }
 
@@ -373,12 +396,14 @@ fn select_cpu(
 
         let a = ret;
 
+        // Attempt to pin a task to its last CPU.
         let wlast_cpu = match last_cpu {
             Some(last_cpu) if a == last_cpu && b != last_cpu => 1,
             Some(last_cpu) if a != last_cpu && b == last_cpu => -1,
             _ => 0,
         };
 
+        // Attempt to reduce the times of raising `TASK_MIGRATE` interrupt.
         let wcur_cpu = if a == cur_cpu && b != cur_cpu {
             1
         } else if a != cur_cpu && b == cur_cpu {
@@ -387,8 +412,9 @@ fn select_cpu(
             0
         };
 
+        // Attempt to balance the load of each CPU.
         let wruntime = {
-            let ra = SCHED_INFO[a].expected_runtime();
+            let ra = rret;
             let diff = ra.abs_diff(rb);
             if diff <= 1 {
                 0
@@ -397,9 +423,11 @@ fn select_cpu(
             }
         };
 
-        let weight = wlast_cpu * 10 + wcur_cpu * 2 + wruntime * 20;
+        let weight = wlast_cpu * 15 + wcur_cpu + wruntime * 40;
 
-        ret = if weight > 0 { a } else { b };
+        if weight < 0 {
+            (ret, rret) = (b, rb);
+        }
     }
 
     Some(ret)

+ 51 - 14
h2o/kernel/src/sched/imp/waiter.rs

@@ -33,12 +33,24 @@ pub struct Blocker {
 }
 
 impl Blocker {
-    pub fn new(event: &Arc<dyn Event>, wake_all: bool, signal: usize) -> Arc<Self> {
+    pub fn new(
+        event: &Arc<dyn Event>,
+        level_triggered: bool,
+        wake_all: bool,
+        signal: usize,
+    ) -> Arc<Self> {
         let ret = Arc::new(Blocker {
             wake_all,
             wo: WaitObject::new(),
             event: Arc::downgrade(event) as _,
-            waiter_data: WaiterData::new(TriggerMode::Level, signal),
+            waiter_data: WaiterData::new(
+                if level_triggered {
+                    TriggerMode::Level
+                } else {
+                    TriggerMode::Edge
+                },
+                signal,
+            ),
             status: Mutex::new((true, 0)),
         });
         event.wait(Arc::clone(&ret) as _);
@@ -110,6 +122,13 @@ struct Request {
     syscall: Option<Syscall>,
 }
 
+#[derive(Debug)]
+struct Ready {
+    canceled: bool,
+    signal: usize,
+    request: Request,
+}
+
 #[derive(Debug)]
 pub struct Dispatcher {
     next_key: AtomicUsize,
@@ -117,7 +136,7 @@ pub struct Dispatcher {
 
     capacity: usize,
     pending: Mutex<Vec<Request>>,
-    ready: SegQueue<(bool, Request)>,
+    ready: SegQueue<Ready>,
 }
 
 impl Dispatcher {
@@ -162,14 +181,24 @@ impl Dispatcher {
         Ok(key)
     }
 
-    pub fn pop(self: &Arc<Self>) -> Option<(bool, usize, Option<Syscall>)> {
-        let (canceled, req) = self.ready.pop()?;
-        if let Some(event) = req.event.upgrade() {
+    pub fn pop(
+        self: &Arc<Self>,
+        key: &mut usize,
+        signal_slot: &mut usize,
+    ) -> Option<(bool, Option<Syscall>)> {
+        let Ready {
+            canceled,
+            signal,
+            request,
+        } = self.ready.pop()?;
+        if let Some(event) = request.event.upgrade() {
             event.unwait(&(Arc::clone(self) as _));
         }
-        let res = if !canceled { req.syscall } else { None };
+        let res = if !canceled { request.syscall } else { None };
         self.event.notify(0, SIG_WRITE);
-        Some((canceled, req.key, res))
+        *key = request.key;
+        *signal_slot = signal;
+        Some((canceled, res))
     }
 }
 
@@ -187,14 +216,18 @@ impl Waiter for Dispatcher {
                 let (e, _) = req.event.as_ptr().to_raw_parts();
                 e == event && req.waiter_data.can_signal(signal, false)
             });
-            iter.for_each(|req| {
-                self.ready.push((false, req));
+            iter.for_each(|request| {
+                self.ready.push(Ready {
+                    canceled: false,
+                    signal,
+                    request,
+                });
                 has_cancel = true;
             });
         });
 
         if has_cancel {
-            self.event.notify(0, SIG_READ)
+            self.event.notify(0, SIG_READ);
         }
     }
 
@@ -214,15 +247,19 @@ impl Waiter for Dispatcher {
                 let (e, _) = req.event.as_ptr().to_raw_parts();
                 e == event && req.waiter_data.can_signal(signal, on_wait)
             });
-            iter.for_each(|req| {
-                self.ready.push((false, req));
+            iter.for_each(|request| {
+                self.ready.push(Ready {
+                    canceled: false,
+                    signal,
+                    request,
+                });
                 has_notify = true;
             });
             pending.is_empty()
         });
 
         if has_notify {
-            self.event.notify(0, SIG_READ)
+            self.event.notify(0, SIG_READ);
         }
         empty
     }

+ 59 - 17
h2o/kernel/src/sched/ipc.rs

@@ -86,23 +86,23 @@ pub trait Event: Debug + Send + Sync {
     }
 
     #[inline]
-    fn notify(&self, clear: usize, set: usize) {
-        self.notify_impl(clear, set);
+    fn notify(&self, clear: usize, set: usize) -> usize {
+        self.notify_impl(clear, set)
     }
 
-    fn notify_impl(&self, clear: usize, set: usize) {
+    fn notify_impl(&self, clear: usize, set: usize) -> usize {
         let mut prev = self.event_data().signal.load(SeqCst);
         let signal = loop {
             let new = (prev & !clear) | set;
             if prev == new {
-                return;
+                return prev;
             }
             match self
                 .event_data()
                 .signal
                 .compare_exchange_weak(prev, new, SeqCst, SeqCst)
             {
-                Ok(_) if prev & new == new => return,
+                Ok(_) if prev & new == new => return new,
                 Ok(_) => break new,
                 Err(signal) => {
                     prev = signal;
@@ -115,6 +115,7 @@ pub trait Event: Debug + Send + Sync {
                 .waiters
                 .retain(|_, waiter| !waiter.try_on_notify(self as *const _ as _, signal, false))
         });
+        signal
     }
 }
 
@@ -173,12 +174,50 @@ mod syscall {
     use super::*;
     use crate::{
         cpu::{arch::apic::TriggerMode, time},
-        sched::{Blocker, Dispatcher, WaiterData, SCHED},
+        sched::{BasicEvent, Blocker, Dispatcher, WaiterData, SCHED},
         syscall::{In, Out, UserPtr},
     };
 
     #[syscall]
-    fn obj_wait(hdl: Handle, timeout_us: u64, wake_all: bool, signal: usize) -> Result<usize> {
+    fn event_new(init_signal: usize) -> Result<Handle> {
+        let obj = BasicEvent::new(init_signal);
+        let event = Arc::downgrade(&obj) as _;
+        SCHED.with_current(|cur| cur.space().handles().insert_raw(obj, Some(event)))
+    }
+
+    #[syscall]
+    fn event_notify(hdl: Handle, clear: usize, set: usize) -> Result<usize> {
+        hdl.check_null()?;
+        let event = SCHED.with_current(|cur| {
+            cur.space()
+                .handles()
+                .get::<BasicEvent>(hdl)
+                .map(|event| Arc::clone(&event))
+        })?;
+        Ok(event.notify(clear, set))
+    }
+
+    #[syscall]
+    fn event_cancel(hdl: Handle) -> Result {
+        hdl.check_null()?;
+        let event = SCHED.with_current(|cur| {
+            cur.space()
+                .handles()
+                .get::<BasicEvent>(hdl)
+                .map(|event| Arc::clone(&event))
+        })?;
+        event.cancel();
+        Ok(())
+    }
+
+    #[syscall]
+    fn obj_wait(
+        hdl: Handle,
+        timeout_us: u64,
+        level_triggered: bool,
+        wake_all: bool,
+        signal: usize,
+    ) -> Result<usize> {
         let pree = PREEMPT.lock();
         let cur = unsafe { (*SCHED.current()).as_ref().ok_or(ESRCH) }?;
 
@@ -188,7 +227,7 @@ mod syscall {
         }
         let event = obj.event().upgrade().ok_or(EPIPE)?;
 
-        let blocker = Blocker::new(&event, wake_all, signal);
+        let blocker = Blocker::new(&event, level_triggered, wake_all, signal);
         blocker.wait(Some(pree), time::from_us(timeout_us))?;
 
         let (detach_ret, signal) = blocker.detach();
@@ -218,10 +257,7 @@ mod syscall {
         let syscall = (!syscall.as_ptr().is_null())
             .then(|| {
                 let syscall = unsafe { syscall.read() }?;
-                if matches!(
-                    syscall.num as usize,
-                    SV_DISP_NEW | SV_DISP_PUSH | SV_DISP_POP
-                ) {
+                if matches!(syscall.num, SV_DISP_NEW | SV_DISP_PUSH | SV_DISP_POP) {
                     return Err(EPERM);
                 }
                 Ok(syscall)
@@ -254,20 +290,26 @@ mod syscall {
     #[syscall]
     fn disp_pop(
         disp: Handle,
-        canceled: UserPtr<Out, bool>,
+        signal_slot: UserPtr<Out, usize>,
         result: UserPtr<Out, usize>,
     ) -> Result<usize> {
         disp.check_null()?;
-        let (c, key, r) = SCHED.with_current(|cur| {
+        let mut key = 0;
+        let mut signal = 0;
+        let (c, r) = SCHED.with_current(|cur| {
             let disp = cur.space().handles().get::<Dispatcher>(disp)?;
             if !disp.features().contains(Feature::READ) {
                 return Err(EPERM);
             }
-            disp.pop().ok_or(ENOENT)
+            disp.pop(&mut key, &mut signal).ok_or(ENOENT)
         })?;
 
-        if !canceled.as_ptr().is_null() {
-            canceled.write(c)?;
+        if !signal_slot.as_ptr().is_null() {
+            if c {
+                signal_slot.write(0)?;
+            } else {
+                signal_slot.write(signal)?;
+            }
         }
         let r = r.map_or(0, crate::syscall::handle);
         if !result.as_ptr().is_null() {

+ 62 - 0
h2o/kernel/src/sched/ipc/arsc.rs

@@ -6,6 +6,7 @@ use core::{
     marker::{PhantomData, Unsize},
     mem::{self, ManuallyDrop, MaybeUninit},
     ops::{CoerceUnsized, Deref, Receiver},
+    pin::Pin,
     ptr::{self, NonNull},
     sync::atomic::{self, AtomicUsize, Ordering::*},
 };
@@ -76,10 +77,39 @@ impl<T> Arsc<T, Global> {
         Self::try_new_in(data, Global)
     }
 
+    #[inline]
+    pub fn new(data: T) -> Self {
+        Self::try_new(data).expect("Failed to create an Arsc")
+    }
+
+    #[inline]
+    pub fn pin(data: T) -> Pin<Self> {
+        unsafe { Pin::new_unchecked(Self::new(data)) }
+    }
+
     #[inline]
     pub fn try_new_uninit() -> Result<Arsc<MaybeUninit<T>, Global>, AllocError> {
         Self::try_new_uninit_in(Global)
     }
+
+    pub fn try_unwrap(this: Self) -> Result<T, Self> {
+        let ref_count = unsafe { &this.inner.as_ref().ref_count };
+        if ref_count.compare_exchange(1, 0, Acquire, Relaxed).is_err() {
+            return Err(this);
+        }
+
+        atomic::fence(Acquire);
+
+        unsafe {
+            ref_count.store(1, Relaxed);
+
+            let data = ptr::read(&this.inner.as_ref().data);
+            let ptr = Self::into_raw(this) as *const MaybeUninit<T>;
+            let _ = Arsc::from_raw(ptr);
+
+            Ok(data)
+        }
+    }
 }
 
 impl<T, A: Allocator> Arsc<MaybeUninit<T>, A> {
@@ -133,6 +163,33 @@ impl<T: ?Sized, A: Allocator> Arsc<T, A> {
     }
 }
 
+impl<T> Arsc<T, Global> {
+    #[must_use]
+    pub fn into_raw(this: Self) -> *const T {
+        let ptr = Self::as_ptr(&this);
+        mem::forget(this);
+        ptr
+    }
+
+    /// # Safety
+    ///
+    /// The raw pointer must have been previously returned by a call to
+    /// [`Arsc<U>::into_raw`][into_raw] where `U` must have the same size and
+    /// alignment as `T`. This is trivially true if `U` is `T`.
+    /// Note that if `U` is not `T` but has the same size and alignment, this is
+    /// basically like transmuting references of different types. See
+    /// [`mem::transmute`][transmute] for more information on what
+    /// restrictions apply in this case.
+    ///
+    /// [into_raw]: Arsc::into_raw
+    /// [transmute]: core::mem::transmute
+    pub unsafe fn from_raw(ptr: *const T) -> Self {
+        let offset = memoffset::offset_of!(ArscInner<T, Global>, data);
+        let inner = unsafe { ptr.byte_sub(offset) as *mut ArscInner<T, Global> };
+        unsafe { Self::from_inner(NonNull::new_unchecked(inner)) }
+    }
+}
+
 impl<T, A: Allocator> Arsc<T, A> {
     pub fn try_make_mut_with<F, E>(this: &mut Self, clone: F) -> Result<&mut T, E>
     where
@@ -161,6 +218,11 @@ impl<T, A: Allocator> Arsc<T, A> {
         let alloc = unsafe { &this.inner.as_ref().alloc };
         Self::try_make_mut_with(this, |t| Ok((T::clone(t), A::clone(alloc))))
     }
+
+    #[inline]
+    pub fn count(this: &Self) -> usize {
+        unsafe { this.inner.as_ref().ref_count.load(Acquire) }
+    }
 }
 
 impl<A: Allocator> Arsc<dyn Any, A> {

+ 10 - 0
h2o/kernel/src/sched/ipc/basic.rs

@@ -1,4 +1,7 @@
+use sv_call::Feature;
+
 use super::*;
+use crate::sched::task::hdl::DefaultFeature;
 
 #[derive(Debug, Default)]
 pub struct BasicEvent {
@@ -20,3 +23,10 @@ impl Event for BasicEvent {
         &self.event_data
     }
 }
+
+unsafe impl DefaultFeature for BasicEvent {
+    #[inline]
+    fn default_features() -> sv_call::Feature {
+        Feature::SEND | Feature::SYNC | Feature::WAIT | Feature::EXECUTE
+    }
+}

+ 3 - 98
h2o/kernel/src/sched/ipc/channel.rs

@@ -1,12 +1,9 @@
 mod syscall;
 
-use alloc::{
-    collections::BTreeMap,
-    sync::{Arc, Weak},
-};
+use alloc::sync::{Arc, Weak};
 use core::{
     mem,
-    sync::atomic::{AtomicU64, AtomicUsize, Ordering::SeqCst},
+    sync::atomic::{AtomicU64, Ordering::SeqCst},
 };
 
 use bytes::Bytes;
@@ -58,29 +55,18 @@ impl Packet {
     }
 }
 
-#[derive(Debug, Default)]
-struct Caller {
-    cell: Option<Packet>,
-    event: Arc<BasicEvent>,
-    head: Option<Packet>,
-}
-
 #[derive(Debug)]
 struct ChannelSide {
-    msg_id: AtomicUsize,
     msgs: SegQueue<Packet>,
     event: Arc<BasicEvent>,
-    callers: Mutex<BTreeMap<usize, Caller>>,
 }
 
 impl Default for ChannelSide {
     #[inline]
     fn default() -> Self {
         ChannelSide {
-            msg_id: AtomicUsize::new(sv_call::ipc::CUSTOM_MSG_ID_END),
             msgs: SegQueue::new(),
             event: BasicEvent::new(0),
-            callers: Mutex::new(BTreeMap::new()),
         }
     }
 }
@@ -130,21 +116,7 @@ impl Channel {
     /// Returns error if the peer is closed or if the channel is full.
     pub fn send(&self, msg: &mut Packet) -> sv_call::Result {
         let peer = self.peer.upgrade().ok_or(sv_call::EPIPE)?;
-        let called = PREEMPT.scope(|| {
-            let mut callers = peer.callers.lock();
-            let called = callers.get_mut(&msg.id);
-            if let Some(caller) = called {
-                let _old = caller.cell.replace(mem::take(msg));
-                caller.event.notify(0, SIG_READ);
-                debug_assert!(_old.is_none());
-                true
-            } else {
-                false
-            }
-        });
-        if called {
-            Ok(())
-        } else if peer.msgs.len() >= MAX_QUEUE_SIZE {
+        if peer.msgs.len() >= MAX_QUEUE_SIZE {
             Err(sv_call::ENOSPC)
         } else {
             peer.msgs.push(mem::take(msg));
@@ -194,69 +166,6 @@ impl Channel {
         }
         unsafe { Self::get_packet(&mut head, buffer_cap, handle_cap) }
     }
-
-    #[inline]
-    fn next_msg_id(id: &AtomicUsize) -> usize {
-        id.fetch_update(SeqCst, SeqCst, |id| {
-            Some(if id == usize::MAX {
-                sv_call::ipc::CUSTOM_MSG_ID_END
-            } else {
-                id + 1
-            })
-        })
-        .unwrap()
-    }
-
-    pub fn call_send(&self, msg: &mut Packet) -> sv_call::Result<usize> {
-        let peer = self.peer.upgrade().ok_or(sv_call::EPIPE)?;
-        if peer.msgs.len() >= MAX_QUEUE_SIZE {
-            Err(sv_call::ENOSPC)
-        } else {
-            let id = Self::next_msg_id(&self.me.msg_id);
-            msg.id = id;
-            PREEMPT.scope(|| {
-                { self.me.callers.lock() }
-                    .try_insert(id, Caller::default())
-                    .map_or(Err(sv_call::EEXIST), |_| Ok(()))
-            })?;
-            peer.msgs.push(mem::take(msg));
-            peer.event.notify(0, SIG_READ);
-            Ok(id)
-        }
-    }
-
-    fn call_event(&self, id: usize) -> sv_call::Result<Arc<BasicEvent>> {
-        PREEMPT.scope(|| {
-            { self.me.callers.lock() }
-                .get(&id)
-                .map_or(Err(sv_call::ENOENT), |ent| Ok(Arc::clone(&ent.event)))
-        })
-    }
-
-    pub fn call_receive(
-        &self,
-        id: usize,
-        buffer_cap: &mut usize,
-        handle_cap: &mut usize,
-    ) -> sv_call::Result<Packet> {
-        let _pree = PREEMPT.lock();
-        let mut callers = self.me.callers.lock();
-        let mut caller = match callers.entry(id) {
-            alloc::collections::btree_map::Entry::Vacant(_) => return Err(sv_call::ENOENT),
-            alloc::collections::btree_map::Entry::Occupied(caller) => caller,
-        };
-        if caller.get().head.is_none() {
-            let err = if self.peer.strong_count() > 0 {
-                sv_call::ENOENT
-            } else {
-                sv_call::EPIPE
-            };
-            let packet = caller.get_mut().cell.take().ok_or(err)?;
-            caller.get_mut().head = Some(packet);
-        }
-        unsafe { Self::get_packet(&mut caller.get_mut().head, buffer_cap, handle_cap) }
-            .inspect(|_| drop(caller.remove()))
-    }
 }
 
 unsafe impl DefaultFeature for Channel {
@@ -269,10 +178,6 @@ impl Drop for Channel {
     fn drop(&mut self) {
         if let Some(peer) = self.peer.upgrade() {
             peer.event.cancel();
-            let _pree = PREEMPT.lock();
-            for (_, caller) in peer.callers.lock().iter() {
-                caller.event.cancel();
-            }
         }
     }
 }

+ 3 - 97
h2o/kernel/src/sched/ipc/channel/syscall.rs

@@ -7,8 +7,7 @@ use sv_call::{
 
 use super::*;
 use crate::{
-    cpu::{arch::apic::TriggerMode, time},
-    sched::{Dispatcher, WaiterData, SIG_READ},
+    sched::SIG_READ,
     syscall::{In, InOut, Out, UserPtr},
 };
 
@@ -41,7 +40,7 @@ where
         return Err(ENOMEM);
     }
     UserPtr::<In, Handle>::new(packet.handles).check_slice(packet.handle_count)?;
-    UserPtr::<In, u8>::new(packet.buffer).check_slice(packet.buffer_size)?;
+    UserPtr::<In>::new(packet.buffer).check_slice(packet.buffer_size)?;
 
     let handles = unsafe { slice::from_raw_parts(packet.handles, packet.handle_count) };
     if handles.contains(&hdl) {
@@ -65,7 +64,7 @@ where
 fn read_raw(packet_ptr: UserPtr<In, RawPacket>) -> Result<RawPacket> {
     let raw = unsafe { packet_ptr.read()? };
     UserPtr::<Out, Handle>::new(raw.handles).check_slice(raw.handle_cap)?;
-    UserPtr::<Out, u8>::new(raw.buffer).check_slice(raw.buffer_cap)?;
+    UserPtr::<Out>::new(raw.buffer).check_slice(raw.buffer_cap)?;
 
     Ok(raw)
 }
@@ -130,96 +129,3 @@ fn chan_recv(hdl: Handle, packet_ptr: UserPtr<InOut, RawPacket>) -> Result {
 
     write_raw_with_rest_of_packet(packet_ptr.out(), raw, res)
 }
-
-#[syscall]
-fn chan_csend(hdl: Handle, packet: UserPtr<In, RawPacket>) -> Result<usize> {
-    chan_send_impl(hdl, packet, |channel, packet| channel.call_send(packet))
-}
-
-#[syscall]
-fn chan_crecv(
-    hdl: Handle,
-    id: usize,
-    packet_ptr: UserPtr<InOut, RawPacket>,
-    timeout_us: u64,
-) -> Result {
-    hdl.check_null()?;
-
-    let mut raw = read_raw(packet_ptr.r#in())?;
-
-    let call_event = SCHED.with_current(|cur| {
-        let channel = cur.space().handles().get::<Channel>(hdl)?;
-        if !{ channel.features() }.contains(Feature::WAIT | Feature::READ) {
-            return Err(EPERM);
-        }
-        Ok(channel.call_event(id)? as _)
-    })?;
-    let blocker = if timeout_us == 0 {
-        None
-    } else {
-        let pree = PREEMPT.lock();
-        let blocker = crate::sched::Blocker::new(&call_event, true, SIG_READ);
-        blocker.wait(Some(pree), time::from_us(timeout_us))?;
-        Some(blocker)
-    };
-
-    let res = SCHED.with_current(|cur| {
-        let map = cur.space().handles();
-
-        let channel = map.get::<Channel>(hdl)?;
-        if !channel.features().contains(Feature::READ) {
-            return Err(EPERM);
-        }
-
-        raw.buffer_size = raw.buffer_cap;
-        raw.handle_count = raw.handle_cap;
-        let res = channel.call_receive(id, &mut raw.buffer_size, &mut raw.handle_count);
-        receive_handles(res, map, &mut raw, &call_event)
-    });
-
-    if let Some(blocker) = blocker {
-        if !blocker.detach().0 {
-            return Err(ETIME);
-        }
-    }
-
-    write_raw_with_rest_of_packet(packet_ptr.out(), raw, res)
-}
-
-#[syscall]
-fn chan_acrecv(
-    hdl: Handle,
-    id: usize,
-    disp: Handle,
-    syscall: UserPtr<In, Syscall>,
-) -> Result<usize> {
-    hdl.check_null()?;
-    disp.check_null()?;
-    let syscall = (!syscall.as_ptr().is_null())
-        .then(|| {
-            let syscall = unsafe { syscall.read() }?;
-            if matches!(
-                syscall.num as usize,
-                SV_DISP_NEW | SV_DISP_PUSH | SV_DISP_POP
-            ) {
-                return Err(EPERM);
-            }
-            Ok(syscall)
-        })
-        .transpose()?;
-
-    SCHED.with_current(|cur| {
-        let chan = cur.space().handles().get::<Channel>(hdl)?;
-        let disp = cur.space().handles().get::<Dispatcher>(disp)?;
-        if !chan.features().contains(Feature::WAIT) {
-            return Err(EPERM);
-        }
-        if !disp.features().contains(Feature::WRITE) {
-            return Err(EPERM);
-        }
-        let event = chan.call_event(id)? as _;
-
-        let waiter_data = WaiterData::new(TriggerMode::Level, SIG_READ);
-        disp.push(&event, waiter_data, syscall)
-    })
-}

+ 7 - 4
h2o/kernel/src/sched/task.rs

@@ -72,7 +72,7 @@ fn exec_inner(
 ) -> sv_call::Result<Init> {
     let ty = Type::pass(ty, cur.ty())?;
     let ti = TaskInfo::builder()
-        .from(Some(cur.clone()))
+        .from(cur.downgrade())
         .excep_chan(Arsc::try_new(Default::default())?)
         .name(name.unwrap_or(format!("{}.func{}", cur.name(), archop::rand::get())))
         .ty(ty)
@@ -81,6 +81,7 @@ fn exec_inner(
         .unwrap();
 
     let tid = tid::allocate(ti).map_err(|_| sv_call::EBUSY)?;
+    space.set_main(&tid);
 
     let entry = ctx::Entry {
         entry: s.entry,
@@ -114,12 +115,12 @@ fn exec(
     })
 }
 
-fn create(name: Option<String>, space: Arc<Space>) -> sv_call::Result<(Init, sv_call::Handle)> {
+fn create(name: Option<String>, space: Arc<Space>, init_chan: sv_call::Handle) -> sv_call::Result<(Init, sv_call::Handle)> {
     let cur = super::SCHED.with_current(|cur| Ok(cur.tid.clone()))?;
 
     let ty = cur.ty();
     let ti = TaskInfo::builder()
-        .from(Some(cur.clone()))
+        .from(cur.downgrade())
         .excep_chan(Arsc::try_new(Default::default())?)
         .name(name.unwrap_or(format!("{}.func{}", cur.name(), archop::rand::get())))
         .ty(ty)
@@ -128,8 +129,10 @@ fn create(name: Option<String>, space: Arc<Space>) -> sv_call::Result<(Init, sv_
         .unwrap();
 
     let tid = tid::allocate(ti).map_err(|_| sv_call::EBUSY)?;
+    space.set_main(&tid);
 
-    let kstack = ctx::Kstack::new(None, ty);
+    let mut kstack = ctx::Kstack::new(None, ty);
+    kstack.task_frame_mut().set_args(init_chan.raw() as _, 0);
     let ext_frame = ctx::ExtFrame::zeroed();
 
     let init = Init::new(tid, space, kstack, ext_frame);

+ 6 - 2
h2o/kernel/src/sched/task/boot.rs

@@ -16,8 +16,12 @@ use crate::{
 static VDSO_DATA: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/target/vdso"));
 pub static VDSO: Azy<(Flags, Phys)> = Azy::new(|| {
     let flags = Flags::READABLE | Flags::EXECUTABLE | Flags::USER_ACCESS;
-    let vdso_mem = Phys::allocate(VDSO_DATA.len().round_up_bit(paging::PAGE_SHIFT), false)
-        .expect("Failed to allocate memory for VDSO");
+    let vdso_mem = Phys::allocate(
+        VDSO_DATA.len().round_up_bit(paging::PAGE_SHIFT),
+        Default::default(),
+        true,
+    )
+    .expect("Failed to allocate memory for VDSO");
     unsafe {
         let dst = vdso_mem.base().to_laddr(minfo::ID_OFFSET);
         dst.copy_from_nonoverlapping(VDSO_DATA.as_ptr(), VDSO_DATA.len());

+ 5 - 3
h2o/kernel/src/sched/task/ctx.rs

@@ -14,6 +14,7 @@ use core::{
     ptr::{self, NonNull},
 };
 
+use archop::PreemptStateGuard;
 use paging::{LAddr, PAGE_SIZE};
 
 use crate::{
@@ -196,7 +197,8 @@ impl DerefMut for ExtFrame {
     }
 }
 
-pub unsafe fn switch_ctx(old: Option<*mut *mut u8>, new: *mut u8) {
-    arch::switch_kframe(old.unwrap_or(ptr::null_mut()), new);
-    arch::switch_finishing();
+pub unsafe fn switch_ctx(old: Option<*mut *mut u8>, new: *mut u8, pree: PreemptStateGuard) {
+    let (mut pv, mut pf) = pree.into_raw();
+    arch::switch_kframe(old.unwrap_or(ptr::null_mut()), new, &mut pv, &mut pf);
+    arch::switch_finishing(pv, pf);
 }

+ 16 - 3
h2o/kernel/src/sched/task/ctx/x86_64.rs

@@ -29,6 +29,8 @@ pub const EXTENDED_FRAME_SIZE: usize = 576;
 #[repr(C)]
 pub struct Kframe {
     cs: u64,
+    pree0: u64,
+    pree1: u64,
     rflags: u64,
     r15: u64,
     r14: u64,
@@ -108,6 +110,12 @@ impl Frame {
         self.rsi = entry.args[1];
     }
 
+    #[inline]
+    pub fn set_args(&mut self, arg0: u64, arg1: u64) {
+        self.rdi = arg0;
+        self.rsi = arg1;
+    }
+
     #[inline]
     pub fn syscall_args(&self) -> Syscall {
         Syscall {
@@ -250,7 +258,8 @@ unsafe extern "C" fn save_regs() {
 }
 
 #[no_mangle]
-pub(super) unsafe extern "C" fn switch_finishing() {
+pub(super) unsafe extern "C" fn switch_finishing(pree_value: usize, pree_flags: u64) {
+    let _pree = PREEMPT.from_raw(pree_value, pree_flags);
     if let Some(ref cur) = *crate::sched::SCHED.current() {
         log::trace!("Switched to task {:?}, P{}", cur.tid().raw(), PREEMPT.raw());
         debug_assert!(!cur.running_state.not_running());
@@ -264,11 +273,15 @@ pub(super) unsafe extern "C" fn switch_finishing() {
             KERNEL_GS.load();
         }
     }
-    PREEMPT.enable(None);
 }
 
 extern "C" {
-    pub(super) fn switch_kframe(old: *mut *mut u8, new: *mut u8);
+    pub(super) fn switch_kframe(
+        old: *mut *mut u8,
+        new: *mut u8,
+        pree_value: *mut usize,
+        pree_flags: *mut u64,
+    );
 
     fn task_fresh();
 }

+ 24 - 8
h2o/kernel/src/sched/task/elf.rs

@@ -4,6 +4,7 @@ use core::ops::Range;
 use bitop_ex::BitOpEx;
 use goblin::elf::*;
 use paging::{LAddr, PAddr};
+use sv_call::mem::PhysOptions;
 
 use super::*;
 use crate::{
@@ -29,7 +30,7 @@ fn map_addr(
         .ok_or(sv_call::ERANGE)?;
     let phys = match phys {
         Some(phys) => phys,
-        None => Phys::allocate(len, true)?,
+        None => Phys::allocate(len, PhysOptions::ZEROED, false)?,
     };
     virt.map(Some(offset), phys, 0, space::page_aligned(len), flags)?;
     Ok(())
@@ -64,24 +65,39 @@ fn load_prog(
         fsize,
         msize
     );
+    let fend = fsize.round_down_bit(paging::PAGE_SHIFT);
+    let cstart = fend;
+    let cend = fsize;
+    let mstart = fend;
+    let mend = msize;
 
     let flags = flags_to_pg_attr(flags);
-    let (vstart, vend) = (virt.val(), virt.val() + fsize);
+    let (vstart, vend) = (virt.val(), virt.val() + fend);
 
-    if fsize > 0 {
+    if fend > 0 {
         let virt = LAddr::from(vstart)..LAddr::from(vend);
         log::trace!("Mapping {:?}", virt);
-        let cnt = fsize.div_ceil_bit(paging::PAGE_SHIFT);
-        let phys = Phys::new(phys, paging::PAGE_SIZE * cnt)?;
+        let phys = Phys::new(phys, fend)?;
         map_addr(space, virt, Some(phys), flags)?;
     }
 
-    if msize > fsize {
-        let extra = msize - fsize;
+    if mend > mstart {
+        let extra = mend - mstart;
 
         let virt = LAddr::from(vend)..LAddr::from(vend + extra);
         log::trace!("Allocating {:?}", virt);
-        map_addr(space, virt, None, flags)?;
+        map_addr(space, virt.clone(), None, flags)?;
+
+        if cend > cstart {
+            unsafe {
+                let dst = virt.start;
+                let src = phys.to_laddr(minfo::ID_OFFSET).add(cstart);
+                let csize = cend - cstart;
+                log::trace!("Copying {:?}", dst..LAddr::from(dst.val() + csize));
+
+                dst.copy_from_nonoverlapping(src, csize);
+            }
+        }
     }
 
     Ok(())

+ 6 - 2
h2o/kernel/src/sched/task/excep.rs

@@ -43,8 +43,12 @@ pub fn dispatch_exception(frame: &mut Frame, vec: ExVec) -> bool {
         return false;
     }
 
-    let blocker =
-        crate::sched::Blocker::new(&(Arc::clone(excep_chan.event()) as _), false, SIG_READ);
+    let blocker = crate::sched::Blocker::new(
+        &(Arc::clone(excep_chan.event()) as _),
+        true,
+        false,
+        SIG_READ,
+    );
     if blocker.wait(None, Duration::MAX).is_err() {
         return false;
     }

+ 2 - 2
h2o/kernel/src/sched/task/hdl.rs

@@ -205,12 +205,12 @@ mod syscall {
 
     #[syscall]
     fn obj_feat(hdl_ptr: UserPtr<InOut, Handle>, feat: Feature) -> Result {
-        let old = unsafe { hdl_ptr.r#in().read() }?;
+        let old = unsafe { hdl_ptr.read() }?;
         old.check_null()?;
         let mut obj = SCHED.with_current(|cur| cur.space().handles().remove_ref(old))?;
         let ret = obj.set_features(feat);
         let new = SCHED.with_current(|cur| cur.space().handles().insert_ref(obj))?;
-        unsafe { hdl_ptr.out().write(new) }?;
+        unsafe { hdl_ptr.write(new) }?;
         ret
     }
 

+ 16 - 2
h2o/kernel/src/sched/task/hdl/node.rs

@@ -62,10 +62,10 @@ impl<T: ?Sized> Ref<T> {
         feat: Feature,
         event: Option<Weak<dyn Event>>,
     ) -> sv_call::Result<Self> {
-        let event = event.unwrap_or(Weak::<crate::sched::BasicEvent>::new() as _);
-        if event.strong_count() == 0 && feat.contains(Feature::WAIT) {
+        if event.is_none() && feat.contains(Feature::WAIT) {
             return Err(sv_call::EPERM);
         }
+        let event = event.unwrap_or(Weak::<crate::sched::BasicEvent>::new() as _);
         Ok(Ref {
             _marker: PhantomPinned,
             next: None,
@@ -123,6 +123,20 @@ impl<T: ?Sized> Ref<T> {
             Err(sv_call::EPERM)
         }
     }
+
+    pub fn try_unwrap(this: Self) -> core::result::Result<T, Self>
+    where
+        T: Sized,
+    {
+        Arc::try_unwrap(this.obj).map_err(|obj| Ref {
+            _marker: PhantomPinned,
+            next: this.next,
+            prev: this.prev,
+            event: this.event,
+            feat: this.feat,
+            obj,
+        })
+    }
 }
 
 impl<T: ?Sized + Send + Sync> Deref for Ref<T> {

+ 2 - 1
h2o/kernel/src/sched/task/idle.rs

@@ -20,7 +20,7 @@ pub(super) static IDLE: Lazy<Tid> = Lazy::new(|| {
     let cpu = unsafe { crate::cpu::id() };
 
     let ti = TaskInfo::builder()
-        .from(None)
+        .from(Default::default())
         .excep_chan(Arsc::try_new(Default::default()).expect("Failed to create task info"))
         .name(format!("IDLE{}", cpu))
         .ty(Type::Kernel)
@@ -40,6 +40,7 @@ pub(super) static IDLE: Lazy<Tid> = Lazy::new(|| {
     let kstack = ctx::Kstack::new(Some(entry), Type::Kernel);
 
     let tid = tid::allocate(ti).expect("Tid exhausted");
+    space.set_main(&tid);
 
     let init = Init::new(tid.clone(), space, kstack, ctx::ExtFrame::zeroed());
     crate::sched::SCHED.unblock(init, true);

+ 8 - 3
h2o/kernel/src/sched/task/sm.rs

@@ -9,7 +9,12 @@ use bitvec::prelude::BitVec;
 use derive_builder::Builder;
 use spin::Mutex;
 
-use super::{ctx, idle, sig::Signal, tid, Space, Tid, Type};
+use super::{
+    ctx, idle,
+    sig::Signal,
+    tid::{self, WeakTid},
+    Space, Tid, Type,
+};
 use crate::{
     cpu::{time::Instant, CpuMask},
     sched::{ipc::Channel, Arsc, BasicEvent, Event, PREEMPT, SIG_READ},
@@ -18,7 +23,7 @@ use crate::{
 #[derive(Debug, Builder)]
 #[builder(no_std, pattern = "owned")]
 pub struct TaskInfo {
-    from: Option<Tid>,
+    from: WeakTid,
     #[builder(setter(skip))]
     ret_cell: Mutex<Option<usize>>,
     #[builder(setter(skip))]
@@ -41,7 +46,7 @@ impl TaskInfo {
     }
 
     #[inline]
-    pub fn from(&self) -> Option<Tid> {
+    pub fn from(&self) -> WeakTid {
         self.from.clone()
     }
 

+ 19 - 0
h2o/kernel/src/sched/task/space.rs

@@ -1,4 +1,5 @@
 use alloc::sync::Arc;
+use core::sync::atomic::{AtomicU32, Ordering::*};
 
 use sv_call::Feature;
 
@@ -16,6 +17,7 @@ pub struct Space {
     mem: Arc<mem::space::Space>,
     handles: HandleMap,
     futexes: Futexes,
+    main: AtomicU32,
 }
 
 unsafe impl Send for Space {}
@@ -28,6 +30,7 @@ impl Space {
             mem,
             handles: HandleMap::new(),
             futexes: Default::default(),
+            main: AtomicU32::new(0),
         })?)
     }
 
@@ -36,6 +39,7 @@ impl Space {
             mem: mem::space::with_current(Arc::clone),
             handles: HandleMap::new(),
             futexes: Default::default(),
+            main: AtomicU32::new(0),
         })
     }
 
@@ -44,6 +48,21 @@ impl Space {
         &self.mem
     }
 
+    #[inline]
+    pub fn set_main(&self, tid: &Tid) {
+        let _ = self.main.compare_exchange(0, tid.raw(), AcqRel, Acquire);
+    }
+
+    #[inline]
+    pub fn try_stop(&self, tid: &Tid) {
+        let _ = self.main.compare_exchange(tid.raw(), 0, AcqRel, Acquire);
+    }
+
+    #[inline]
+    pub fn has_to_stop(&self) -> bool {
+        self.main.load(Acquire) == 0
+    }
+
     #[inline]
     pub fn handles(&self) -> &HandleMap {
         &self.handles

+ 31 - 21
h2o/kernel/src/sched/task/syscall.rs

@@ -48,8 +48,8 @@ unsafe impl DefaultFeature for SuspendToken {
 }
 
 #[syscall]
-fn task_exit(retval: usize) -> Result {
-    SCHED.exit_current(retval);
+fn task_exit(retval: usize, kill_all: bool) -> Result {
+    SCHED.exit_current(retval, kill_all);
     #[allow(unreachable_code)]
     Err(EKILLED)
 }
@@ -71,7 +71,7 @@ fn task_sleep(ms: u32) -> Result {
     }
 }
 
-fn get_name(ptr: UserPtr<In, u8>, len: usize) -> Result<Option<String>> {
+fn get_name(ptr: UserPtr<In>, len: usize) -> Result<Option<String>> {
     if !ptr.as_ptr().is_null() {
         let mut buf = Vec::<u8>::with_capacity(len);
         unsafe {
@@ -127,26 +127,36 @@ fn task_exec(ci: UserPtr<In, task::ExecInfo>) -> Result<Handle> {
 
 #[syscall]
 fn task_new(
-    name: UserPtr<In, u8>,
+    name: UserPtr<In>,
     name_len: usize,
     space: Handle,
+    init_chan: Handle,
     st: UserPtr<Out, Handle>,
 ) -> Result<Handle> {
     let name = get_name(name, name_len)?;
 
-    let new_space = if space == Handle::NULL {
-        SCHED.with_current(|cur| Ok(Arc::clone(cur.space())))?
-    } else {
-        SCHED.with_current(|cur| {
-            cur.space()
-                .handles()
-                .remove::<Space>(space)
-                .map(Ref::into_raw)
-        })?
+    let (init_chan, space) = SCHED.with_current(|cur| {
+        let handles = cur.space().handles();
+        let init_chan = if init_chan == Handle::NULL {
+            None
+        } else {
+            Some(handles.remove::<crate::sched::ipc::Channel>(init_chan)?)
+        };
+        if space == Handle::NULL {
+            Ok((init_chan, Arc::clone(cur.space())))
+        } else {
+            let space = handles.remove::<Space>(space)?;
+            Ok((init_chan, Ref::into_raw(space)))
+        }
+    })?;
+    let init_chan = match init_chan {
+        Some(obj) => PREEMPT.scope(|| space.handles().insert_ref(obj))?,
+        None => Handle::NULL,
     };
+
     let mut sus_slot = Arsc::try_new_uninit()?;
 
-    let (task, hdl) = super::create(name, Arc::clone(&new_space))?;
+    let (task, hdl) = super::create(name, space, init_chan)?;
 
     let task = super::Ready::block(
         super::IntoReady::into_ready(task, unsafe { crate::cpu::id() }, MIN_TIME_GRAN),
@@ -197,7 +207,7 @@ fn task_ctl(hdl: Handle, op: u32, data: UserPtr<InOut, Handle>) -> Result {
             Ok(())
         }
         task::TASK_CTL_SUSPEND => {
-            data.out().check()?;
+            data.check()?;
 
             let child = cur.child(hdl, Feature::EXECUTE)?;
 
@@ -216,7 +226,7 @@ fn task_ctl(hdl: Handle, op: u32, data: UserPtr<InOut, Handle>) -> Result {
             })?;
 
             let out = super::PREEMPT.scope(|| cur.handles().insert(st, None))?;
-            unsafe { data.out().write(out)? };
+            unsafe { data.write(out)? };
 
             Ok(())
         }
@@ -228,7 +238,7 @@ fn read_regs(
     task: &Blocked,
     feat: Feature,
     addr: usize,
-    data: UserPtr<Out, u8>,
+    data: UserPtr<Out>,
     len: usize,
 ) -> Result<()> {
     if !feat.contains(Feature::READ) {
@@ -258,7 +268,7 @@ fn write_regs(
     task: &mut Blocked,
     feat: Feature,
     addr: usize,
-    data: UserPtr<In, u8>,
+    data: UserPtr<In>,
     len: usize,
 ) -> Result<()> {
     if !feat.contains(Feature::WRITE) {
@@ -330,7 +340,7 @@ fn task_debug(hdl: Handle, op: u32, addr: usize, data: UserPtr<InOut, u8>, len:
                     return Err(EPERM);
                 }
                 let slice = slice::from_raw_parts(addr as *mut u8, len);
-                data.out().write_slice(slice)
+                data.write_slice(slice)
             })
         },
         task::TASK_DBG_WRITE_MEM => unsafe {
@@ -338,7 +348,7 @@ fn task_debug(hdl: Handle, op: u32, addr: usize, data: UserPtr<InOut, u8>, len:
                 if !feat.contains(Feature::WRITE) {
                     return Err(EPERM);
                 }
-                data.r#in().read_slice(addr as *mut u8, len)
+                data.read_slice(addr as *mut u8, len)
             })
         },
         task::TASK_DBG_EXCEP_HDL => {
@@ -352,7 +362,7 @@ fn task_debug(hdl: Handle, op: u32, addr: usize, data: UserPtr<InOut, u8>, len:
                     })
                 })?;
 
-                unsafe { data.out().cast::<Handle>().write(hdl) }
+                unsafe { data.cast::<Handle>().write(hdl) }
             }
         }
         _ => Err(EINVAL),

+ 47 - 6
h2o/kernel/src/sched/task/tid.rs

@@ -1,3 +1,4 @@
+use alloc::sync::{Arc, Weak};
 use core::{hash::BuildHasherDefault, num::NonZeroU32, ops::Deref};
 
 use archop::Azy;
@@ -5,20 +6,25 @@ use collection_ex::{CHashMap, FnvHasher, IdAllocator};
 use sv_call::Feature;
 
 use super::{hdl::DefaultFeature, TaskInfo};
-use crate::sched::{Arsc, PREEMPT};
+use crate::sched::PREEMPT;
 
 pub const NR_TASKS: usize = 65536;
 
 type BH = BuildHasherDefault<FnvHasher>;
-static TI_MAP: Azy<CHashMap<u32, Arsc<TaskInfo>, BH>> = Azy::new(Default::default);
+static TI_MAP: Azy<CHashMap<u32, Arc<TaskInfo>, BH>> = Azy::new(Default::default);
 static TID_ALLOC: Azy<spin::Mutex<IdAllocator>> =
     Azy::new(|| spin::Mutex::new(IdAllocator::new(0..=(NR_TASKS as u64 - 1))));
 
 #[derive(Debug, Clone)]
-#[repr(C)]
 pub struct Tid {
     raw: NonZeroU32,
-    ti: Arsc<TaskInfo>,
+    ti: Arc<TaskInfo>,
+}
+
+#[derive(Debug, Clone)]
+pub struct WeakTid {
+    raw: Option<NonZeroU32>,
+    ti: Weak<TaskInfo>,
 }
 
 impl Deref for Tid {
@@ -35,12 +41,47 @@ impl Tid {
     pub fn raw(&self) -> u32 {
         self.raw.get()
     }
+
+    #[inline]
+    pub fn downgrade(&self) -> WeakTid {
+        WeakTid {
+            raw: Some(self.raw),
+            ti: Arc::downgrade(&self.ti),
+        }
+    }
+}
+
+impl WeakTid {
+    #[inline]
+    pub fn new() -> Self {
+        WeakTid {
+            raw: None,
+            ti: Weak::new(),
+        }
+    }
+
+    pub fn raw(&self) -> Option<u32> {
+        self.raw.map(|raw| raw.get())
+    }
+
+    pub fn upgrade(&self) -> Option<Tid> {
+        let raw = self.raw?;
+        let ti = self.ti.upgrade()?;
+        Some(Tid { raw, ti })
+    }
+}
+
+impl Default for WeakTid {
+    #[inline]
+    fn default() -> Self {
+        Self::new()
+    }
 }
 
 impl PartialEq for Tid {
     #[inline]
     fn eq(&self, other: &Self) -> bool {
-        self.raw == other.raw && Arsc::ptr_eq(&self.ti, &other.ti)
+        self.raw == other.raw && Arc::ptr_eq(&self.ti, &other.ti)
     }
 }
 
@@ -64,7 +105,7 @@ pub fn allocate(ti: TaskInfo) -> sv_call::Result<Tid> {
     let _flags = PREEMPT.lock();
     match next() {
         Some(raw) => {
-            let ti = Arsc::try_new(ti)?;
+            let ti = Arc::try_new(ti)?;
             let old = TI_MAP.insert(raw.get(), ti.clone());
             debug_assert!(old.is_none());
             Ok(Tid { raw, ti })

+ 1 - 3
h2o/kernel/src/sched/wait.rs

@@ -47,9 +47,7 @@ impl WaitObject {
         let mut cnt = 0;
         while cnt < num {
             match self.wait_queue.pop() {
-                Some(timer) if timer.cancel(preempt) => {
-                    cnt += 1;
-                }
+                Some(timer) if timer.cancel(preempt) => cnt += 1,
                 Some(_) => {}
                 None => break,
             }

+ 3 - 3
h2o/kernel/src/sched/wait/futex.rs

@@ -113,7 +113,7 @@ mod syscall {
     ) -> Result {
         let _ = unsafe { ptr.read() }?;
         let _ = unsafe { other.read() }?;
-        let (wake, requeue) = unsafe { (wake_num.r#in().read()?, requeue_num.r#in().read()?) };
+        let (wake, requeue) = unsafe { (wake_num.read()?, requeue_num.read()?) };
 
         let pree = PREEMPT.lock();
         let futex = unsafe { (*SCHED.current()).as_ref().unwrap().space.futex(ptr) };
@@ -124,8 +124,8 @@ mod syscall {
         drop(pree);
 
         unsafe {
-            wake_num.out().write(wake)?;
-            requeue_num.out().write(requeue)?;
+            wake_num.write(wake)?;
+            requeue_num.write(requeue)?;
         }
 
         Ok(())

+ 28 - 22
h2o/kernel/src/syscall/user_ptr.rs

@@ -6,26 +6,26 @@ pub use self::types::*;
 use crate::{mem::space::PageFaultErrCode, sched::SCHED};
 
 #[derive(Copy, Clone)]
-pub struct UserPtr<T: Type, D> {
+pub struct UserPtr<T: PtrType, D = u8> {
     data: *mut D,
     _marker: PhantomData<T>,
 }
 
-impl<T: Type, D> PartialEq for UserPtr<T, D> {
+impl<T: PtrType, D> PartialEq for UserPtr<T, D> {
     #[inline]
     fn eq(&self, other: &Self) -> bool {
         self.data == other.data
     }
 }
 
-impl<T: Type, D> Hash for UserPtr<T, D> {
+impl<T: PtrType, D> Hash for UserPtr<T, D> {
     #[inline]
     fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
         self.data.hash(state);
     }
 }
 
-impl<T: Type, D> UserPtr<T, D> {
+impl<T: PtrType, D> UserPtr<T, D> {
     pub fn new(data: *mut D) -> Self {
         UserPtr {
             data,
@@ -66,7 +66,7 @@ impl<T: Type, D> UserPtr<T, D> {
     }
 }
 
-impl<D> UserPtr<In, D> {
+impl<T: InPtrType, D> UserPtr<T, D> {
     /// # Errors
     ///
     /// Returns error if the pointer is invalid for reads or if the pointer is
@@ -115,9 +115,17 @@ impl<D> UserPtr<In, D> {
         )
         .into_result()
     }
+
+    #[inline]
+    pub fn r#in(&self) -> UserPtr<In, D> {
+        UserPtr {
+            data: self.data,
+            _marker: PhantomData,
+        }
+    }
 }
 
-impl<D> UserPtr<Out, D> {
+impl<T: OutPtrType, D> UserPtr<T, D> {
     /// # Errors
     ///
     /// Returns error if the pointer is invalid for writes or if the pointer is
@@ -157,16 +165,6 @@ impl<D> UserPtr<Out, D> {
             .into_result()
         }
     }
-}
-
-impl<D> UserPtr<InOut, D> {
-    #[inline]
-    pub fn r#in(&self) -> UserPtr<In, D> {
-        UserPtr {
-            data: self.data,
-            _marker: PhantomData,
-        }
-    }
 
     #[inline]
     pub fn out(&self) -> UserPtr<Out, D> {
@@ -177,13 +175,13 @@ impl<D> UserPtr<InOut, D> {
     }
 }
 
-impl<T: Type, D> fmt::Debug for UserPtr<T, D> {
+impl<T: PtrType, D> fmt::Debug for UserPtr<T, D> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.debug_tuple("UserPtr").field(&self.data).finish()
     }
 }
 
-impl<T: Type, D> SerdeReg for UserPtr<T, D> {
+impl<T: PtrType, D> SerdeReg for UserPtr<T, D> {
     #[inline]
     fn encode(self) -> usize {
         self.data as usize
@@ -220,10 +218,18 @@ mod types {
     #[derive(Copy, Clone)]
     pub enum InOut {}
 
-    pub trait Type {}
-    impl Type for In {}
-    impl Type for Out {}
-    impl Type for InOut {}
+    pub trait PtrType {}
+    impl PtrType for In {}
+    impl PtrType for Out {}
+    impl PtrType for InOut {}
+
+    pub trait InPtrType: PtrType {}
+    impl InPtrType for In {}
+    impl InPtrType for InOut {}
+
+    pub trait OutPtrType: PtrType {}
+    impl OutPtrType for Out {}
+    impl OutPtrType for InOut {}
 }
 
 #[repr(C)]

+ 49 - 102
h2o/kernel/syscall/channel.json

@@ -1,102 +1,49 @@
-[
-    {
-        "name": "sv_chan_new",
-        "returns": "()",
-        "args": [
-            {
-                "name": "p1",
-                "ty": "*mut Handle"
-            },
-            {
-                "name": "p2",
-                "ty": "*mut Handle"
-            }
-        ]
-    },
-    {
-        "name": "sv_chan_send",
-        "returns": "()",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "packet",
-                "ty": "*const RawPacket"
-            }
-        ]
-    },
-    {
-        "name": "sv_chan_recv",
-        "returns": "()",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "packet",
-                "ty": "*mut RawPacket"
-            }
-        ]
-    },
-    {
-        "name": "sv_chan_csend",
-        "returns": "usize",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "packet",
-                "ty": "*const RawPacket"
-            }
-        ]
-    },
-    {
-        "name": "sv_chan_crecv",
-        "returns": "()",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "id",
-                "ty": "usize"
-            },
-            {
-                "name": "packet",
-                "ty": "*mut RawPacket"
-            },
-            {
-                "name": "timeout_us",
-                "ty": "u64"
-            }
-        ]
-    },
-    {
-        "name": "sv_chan_acrecv",
-        "returns": "usize",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "id",
-                "ty": "usize"
-            },
-            {
-                "name": "disp",
-                "ty": "Handle"
-            },
-            {
-                "name": "syscall",
-                "ty": "*const Syscall"
-            }
-        ]
-    }
-]
+{
+    "types": [
+        "Channel"
+    ],
+    "funcs": [
+        {
+            "name": "sv_chan_new",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "p1",
+                    "ty": "*mut Handle"
+                },
+                {
+                    "name": "p2",
+                    "ty": "*mut Handle"
+                }
+            ]
+        },
+        {
+            "name": "sv_chan_send",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "packet",
+                    "ty": "*const RawPacket"
+                }
+            ]
+        },
+        {
+            "name": "sv_chan_recv",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "packet",
+                    "ty": "*mut RawPacket"
+                }
+            ]
+        }
+    ]
+}

+ 61 - 56
h2o/kernel/syscall/dispatcher.json

@@ -1,56 +1,61 @@
-[
-    {
-        "name": "sv_disp_new",
-        "returns": "Handle",
-        "args": [
-            {
-                "name": "capacity",
-                "ty": "usize"
-            }
-        ]
-    },
-    {
-        "name": "sv_disp_push",
-        "returns": "usize",
-        "args": [
-            {
-                "name": "disp",
-                "ty": "Handle"
-            },
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "level_triggered",
-                "ty": "bool"
-            },
-            {
-                "name": "signal",
-                "ty": "usize"
-            },
-            {
-                "name": "syscall",
-                "ty": "*const Syscall"
-            }
-        ]
-    },
-    {
-        "name": "sv_disp_pop",
-        "returns": "usize",
-        "args": [
-            {
-                "name": "disp",
-                "ty": "Handle"
-            },
-            {
-                "name": "canceled",
-                "ty": "*mut bool"
-            },
-            {
-                "name": "result",
-                "ty": "*mut usize"
-            }
-        ]
-    }
-]
+{
+    "types": [
+        "Dispatcher"
+    ],
+    "funcs": [
+        {
+            "name": "sv_disp_new",
+            "returns": "Handle",
+            "args": [
+                {
+                    "name": "capacity",
+                    "ty": "usize"
+                }
+            ]
+        },
+        {
+            "name": "sv_disp_push",
+            "returns": "usize",
+            "args": [
+                {
+                    "name": "disp",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "level_triggered",
+                    "ty": "bool"
+                },
+                {
+                    "name": "signal",
+                    "ty": "usize"
+                },
+                {
+                    "name": "syscall",
+                    "ty": "*const Syscall"
+                }
+            ]
+        },
+        {
+            "name": "sv_disp_pop",
+            "returns": "usize",
+            "args": [
+                {
+                    "name": "disp",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "signal",
+                    "ty": "*mut usize"
+                },
+                {
+                    "name": "result",
+                    "ty": "*mut usize"
+                }
+            ]
+        }
+    ]
+}

+ 45 - 0
h2o/kernel/syscall/event.json

@@ -0,0 +1,45 @@
+{
+    "types": [
+        "event"
+    ],
+    "funcs": [
+        {
+            "name": "sv_event_new",
+            "returns": "Handle",
+            "args": [
+                {
+                    "name": "init_signal",
+                    "ty": "usize"
+                }
+            ]
+        },
+        {
+            "name": "sv_event_notify",
+            "returns": "usize",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "clear",
+                    "ty": "usize"
+                },
+                {
+                    "name": "set",
+                    "ty": "usize"
+                }
+            ]
+        },
+        {
+            "name": "sv_event_cancel",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                }
+            ]
+        }
+    ]
+}

+ 59 - 56
h2o/kernel/syscall/futex.json

@@ -1,56 +1,59 @@
-[
-    {
-        "name": "sv_futex_wait",
-        "returns": "()",
-        "args": [
-            {
-                "name": "ptr",
-                "ty": "*const u64"
-            },
-            {
-                "name": "expected",
-                "ty": "u64"
-            },
-            {
-                "name": "timeout_us",
-                "ty": "u64"
-            }
-        ]
-    },
-    {
-        "name": "sv_futex_wake",
-        "returns": "usize",
-        "args": [
-            {
-                "name": "ptr",
-                "ty": "*const u64"
-            },
-            {
-                "name": "num",
-                "ty": "usize"
-            }
-        ]
-    },
-    {
-        "name": "sv_futex_reque",
-        "returns": "()",
-        "args": [
-            {
-                "name": "ptr",
-                "ty": "*const u64"
-            },
-            {
-                "name": "wake_num",
-                "ty": "*mut usize"
-            },
-            {
-                "name": "other",
-                "ty": "*const u64"
-            },
-            {
-                "name": "reque_num",
-                "ty":"*mut usize"
-            }
-        ]
-    }
-]
+{
+    "types": [],
+    "funcs": [
+        {
+            "name": "sv_futex_wait",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "ptr",
+                    "ty": "*const u64"
+                },
+                {
+                    "name": "expected",
+                    "ty": "u64"
+                },
+                {
+                    "name": "timeout_us",
+                    "ty": "u64"
+                }
+            ]
+        },
+        {
+            "name": "sv_futex_wake",
+            "returns": "usize",
+            "args": [
+                {
+                    "name": "ptr",
+                    "ty": "*const u64"
+                },
+                {
+                    "name": "num",
+                    "ty": "usize"
+                }
+            ]
+        },
+        {
+            "name": "sv_futex_reque",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "ptr",
+                    "ty": "*const u64"
+                },
+                {
+                    "name": "wake_num",
+                    "ty": "*mut usize"
+                },
+                {
+                    "name": "other",
+                    "ty": "*const u64"
+                },
+                {
+                    "name": "reque_num",
+                    "ty": "*mut usize"
+                }
+            ]
+        }
+    ]
+}

+ 25 - 22
h2o/kernel/syscall/integer.json

@@ -1,22 +1,25 @@
-[
-    {
-        "name": "sv_int_new",
-        "returns": "Handle",
-        "args": [
-            {
-                "name": "value",
-                "ty": "u64"
-            }
-        ]
-    },
-    {
-        "name": "sv_int_get",
-        "returns": "u64",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            }
-        ]
-    }
-]
+{
+    "types": [],
+    "funcs": [
+        {
+            "name": "sv_int_new",
+            "returns": "Handle",
+            "args": [
+                {
+                    "name": "value",
+                    "ty": "u64"
+                }
+            ]
+        },
+        {
+            "name": "sv_int_get",
+            "returns": "u64",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                }
+            ]
+        }
+    ]
+}

+ 53 - 48
h2o/kernel/syscall/interrupt.json

@@ -1,48 +1,53 @@
-[
-    {
-        "name": "sv_intr_new",
-        "returns": "Handle",
-        "args": [
-            {
-                "name": "res",
-                "ty": "Handle"
-            },
-            {
-                "name": "gsi",
-                "ty": "u32"
-            },
-            {
-                "name": "config",
-                "ty": "IntrConfig"
-            }
-        ]
-    },
-    {
-        "name": "sv_intr_wait",
-        "returns": "()",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "timeout_us",
-                "ty": "u64"
-            },
-            {
-                "name": "last_time",
-                "ty": "*mut ()"
-            }
-        ]
-    },
-    {
-        "name": "sv_intr_drop",
-        "returns": "()",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            }
-        ]
-    }
-]
+{
+    "types": [
+        "Interrupt"
+    ],
+    "funcs": [
+        {
+            "name": "sv_intr_new",
+            "returns": "Handle",
+            "args": [
+                {
+                    "name": "res",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "gsi",
+                    "ty": "u32"
+                },
+                {
+                    "name": "config",
+                    "ty": "IntrConfig"
+                }
+            ]
+        },
+        {
+            "name": "sv_intr_wait",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "timeout_us",
+                    "ty": "u64"
+                },
+                {
+                    "name": "last_time",
+                    "ty": "*mut ()"
+                }
+            ]
+        },
+        {
+            "name": "sv_intr_drop",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                }
+            ]
+        }
+    ]
+}

+ 19 - 16
h2o/kernel/syscall/log.json

@@ -1,16 +1,19 @@
-[
-    {
-        "name": "sv_log",
-        "returns": "()",
-        "args": [
-            {
-                "name": "buffer",
-                "ty": "*const u8"
-            },
-            {
-                "name": "len",
-                "ty": "usize"
-            }
-        ]
-    }
-]
+{
+    "types": [],
+    "funcs": [
+        {
+            "name": "sv_log",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "buffer",
+                    "ty": "*const u8"
+                },
+                {
+                    "name": "len",
+                    "ty": "usize"
+                }
+            ]
+        }
+    ]
+}

+ 274 - 206
h2o/kernel/syscall/memory.json

@@ -1,206 +1,274 @@
-[
-    {
-        "name": "sv_phys_alloc",
-        "returns": "Handle",
-        "args": [
-            {
-                "name": "size",
-                "ty": "usize"
-            },
-            {
-                "name": "zeroed",
-                "ty": "bool"
-            }
-        ]
-    },
-    {
-        "name": "sv_phys_size",
-        "returns": "usize",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            }
-        ]
-    },
-    {
-        "name": "sv_phys_read",
-        "returns": "()",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "offset",
-                "ty": "usize"
-            },
-            {
-                "name": "len",
-                "ty": "usize"
-            },
-            {
-                "name": "buffer",
-                "ty": "*mut u8"
-            }
-        ]
-    },
-    {
-        "name": "sv_phys_write",
-        "returns": "()",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "offset",
-                "ty": "usize"
-            },
-            {
-                "name": "len",
-                "ty": "usize"
-            },
-            {
-                "name": "buffer",
-                "ty": "*const u8"
-            }
-        ]
-    },
-    {
-        "name": "sv_phys_sub",
-        "returns": "Handle",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "offset",
-                "ty": "usize"
-            },
-            {
-                "name": "len",
-                "ty": "usize"
-            },
-            {
-                "name": "copy",
-                "ty": "bool"
-            }
-        ]
-    },
-    {
-        "name": "sv_virt_alloc",
-        "returns": "Handle",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "offset",
-                "ty": "usize"
-            },
-            {
-                "name": "size",
-                "ty": "usize"
-            },
-            {
-                "name": "align",
-                "ty": "usize"
-            }
-        ]
-    },
-    {
-        "name": "sv_virt_info",
-        "returns": "*mut u8",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "size",
-                "ty": "*mut usize"
-            }
-        ]
-    },
-    {
-        "name": "sv_virt_drop",
-        "returns": "()",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            }
-        ]
-    },
-    {
-        "name": "sv_virt_map",
-        "returns": "*mut u8",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "mi",
-                "ty": "*const VirtMapInfo"
-            }
-        ]
-    },
-    {
-        "name": "sv_virt_reprot",
-        "returns": "()",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "base",
-                "ty": "*mut u8"
-            },
-            {
-                "name": "len",
-                "ty": "usize"
-            },
-            {
-                "name": "flags",
-                "ty": "Flags"
-            }
-        ]
-    },
-    {
-        "name": "sv_virt_unmap",
-        "returns": "()",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "base",
-                "ty": "*mut u8"
-            },
-            {
-                "name": "len",
-                "ty": "usize"
-            },
-            {
-                "name": "drop_child",
-                "ty": "bool"
-            }
-        ]
-    },
-    {
-        "name": "sv_mem_info",
-        "returns": "()",
-        "args": [
-            {
-                "name": "info",
-                "ty": "*mut MemInfo"
-            }
-        ]
-    }
-]
+{
+    "types": [
+        "Phys",
+        "Virt"
+    ],
+    "funcs": [
+        {
+            "name": "sv_phys_alloc",
+            "returns": "Handle",
+            "args": [
+                {
+                    "name": "size",
+                    "ty": "usize"
+                },
+                {
+                    "name": "options",
+                    "ty": "PhysOptions"
+                }
+            ]
+        },
+        {
+            "name": "sv_phys_size",
+            "returns": "usize",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                }
+            ]
+        },
+        {
+            "name": "sv_phys_read",
+            "returns": "usize",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "offset",
+                    "ty": "usize"
+                },
+                {
+                    "name": "len",
+                    "ty": "usize"
+                },
+                {
+                    "name": "buffer",
+                    "ty": "*mut u8"
+                }
+            ]
+        },
+        {
+            "name": "sv_phys_write",
+            "returns": "usize",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "offset",
+                    "ty": "usize"
+                },
+                {
+                    "name": "len",
+                    "ty": "usize"
+                },
+                {
+                    "name": "buffer",
+                    "ty": "*const u8"
+                }
+            ]
+        },
+        {
+            "name": "sv_phys_readv",
+            "returns": "usize",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "offset",
+                    "ty": "usize"
+                },
+                {
+                    "name": "bufs",
+                    "ty": "*const IoVec"
+                },
+                {
+                    "name": "count",
+                    "ty": "usize"
+                }
+            ]
+        },
+        {
+            "name": "sv_phys_writev",
+            "returns": "usize",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "offset",
+                    "ty": "usize"
+                },
+                {
+                    "name": "bufs",
+                    "ty": "*const IoVec"
+                },
+                {
+                    "name": "count",
+                    "ty": "usize"
+                }
+            ]
+        },
+        {
+            "name": "sv_phys_sub",
+            "returns": "Handle",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "offset",
+                    "ty": "usize"
+                },
+                {
+                    "name": "len",
+                    "ty": "usize"
+                },
+                {
+                    "name": "copy",
+                    "ty": "bool"
+                }
+            ]
+        },
+        {
+            "name": "sv_phys_resize",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "new_len",
+                    "ty": "usize"
+                },
+                {
+                    "name": "zeroed",
+                    "ty": "bool"
+                }
+            ]
+        },
+        {
+            "name": "sv_virt_alloc",
+            "returns": "Handle",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "offset",
+                    "ty": "usize"
+                },
+                {
+                    "name": "size",
+                    "ty": "usize"
+                },
+                {
+                    "name": "align",
+                    "ty": "usize"
+                }
+            ]
+        },
+        {
+            "name": "sv_virt_info",
+            "returns": "*mut u8",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "size",
+                    "ty": "*mut usize"
+                }
+            ]
+        },
+        {
+            "name": "sv_virt_drop",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                }
+            ]
+        },
+        {
+            "name": "sv_virt_map",
+            "returns": "*mut u8",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "mi",
+                    "ty": "*mut VirtMapInfo"
+                }
+            ]
+        },
+        {
+            "name": "sv_virt_reprot",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "base",
+                    "ty": "*mut u8"
+                },
+                {
+                    "name": "len",
+                    "ty": "usize"
+                },
+                {
+                    "name": "flags",
+                    "ty": "Flags"
+                }
+            ]
+        },
+        {
+            "name": "sv_virt_unmap",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "base",
+                    "ty": "*mut u8"
+                },
+                {
+                    "name": "len",
+                    "ty": "usize"
+                },
+                {
+                    "name": "drop_child",
+                    "ty": "bool"
+                }
+            ]
+        },
+        {
+            "name": "sv_mem_info",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "info",
+                    "ty": "*mut MemInfo"
+                }
+            ]
+        }
+    ]
+}

+ 65 - 58
h2o/kernel/syscall/object.json

@@ -1,58 +1,65 @@
-[
-    {
-        "name": "sv_obj_clone",
-        "returns": "Handle",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            }
-        ]
-    },
-    {
-        "name": "sv_obj_feat",
-        "returns": "()",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "*mut Handle"
-            },
-            {
-                "name": "feat",
-                "ty": "Feature"
-            }
-        ]
-    },
-    {
-        "name": "sv_obj_drop",
-        "returns": "()",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            }
-        ]
-    },
-    {
-        "name": "sv_obj_wait",
-        "returns": "usize",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "timeout_us",
-                "ty": "u64"
-            },
-            {
-                "name": "wake_all",
-                "ty": "bool"
-            },
-            {
-                "name": "signal",
-                "ty": "usize"
-            }
-        ]
-    }
-]
+{
+    "types": [],
+    "funcs": [
+        {
+            "name": "sv_obj_clone",
+            "returns": "Handle",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                }
+            ]
+        },
+        {
+            "name": "sv_obj_feat",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "*mut Handle"
+                },
+                {
+                    "name": "feat",
+                    "ty": "Feature"
+                }
+            ]
+        },
+        {
+            "name": "sv_obj_drop",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                }
+            ]
+        },
+        {
+            "name": "sv_obj_wait",
+            "returns": "usize",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "timeout_us",
+                    "ty": "u64"
+                },
+                {
+                    "name": "level_triggered",
+                    "ty": "bool"
+                },
+                {
+                    "name": "wake_all",
+                    "ty": "bool"
+                },
+                {
+                    "name": "signal",
+                    "ty": "usize"
+                }
+            ]
+        }
+    ]
+}

+ 85 - 78
h2o/kernel/syscall/resource.json

@@ -1,78 +1,85 @@
-[
-    {
-        "name": "sv_res_alloc",
-        "returns": "Handle",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "ty",
-                "ty": "u32"
-            },
-            {
-                "name": "base",
-                "ty": "usize"
-            },
-            {
-                "name": "size",
-                "ty": "usize"
-            }
-        ]
-    },
-    {
-        "name": "sv_pio_acq",
-        "returns": "()",
-        "args": [
-            {
-                "name": "res",
-                "ty": "Handle"
-            },
-            {
-                "name": "base",
-                "ty": "u16"
-            },
-            {
-                "name": "size",
-                "ty": "u16"
-            }
-        ]
-    },
-    {
-        "name": "sv_pio_rel",
-        "returns": "()",
-        "args": [
-            {
-                "name": "res",
-                "ty": "Handle"
-            },
-            {
-                "name": "base",
-                "ty": "u16"
-            },
-            {
-                "name": "size",
-                "ty": "u16"
-            }
-        ]
-    },
-    {
-        "name": "sv_phys_acq",
-        "returns": "Handle",
-        "args": [
-            {
-                "name": "res",
-                "ty": "Handle"
-            },
-            {
-                "name": "addr",
-                "ty": "usize"
-            },
-            {
-                "name": "size",
-                "ty": "usize"
-            }
-        ]
-    }
-]
+{
+    "types": [
+        "MemRes",
+        "PioRes",
+        "GsiRes"
+    ],
+    "funcs": [
+        {
+            "name": "sv_res_alloc",
+            "returns": "Handle",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "ty",
+                    "ty": "u32"
+                },
+                {
+                    "name": "base",
+                    "ty": "usize"
+                },
+                {
+                    "name": "size",
+                    "ty": "usize"
+                }
+            ]
+        },
+        {
+            "name": "sv_pio_acq",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "res",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "base",
+                    "ty": "u16"
+                },
+                {
+                    "name": "size",
+                    "ty": "u16"
+                }
+            ]
+        },
+        {
+            "name": "sv_pio_rel",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "res",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "base",
+                    "ty": "u16"
+                },
+                {
+                    "name": "size",
+                    "ty": "u16"
+                }
+            ]
+        },
+        {
+            "name": "sv_phys_acq",
+            "returns": "Handle",
+            "args": [
+                {
+                    "name": "res",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "addr",
+                    "ty": "usize"
+                },
+                {
+                    "name": "size",
+                    "ty": "usize"
+                }
+            ]
+        }
+    ]
+}

+ 144 - 129
h2o/kernel/syscall/task.json

@@ -1,129 +1,144 @@
-[
-    {
-        "name": "sv_task_exit",
-        "returns": "()",
-        "args": [
-            {
-                "name": "retval",
-                "ty": "usize"
-            }
-        ]
-    },
-    {
-        "name": "sv_task_sleep",
-        "returns": "()",
-        "args": [
-            {
-                "name": "ms",
-                "ty": "u32"
-            }
-        ]
-    },
-    {
-        "name": "sv_space_new",
-        "returns": "Handle",
-        "args": [
-            {
-                "name": "root_virt",
-                "ty": "*mut Handle"
-            }
-        ]
-    },
-    {
-        "name": "sv_task_exec",
-        "returns": "Handle",
-        "args": [
-            {
-                "name": "ci",
-                "ty": "*const ExecInfo"
-            }
-        ]
-    },
-    {
-        "name": "sv_task_new",
-        "returns": "Handle",
-        "args": [
-            {
-                "name": "name",
-                "ty": "*const u8"
-            },
-            {
-                "name": "name_len",
-                "ty": "usize"
-            },
-            {
-                "name": "space",
-                "ty": "Handle"
-            },
-            {
-                "name": "st",
-                "ty": "*mut Handle"
-            }
-        ]
-    },
-    {
-        "name": "sv_task_join",
-        "returns": "()",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "retval",
-                "ty": "*mut usize"
-            }
-        ]
-    },
-    {
-        "name": "sv_task_ctl",
-        "returns": "()",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "op",
-                "ty": "u32"
-            },
-            {
-                "name": "data",
-                "ty": "*mut Handle"
-            }
-        ]
-    },
-    {
-        "name": "sv_task_debug",
-        "returns": "()",
-        "args": [
-            {
-                "name": "hdl",
-                "ty": "Handle"
-            },
-            {
-                "name": "op",
-                "ty": "u32"
-            },
-            {
-                "name": "addr",
-                "ty": "usize"
-            },
-            {
-                "name": "data",
-                "ty": "*mut u8"
-            },
-            {
-                "name": "len",
-                "ty": "usize"
-            }
-        ]
-    },
-    {
-        "name": "sv_cpu_num",
-        "returns": "usize",
-        "vdso_specific": true,
-        "vdso_only": true,
-        "args": []
-    }
-]
+{
+    "types": [
+        "Task",
+        "Space",
+        "SuspendToken"
+    ],
+    "funcs": [
+        {
+            "name": "sv_task_exit",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "retval",
+                    "ty": "usize"
+                },
+                {
+                    "name": "kill_all",
+                    "ty": "bool"
+                }
+            ]
+        },
+        {
+            "name": "sv_task_sleep",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "ms",
+                    "ty": "u32"
+                }
+            ]
+        },
+        {
+            "name": "sv_space_new",
+            "returns": "Handle",
+            "args": [
+                {
+                    "name": "root_virt",
+                    "ty": "*mut Handle"
+                }
+            ]
+        },
+        {
+            "name": "sv_task_exec",
+            "returns": "Handle",
+            "args": [
+                {
+                    "name": "ci",
+                    "ty": "*const ExecInfo"
+                }
+            ]
+        },
+        {
+            "name": "sv_task_new",
+            "returns": "Handle",
+            "args": [
+                {
+                    "name": "name",
+                    "ty": "*const u8"
+                },
+                {
+                    "name": "name_len",
+                    "ty": "usize"
+                },
+                {
+                    "name": "space",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "init_chan",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "st",
+                    "ty": "*mut Handle"
+                }
+            ]
+        },
+        {
+            "name": "sv_task_join",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "retval",
+                    "ty": "*mut usize"
+                }
+            ]
+        },
+        {
+            "name": "sv_task_ctl",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "op",
+                    "ty": "u32"
+                },
+                {
+                    "name": "data",
+                    "ty": "*mut Handle"
+                }
+            ]
+        },
+        {
+            "name": "sv_task_debug",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "hdl",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "op",
+                    "ty": "u32"
+                },
+                {
+                    "name": "addr",
+                    "ty": "usize"
+                },
+                {
+                    "name": "data",
+                    "ty": "*mut u8"
+                },
+                {
+                    "name": "len",
+                    "ty": "usize"
+                }
+            ]
+        },
+        {
+            "name": "sv_cpu_num",
+            "returns": "usize",
+            "vdso_specific": true,
+            "vdso_only": true,
+            "args": []
+        }
+    ]
+}

+ 44 - 39
h2o/kernel/syscall/time.json

@@ -1,39 +1,44 @@
-[
-    {
-        "name": "sv_time_get",
-        "returns": "()",
-        "vdso_specific": true,
-        "args": [
-            {
-                "name": "ptr",
-                "ty": "*mut ()"
-            }
-        ]
-    },
-    {
-        "name": "sv_random",
-        "returns": "u64",
-        "vdso_specific": true,
-        "vdso_only": true,
-        "args": []
-    },
-    {
-        "name": "sv_timer_new",
-        "returns": "Handle",
-        "args": []
-    },
-    {
-        "name": "sv_timer_set",
-        "returns": "()",
-        "args": [
-            {
-                "name": "handle",
-                "ty": "Handle"
-            },
-            {
-                "name": "duration_us",
-                "ty": "u64"
-            }
-        ]
-    }
-]
+{
+    "types": [
+        "Timer"
+    ],
+    "funcs": [
+        {
+            "name": "sv_time_get",
+            "returns": "()",
+            "vdso_specific": true,
+            "args": [
+                {
+                    "name": "ptr",
+                    "ty": "*mut ()"
+                }
+            ]
+        },
+        {
+            "name": "sv_random",
+            "returns": "u64",
+            "vdso_specific": true,
+            "vdso_only": true,
+            "args": []
+        },
+        {
+            "name": "sv_timer_new",
+            "returns": "Handle",
+            "args": []
+        },
+        {
+            "name": "sv_timer_set",
+            "returns": "()",
+            "args": [
+                {
+                    "name": "handle",
+                    "ty": "Handle"
+                },
+                {
+                    "name": "duration_us",
+                    "ty": "u64"
+                }
+            ]
+        }
+    ]
+}

+ 29 - 33
h2o/libs/archop/src/x86_64/lock.rs

@@ -1,4 +1,7 @@
-use core::sync::atomic::{AtomicUsize, Ordering::*};
+use core::{
+    mem,
+    sync::atomic::{AtomicUsize, Ordering::*},
+};
 
 pub mod mutex;
 pub mod rwlock;
@@ -20,6 +23,15 @@ impl Drop for IntrState {
 
 pub struct PreemptStateGuard<'a>(u64, &'a AtomicUsize);
 
+impl<'a> PreemptStateGuard<'a> {
+    #[inline]
+    pub fn into_raw(self) -> (usize, u64) {
+        let ret = (self.1.load(Relaxed), self.0);
+        mem::forget(self);
+        ret
+    }
+}
+
 impl<'a> Drop for PreemptStateGuard<'a> {
     fn drop(&mut self) {
         if self.1.fetch_sub(1, Release) == 1 {
@@ -38,7 +50,7 @@ impl PreemptState {
 
     pub fn lock(&self) -> PreemptStateGuard {
         let flags = unsafe { crate::pause_intr() };
-        self.0.fetch_add(1, Acquire);
+        self.0.fetch_add(1, Relaxed);
         PreemptStateGuard(flags, &self.0)
     }
 
@@ -52,46 +64,30 @@ impl PreemptState {
         func()
     }
 
+    #[inline]
     pub fn is_locked(&self) -> bool {
-        self.0.load(Acquire) > 0
+        self.0.load(Relaxed) > 0
     }
 
+    #[inline]
     pub fn raw(&self) -> usize {
-        self.0.load(Acquire)
+        self.0.load(Relaxed)
     }
 
     /// # Safety
     ///
-    /// This function must be called only if a [`PreemptStateGuard`] is
-    /// [`forget`]ed or peered with [`disable`].
+    /// `value` and `flags` must be from [`into_raw`] method and the current
+    /// state must be valid.
     ///
-    /// [`forget`]: core::mem::forget
-    /// [`disable`]: Self::disable
-    pub unsafe fn enable(&self, flags: Option<u64>) -> bool {
-        let p = self.0.load(Acquire);
-        if p > 0
-            && self
-                .0
-                .compare_exchange_weak(p, p - 1, AcqRel, Acquire)
-                .is_ok()
-        {
-            if p == 1 {
-                crate::resume_intr(flags);
-            }
-            true
+    /// [`into_raw`]: PreemptStateGuard::into_raw
+    #[inline]
+    pub unsafe fn from_raw(&self, value: usize, flags: u64) -> PreemptStateGuard {
+        self.0.store(if value > 0 { value } else { 1 }, Release);
+        let flags = if flags > 0 {
+            flags
         } else {
-            false
-        }
-    }
-
-    /// # Safety
-    ///
-    /// This function must be called only if peered with [`enable`].
-    ///
-    /// [`enable`]: Self::enable
-    pub unsafe fn disable(&self) -> (u64, usize) {
-        let flags = crate::pause_intr();
-        let old = self.0.fetch_add(1, AcqRel);
-        (flags, old)
+            crate::pause_intr()
+        };
+        PreemptStateGuard(flags, &self.0)
     }
 }

+ 0 - 2
h2o/libs/collection_ex/src/lib.rs

@@ -1,7 +1,5 @@
 #![no_std]
 #![feature(build_hasher_simple_hash_one)]
-#![feature(const_btree_new)]
-#![feature(map_first_last)]
 #![feature(map_try_insert)]
 
 mod chash_map;

+ 3 - 1
h2o/libs/minfo/src/lib.rs

@@ -4,7 +4,9 @@ use core::alloc::Layout;
 
 // Physical addresses
 
-pub const KARGS_BASE: usize = 0;
+// The rust compiler panics on debug mode runtime when using the 0 address. Use
+// another free address for passing arguments.
+pub const KARGS_BASE: usize = 0x1000;
 
 pub const TRAMPOLINE_RANGE: core::ops::Range<usize> = 0..0x100000;
 

+ 3 - 1
h2o/libs/syscall/build.rs

@@ -1,9 +1,11 @@
 fn main() {
     #[cfg(all(feature = "call", feature = "vdso"))]
     {
+        const TARGET: &str = "../../../target/sysroot/usr/include/h2o.h";
         std::thread::spawn(|| {
             let config = cbindgen::Config::from_file("cbindgen.toml").unwrap();
             println!("cargo:rerun-if-changed=cbindgen.toml");
+            println!("cargo:rerun-if-changed={TARGET}");
 
             let src_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
             let bindings = cbindgen::Builder::new()
@@ -12,7 +14,7 @@ fn main() {
                 .generate()
                 .unwrap();
 
-            let c_target_path = src_dir.join("../../../target/sysroot/usr/include/h2o.h");
+            let c_target_path = src_dir.join(TARGET);
             bindings.write_to_file(c_target_path);
         });
     }

+ 1 - 6
h2o/libs/syscall/src/call.rs

@@ -15,12 +15,7 @@ pub struct Syscall {
 
 #[cfg(all(not(feature = "stub"), feature = "call"))]
 use crate::{
-    c_ty::*,
-    ipc::RawPacket,
-    mem::{Flags, MemInfo, VirtMapInfo},
-    res::IntrConfig,
-    task::ExecInfo,
-    Feature, Handle, SerdeReg,
+    c_ty::*, ipc::RawPacket, mem::*, res::IntrConfig, task::ExecInfo, Feature, Handle, SerdeReg,
 };
 
 #[cfg(feature = "vdso")]

+ 82 - 94
h2o/libs/syscall/src/error.rs

@@ -1,6 +1,9 @@
 pub mod c_ty;
 
-use core::{fmt::Debug, ops::Range};
+use core::{
+    fmt::{Debug, Display},
+    ops::Range,
+};
 
 use crate::SerdeReg;
 
@@ -30,6 +33,8 @@ pub struct Error {
     raw: i32,
 }
 
+impl core::error::Error for Error {}
+
 impl Error {
     fn try_decode(val: usize) -> Option<Self> {
         let err = -(val as i32);
@@ -49,6 +54,15 @@ impl Error {
         }
     }
 
+    pub fn name(&self) -> &'static str {
+        let index = -self.raw;
+        if ERRC_RANGE.contains(&index) {
+            ERRC_NAME[index as usize]
+        } else {
+            CUSTOM_NAME[(index - CUSTOM_OFFSET) as usize]
+        }
+    }
+
     pub fn desc_by_index(errnum: i32) -> Option<&'static str> {
         let index = -errnum as usize;
         { ERRC_DESC.get(index) }
@@ -73,7 +87,13 @@ impl Error {
 
 impl Debug for Error {
     fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
-        write!(f, "Error: {}", self.desc())
+        write!(f, "{}", self.name())
+    }
+}
+
+impl Display for Error {
+    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(f, "{}", self.desc())
     }
 }
 
@@ -105,100 +125,68 @@ impl From<core::str::Utf8Error> for Error {
     }
 }
 
-macro_rules! declare_error {
-    ($e:ident, $v:literal, $desc:literal) => {
-        #[doc = $desc]
-        pub const $e: Error = Error { raw: -$v };
+macro_rules! declare_errors {
+    (($descs:ident, $names:ident, $num:expr) => {
+        $(const $e:ident = Error { $v:literal, $desc:literal };)*
+    }) => {
+        $(
+            #[doc = $desc]
+            pub const $e: Error = Error { raw: -$v };
+        )*
+
+        const $descs: [&str; $num] = [$($desc),*];
+        const $names: [&str; $num] = [$(stringify!($e)),*];
     };
 }
 
-declare_error!(OK, 0, "Success");
-declare_error!(EPERM, 1, "Operation not permitted");
-declare_error!(ENOENT, 2, "No such file or directory");
-declare_error!(ESRCH, 3, "No such process");
-declare_error!(EINTR, 4, "Interrupted system call");
-declare_error!(EIO, 5, "I/O error");
-declare_error!(ENXIO, 6, "No such device or address");
-declare_error!(E2BIG, 7, "Argument list too long");
-declare_error!(ENOEXEC, 8, "Executable format error");
-declare_error!(EBADF, 9, "Bad file number");
-declare_error!(ECHILD, 10, "No child processes");
-declare_error!(EAGAIN, 11, "Try again");
-declare_error!(ENOMEM, 12, "Out of memory");
-declare_error!(EACCES, 13, "Permission denied");
-declare_error!(EFAULT, 14, "Bad address");
-declare_error!(ENOTBLK, 15, "Block device required");
-declare_error!(EBUSY, 16, "Device or resource busy");
-declare_error!(EEXIST, 17, "File exists");
-declare_error!(EXDEV, 18, "Cross-device link");
-declare_error!(ENODEV, 19, "No such device");
-declare_error!(ENOTDIR, 20, "Not a directory");
-declare_error!(EISDIR, 21, "Is a directory");
-declare_error!(EINVAL, 22, "Invalid argument");
-declare_error!(ENFILE, 23, "File table overflow");
-declare_error!(EMFILE, 24, "Too many open files");
-declare_error!(ENOTTY, 25, "Not a typewriter");
-declare_error!(ETXTBSY, 26, "Text file busy");
-declare_error!(EFBIG, 27, "File too large");
-declare_error!(ENOSPC, 28, "No space left on device");
-declare_error!(ESPIPE, 29, "Illegal seek");
-declare_error!(EROFS, 30, "Read-only file system");
-declare_error!(EMLINK, 31, "Too many links");
-declare_error!(EPIPE, 32, "Broken pipe");
-declare_error!(EDOM, 33, "Math argument out of domain of func");
-declare_error!(ERANGE, 34, "Range not available");
+declare_errors! {
+    (ERRC_DESC, ERRC_NAME, (ERRC_RANGE.end - ERRC_RANGE.start + 1) as usize) => {
+        const OK       = Error { 0, "Success" };
+        const EPERM    = Error { 1, "Operation not permitted" };
+        const ENOENT   = Error { 2, "No such file or directory" };
+        const ESRCH    = Error { 3, "No such process" };
+        const EINTR    = Error { 4, "Interrupted system call" };
+        const EIO      = Error { 5, "I/O error" };
+        const ENXIO    = Error { 6, "No such device or address" };
+        const E2BIG    = Error { 7, "Argument list too long" };
+        const ENOEXEC  = Error { 8, "Executable format error" };
+        const EBADF    = Error { 9, "Bad file number" };
+        const ECHILD   = Error { 10, "No child processes" };
+        const EAGAIN   = Error { 11, "Try again" };
+        const ENOMEM   = Error { 12, "Out of memory" };
+        const EACCES   = Error { 13, "Permission denied" };
+        const EFAULT   = Error { 14, "Bad address" };
+        const ENOTBLK  = Error { 15, "Block device required" };
+        const EBUSY    = Error { 16, "Device or resource busy" };
+        const EEXIST   = Error { 17, "File exists" };
+        const EXDEV    = Error { 18, "Cross-device link" };
+        const ENODEV   = Error { 19, "No such device" };
+        const ENOTDIR  = Error { 20, "Not a directory" };
+        const EISDIR   = Error { 21, "Is a directory" };
+        const EINVAL   = Error { 22, "Invalid argument" };
+        const ENFILE   = Error { 23, "File table overflow" };
+        const EMFILE   = Error { 24, "Too many open files" };
+        const ENOTTY   = Error { 25, "Not a typewriter" };
+        const ETXTBSY  = Error { 26, "Text file busy" };
+        const EFBIG    = Error { 27, "File too large" };
+        const ENOSPC   = Error { 28, "No space left on device" };
+        const ESPIPE   = Error { 29, "Illegal seek" };
+        const EROFS    = Error { 30, "Read-only file system" };
+        const EMLINK   = Error { 31, "Too many links" };
+        const EPIPE    = Error { 32, "Broken pipe" };
+        const EDOM     = Error { 33, "Math argument out of domain of func" };
+        const ERANGE   = Error { 34, "Range not available" };
+    }
+}
 
 const CUSTOM_OFFSET: i32 = CUSTOM_RANGE.start;
-declare_error!(EKILLED, 1001, "Object already killed");
-declare_error!(EBUFFER, 1002, "Buffer range exceeded");
-declare_error!(ETIME, 1003, "Timed out");
-declare_error!(EALIGN, 1004, "Pointer unaligned");
-declare_error!(ETYPE, 1005, "Object type mismatch");
-declare_error!(ESPRT, 1006, "Function not supported");
-
-const ERRC_DESC: &[&str] = &[
-    "OK",
-    "Operation not permitted",
-    "No such file or directory",
-    "No such process",
-    "Interrupted system call",
-    "I/O error",
-    "No such device or address",
-    "Argument list too long",
-    "Executable format error",
-    "Bad file number",
-    "No child processes",
-    "Try again",
-    "Out of memory",
-    "Permission denied",
-    "Bad address",
-    "Block device required",
-    "Device or resource busy",
-    "File exists",
-    "Cross-device link",
-    "No such device",
-    "Not a directory",
-    "Is a directory",
-    "Invalid argument",
-    "File table overflow",
-    "Too many open files",
-    "Not a typewriter",
-    "Text file busy",
-    "File too large",
-    "No space left on device",
-    "Illegal seek",
-    "Read-only file system",
-    "Too many links",
-    "Broken pipe",
-    "Math argument out of domain of func",
-    "Range not available",
-];
-
-const CUSTOM_DESC: &[&str] = &[
-    "Task already killed",
-    "Buffer range exceeded",
-    "Timed out",
-    "Pointer unaligned",
-    "Object type mismatch",
-    "Function not supported",
-];
+declare_errors! {
+    (CUSTOM_DESC, CUSTOM_NAME, (CUSTOM_RANGE.end - CUSTOM_RANGE.start) as usize) => {
+        const EKILLED = Error { 1001, "Object already killed" };
+        const EBUFFER = Error { 1002, "Buffer range exceeded" };
+        const ETIME   = Error { 1003, "Timed out" };
+        const EALIGN  = Error { 1004, "Pointer unaligned" };
+        const ETYPE   = Error { 1005, "Object type mismatch" };
+        const ESPRT   = Error { 1006, "Function not supported" };
+    }
+}

+ 4 - 6
h2o/libs/syscall/src/ipc.rs

@@ -14,10 +14,8 @@ pub struct RawPacket {
 
 pub const MAX_HANDLE_COUNT: usize = 256;
 pub const MAX_BUFFER_SIZE: usize = crate::mem::PAGE_SIZE;
-pub const CUSTOM_MSG_ID_START: usize = 0;
-pub const CUSTOM_MSG_ID_END: usize = 12;
 
-pub const SIG_GENERIC: usize = 0b0001;
-pub const SIG_READ: usize = 0b0010;
-pub const SIG_WRITE: usize = 0b0100;
-pub const SIG_TIMER: usize = 0b1000;
+pub const SIG_GENERIC: usize = 0b0000_0001;
+pub const SIG_READ: usize = 0b0000_0010;
+pub const SIG_WRITE: usize = 0b0000_0100;
+pub const SIG_TIMER: usize = 0b0000_1000;

+ 2 - 0
h2o/libs/syscall/src/lib.rs

@@ -1,9 +1,11 @@
 #![no_std]
 #![warn(clippy::missing_panics_doc)]
 #![feature(allocator_api)]
+#![feature(error_in_core)]
 #![feature(asm_const)]
 #![feature(lang_items)]
 #![feature(linkage)]
+#![feature(macro_metavar_expr)]
 
 pub mod call;
 pub mod error;

+ 28 - 0
h2o/libs/syscall/src/mem.rs

@@ -12,13 +12,34 @@ bitflags! {
         const EXECUTABLE  = 1 << 3;
         const UNCACHED    = 1 << 4;
     }
+
+    #[derive(Default)]
+    #[repr(transparent)]
+    pub struct PhysOptions: u32 {
+        const RESIZABLE = 1 << 0;
+        const ZEROED = 1 << 1;
+    }
 }
 
 impl SerdeReg for Flags {
+    #[inline]
+    fn encode(self) -> usize {
+        self.bits() as usize
+    }
+
+    #[inline]
+    fn decode(val: usize) -> Self {
+        Self::from_bits_truncate(val as u32)
+    }
+}
+
+impl SerdeReg for PhysOptions {
+    #[inline]
     fn encode(self) -> usize {
         self.bits() as usize
     }
 
+    #[inline]
     fn decode(val: usize) -> Self {
         Self::from_bits_truncate(val as u32)
     }
@@ -43,3 +64,10 @@ pub struct VirtMapInfo {
     pub align: usize,
     pub flags: Flags,
 }
+
+#[derive(Debug, Copy, Clone)]
+#[repr(C)]
+pub struct IoVec {
+    pub ptr: *mut u8,
+    pub len: usize,
+}

+ 1 - 6
h2o/libs/syscall/src/stub.rs

@@ -1,10 +1,5 @@
 use crate::{
-    c_ty::*,
-    ipc::RawPacket,
-    mem::{Flags, MemInfo, VirtMapInfo},
-    res::IntrConfig,
-    task::ExecInfo,
-    Feature, Handle, Syscall,
+    c_ty::*, ipc::RawPacket, mem::*, res::IntrConfig, task::ExecInfo, Feature, Handle, Syscall,
 };
 
 include!(concat!(env!("CARGO_MANIFEST_DIR"), "/target/stub.rs"));

+ 3 - 3
h2o/libs/syscall/syscall.ld

@@ -5,9 +5,9 @@ SECTIONS
     . = SIZEOF_HEADERS;
     .note.gnu.build-id  : { *(.note.gnu.build-id) } :note
 
-    .text       : { *(.text*) }     :load
-    .rodata     : { *(.rodata*) }   :load
-    .dynamic    : { *(.dynamic*) }  :load :dynamic
+    .text                   : { *(.text*) }     :load
+    .rodata ALIGN (0x10)    : { *(.rodata*) }   :load
+    .dynamic                : { *(.dynamic*) }  :load :dynamic
 
     /DISCARD/ : { *(.comment*) }
 }

+ 0 - 9
h2o/localdep/acpica.h

@@ -1,9 +0,0 @@
-#if !defined(_ACPICA_H_)
-#define _ACPICA_H_
-
-#include "acpica/include/acexcep.h"
-#include "acpica/include/acpi.h"
-#include "acpica/include/actbinfo.h"
-#include "acpica/include/actypes.h"
-
-#endif // _ACPICA_H_

+ 0 - 440
h2o/localdep/acpica/dispatcher/dsargs.c

@@ -1,440 +0,0 @@
-/******************************************************************************
- *
- * Module Name: dsargs - Support for execution of dynamic arguments for static
- *                       objects (regions, fields, buffer fields, etc.)
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acparser.h"
-#include "amlcode.h"
-#include "acdispat.h"
-#include "acnamesp.h"
-
-#define _COMPONENT          ACPI_DISPATCHER
-        ACPI_MODULE_NAME    ("dsargs")
-
-/* Local prototypes */
-
-static ACPI_STATUS
-AcpiDsExecuteArguments (
-    ACPI_NAMESPACE_NODE     *Node,
-    ACPI_NAMESPACE_NODE     *ScopeNode,
-    UINT32                  AmlLength,
-    UINT8                   *AmlStart);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsExecuteArguments
- *
- * PARAMETERS:  Node                - Object NS node
- *              ScopeNode           - Parent NS node
- *              AmlLength           - Length of executable AML
- *              AmlStart            - Pointer to the AML
- *
- * RETURN:      Status.
- *
- * DESCRIPTION: Late (deferred) execution of region or field arguments
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiDsExecuteArguments (
-    ACPI_NAMESPACE_NODE     *Node,
-    ACPI_NAMESPACE_NODE     *ScopeNode,
-    UINT32                  AmlLength,
-    UINT8                   *AmlStart)
-{
-    ACPI_STATUS             Status;
-    ACPI_PARSE_OBJECT       *Op;
-    ACPI_WALK_STATE         *WalkState;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsExecuteArguments, AmlStart);
-
-
-    /* Allocate a new parser op to be the root of the parsed tree */
-
-    Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP, AmlStart);
-    if (!Op)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    /* Save the Node for use in AcpiPsParseAml */
-
-    Op->Common.Node = ScopeNode;
-
-    /* Create and initialize a new parser state */
-
-    WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
-    if (!WalkState)
-    {
-        Status = AE_NO_MEMORY;
-        goto Cleanup;
-    }
-
-    Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
-        AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
-    if (ACPI_FAILURE (Status))
-    {
-        AcpiDsDeleteWalkState (WalkState);
-        goto Cleanup;
-    }
-
-    /* Mark this parse as a deferred opcode */
-
-    WalkState->ParseFlags = ACPI_PARSE_DEFERRED_OP;
-    WalkState->DeferredNode = Node;
-
-    /* Pass1: Parse the entire declaration */
-
-    Status = AcpiPsParseAml (WalkState);
-    if (ACPI_FAILURE (Status))
-    {
-        goto Cleanup;
-    }
-
-    /* Get and init the Op created above */
-
-    Op->Common.Node = Node;
-    AcpiPsDeleteParseTree (Op);
-
-    /* Evaluate the deferred arguments */
-
-    Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP, AmlStart);
-    if (!Op)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    Op->Common.Node = ScopeNode;
-
-    /* Create and initialize a new parser state */
-
-    WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
-    if (!WalkState)
-    {
-        Status = AE_NO_MEMORY;
-        goto Cleanup;
-    }
-
-    /* Execute the opcode and arguments */
-
-    Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
-        AmlLength, NULL, ACPI_IMODE_EXECUTE);
-    if (ACPI_FAILURE (Status))
-    {
-        AcpiDsDeleteWalkState (WalkState);
-        goto Cleanup;
-    }
-
-    /* Mark this execution as a deferred opcode */
-
-    WalkState->DeferredNode = Node;
-    Status = AcpiPsParseAml (WalkState);
-
-Cleanup:
-    AcpiPsDeleteParseTree (Op);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsGetBufferFieldArguments
- *
- * PARAMETERS:  ObjDesc         - A valid BufferField object
- *
- * RETURN:      Status.
- *
- * DESCRIPTION: Get BufferField Buffer and Index. This implements the late
- *              evaluation of these field attributes.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsGetBufferFieldArguments (
-    ACPI_OPERAND_OBJECT     *ObjDesc)
-{
-    ACPI_OPERAND_OBJECT     *ExtraDesc;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsGetBufferFieldArguments, ObjDesc);
-
-
-    if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Get the AML pointer (method object) and BufferField node */
-
-    ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
-    Node = ObjDesc->BufferField.Node;
-
-    ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
-        ACPI_TYPE_BUFFER_FIELD, Node, NULL));
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n",
-        AcpiUtGetNodeName (Node)));
-
-    /* Execute the AML code for the TermArg arguments */
-
-    Status = AcpiDsExecuteArguments (Node, Node->Parent,
-        ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsGetBankFieldArguments
- *
- * PARAMETERS:  ObjDesc         - A valid BankField object
- *
- * RETURN:      Status.
- *
- * DESCRIPTION: Get BankField BankValue. This implements the late
- *              evaluation of these field attributes.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsGetBankFieldArguments (
-    ACPI_OPERAND_OBJECT     *ObjDesc)
-{
-    ACPI_OPERAND_OBJECT     *ExtraDesc;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsGetBankFieldArguments, ObjDesc);
-
-
-    if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Get the AML pointer (method object) and BankField node */
-
-    ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
-    Node = ObjDesc->BankField.Node;
-
-    ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
-        ACPI_TYPE_LOCAL_BANK_FIELD, Node, NULL));
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] BankField Arg Init\n",
-        AcpiUtGetNodeName (Node)));
-
-    /* Execute the AML code for the TermArg arguments */
-
-    Status = AcpiDsExecuteArguments (Node, Node->Parent,
-        ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsGetBufferArguments
- *
- * PARAMETERS:  ObjDesc         - A valid Buffer object
- *
- * RETURN:      Status.
- *
- * DESCRIPTION: Get Buffer length and initializer byte list. This implements
- *              the late evaluation of these attributes.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsGetBufferArguments (
-    ACPI_OPERAND_OBJECT     *ObjDesc)
-{
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsGetBufferArguments, ObjDesc);
-
-
-    if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Get the Buffer node */
-
-    Node = ObjDesc->Buffer.Node;
-    if (!Node)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "No pointer back to namespace node in buffer object %p",
-            ObjDesc));
-        return_ACPI_STATUS (AE_AML_INTERNAL);
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer Arg Init\n"));
-
-    /* Execute the AML code for the TermArg arguments */
-
-    Status = AcpiDsExecuteArguments (Node, Node,
-        ObjDesc->Buffer.AmlLength, ObjDesc->Buffer.AmlStart);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsGetPackageArguments
- *
- * PARAMETERS:  ObjDesc         - A valid Package object
- *
- * RETURN:      Status.
- *
- * DESCRIPTION: Get Package length and initializer byte list. This implements
- *              the late evaluation of these attributes.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsGetPackageArguments (
-    ACPI_OPERAND_OBJECT     *ObjDesc)
-{
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsGetPackageArguments, ObjDesc);
-
-
-    if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Get the Package node */
-
-    Node = ObjDesc->Package.Node;
-    if (!Node)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "No pointer back to namespace node in package %p", ObjDesc));
-        return_ACPI_STATUS (AE_AML_INTERNAL);
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Package Argument Init, AML Ptr: %p\n",
-        ObjDesc->Package.AmlStart));
-
-    /* Execute the AML code for the TermArg arguments */
-
-    Status = AcpiDsExecuteArguments (Node, Node,
-        ObjDesc->Package.AmlLength, ObjDesc->Package.AmlStart);
-
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsGetRegionArguments
- *
- * PARAMETERS:  ObjDesc         - A valid region object
- *
- * RETURN:      Status.
- *
- * DESCRIPTION: Get region address and length. This implements the late
- *              evaluation of these region attributes.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsGetRegionArguments (
-    ACPI_OPERAND_OBJECT     *ObjDesc)
-{
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     *ExtraDesc;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsGetRegionArguments, ObjDesc);
-
-
-    if (ObjDesc->Region.Flags & AOPOBJ_DATA_VALID)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
-    if (!ExtraDesc)
-    {
-        return_ACPI_STATUS (AE_NOT_EXIST);
-    }
-
-    /* Get the Region node */
-
-    Node = ObjDesc->Region.Node;
-
-    ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
-        ACPI_TYPE_REGION, Node, NULL));
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-        "[%4.4s] OpRegion Arg Init at AML %p\n",
-        AcpiUtGetNodeName (Node), ExtraDesc->Extra.AmlStart));
-
-    /* Execute the argument AML */
-
-    Status = AcpiDsExecuteArguments (Node, ExtraDesc->Extra.ScopeNode,
-        ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    Status = AcpiUtAddAddressRange (ObjDesc->Region.SpaceId,
-        ObjDesc->Region.Address, ObjDesc->Region.Length, Node);
-    return_ACPI_STATUS (Status);
-}

+ 0 - 418
h2o/localdep/acpica/dispatcher/dscontrol.c

@@ -1,418 +0,0 @@
-/******************************************************************************
- *
- * Module Name: dscontrol - Support for execution control opcodes -
- *                          if/else/while/return
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "amlcode.h"
-#include "acdispat.h"
-#include "acinterp.h"
-#include "acdebug.h"
-
-#define _COMPONENT          ACPI_DISPATCHER
-        ACPI_MODULE_NAME    ("dscontrol")
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsExecBeginControlOp
- *
- * PARAMETERS:  WalkList        - The list that owns the walk stack
- *              Op              - The control Op
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Handles all control ops encountered during control method
- *              execution.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsExecBeginControlOp (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Op)
-{
-    ACPI_STATUS             Status = AE_OK;
-    ACPI_GENERIC_STATE      *ControlState;
-
-
-    ACPI_FUNCTION_NAME (DsExecBeginControlOp);
-
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n",
-        Op, Op->Common.AmlOpcode, WalkState));
-
-    switch (Op->Common.AmlOpcode)
-    {
-    case AML_WHILE_OP:
-        /*
-         * If this is an additional iteration of a while loop, continue.
-         * There is no need to allocate a new control state.
-         */
-        if (WalkState->ControlState)
-        {
-            if (WalkState->ControlState->Control.AmlPredicateStart ==
-                (WalkState->ParserState.Aml - 1))
-            {
-                /* Reset the state to start-of-loop */
-
-                WalkState->ControlState->Common.State =
-                    ACPI_CONTROL_CONDITIONAL_EXECUTING;
-                break;
-            }
-        }
-
-        /*lint -fallthrough */
-
-    case AML_IF_OP:
-        /*
-         * IF/WHILE: Create a new control state to manage these
-         * constructs. We need to manage these as a stack, in order
-         * to handle nesting.
-         */
-        ControlState = AcpiUtCreateControlState ();
-        if (!ControlState)
-        {
-            Status = AE_NO_MEMORY;
-            break;
-        }
-        /*
-         * Save a pointer to the predicate for multiple executions
-         * of a loop
-         */
-        ControlState->Control.AmlPredicateStart =
-            WalkState->ParserState.Aml - 1;
-        ControlState->Control.PackageEnd =
-            WalkState->ParserState.PkgEnd;
-        ControlState->Control.Opcode =
-            Op->Common.AmlOpcode;
-        ControlState->Control.LoopTimeout = AcpiOsGetTimer () +
-           (UINT64) (AcpiGbl_MaxLoopIterations * ACPI_100NSEC_PER_SEC);
-
-        /* Push the control state on this walk's control stack */
-
-        AcpiUtPushGenericState (&WalkState->ControlState, ControlState);
-        break;
-
-    case AML_ELSE_OP:
-
-        /* Predicate is in the state object */
-        /* If predicate is true, the IF was executed, ignore ELSE part */
-
-        if (WalkState->LastPredicate)
-        {
-            Status = AE_CTRL_TRUE;
-        }
-
-        break;
-
-    case AML_RETURN_OP:
-
-        break;
-
-    default:
-
-        break;
-    }
-
-    return (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsExecEndControlOp
- *
- * PARAMETERS:  WalkList        - The list that owns the walk stack
- *              Op              - The control Op
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Handles all control ops encountered during control method
- *              execution.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsExecEndControlOp (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Op)
-{
-    ACPI_STATUS             Status = AE_OK;
-    ACPI_GENERIC_STATE      *ControlState;
-
-
-    ACPI_FUNCTION_NAME (DsExecEndControlOp);
-
-
-    switch (Op->Common.AmlOpcode)
-    {
-    case AML_IF_OP:
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", Op));
-
-        /*
-         * Save the result of the predicate in case there is an
-         * ELSE to come
-         */
-        WalkState->LastPredicate =
-            (BOOLEAN) WalkState->ControlState->Common.Value;
-
-        /*
-         * Pop the control state that was created at the start
-         * of the IF and free it
-         */
-        ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
-        AcpiUtDeleteGenericState (ControlState);
-        break;
-
-    case AML_ELSE_OP:
-
-        break;
-
-    case AML_WHILE_OP:
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", Op));
-
-        ControlState = WalkState->ControlState;
-        if (ControlState->Common.Value)
-        {
-            /* Predicate was true, the body of the loop was just executed */
-
-            /*
-             * This infinite loop detection mechanism allows the interpreter
-             * to escape possibly infinite loops. This can occur in poorly
-             * written AML when the hardware does not respond within a while
-             * loop and the loop does not implement a timeout.
-             */
-            if (ACPI_TIME_AFTER (AcpiOsGetTimer (),
-                    ControlState->Control.LoopTimeout))
-            {
-                Status = AE_AML_LOOP_TIMEOUT;
-                break;
-            }
-
-            /*
-             * Go back and evaluate the predicate and maybe execute the loop
-             * another time
-             */
-            Status = AE_CTRL_PENDING;
-            WalkState->AmlLastWhile =
-                ControlState->Control.AmlPredicateStart;
-            break;
-        }
-
-        /* Predicate was false, terminate this while loop */
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-            "[WHILE_OP] termination! Op=%p\n",Op));
-
-        /* Pop this control state and free it */
-
-        ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
-        AcpiUtDeleteGenericState (ControlState);
-        break;
-
-    case AML_RETURN_OP:
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-            "[RETURN_OP] Op=%p Arg=%p\n",Op, Op->Common.Value.Arg));
-
-        /*
-         * One optional operand -- the return value
-         * It can be either an immediate operand or a result that
-         * has been bubbled up the tree
-         */
-        if (Op->Common.Value.Arg)
-        {
-            /* Since we have a real Return(), delete any implicit return */
-
-            AcpiDsClearImplicitReturn (WalkState);
-
-            /* Return statement has an immediate operand */
-
-            Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
-            if (ACPI_FAILURE (Status))
-            {
-                return (Status);
-            }
-
-            /*
-             * If value being returned is a Reference (such as
-             * an arg or local), resolve it now because it may
-             * cease to exist at the end of the method.
-             */
-            Status = AcpiExResolveToValue (
-                &WalkState->Operands [0], WalkState);
-            if (ACPI_FAILURE (Status))
-            {
-                return (Status);
-            }
-
-            /*
-             * Get the return value and save as the last result
-             * value. This is the only place where WalkState->ReturnDesc
-             * is set to anything other than zero!
-             */
-            WalkState->ReturnDesc = WalkState->Operands[0];
-        }
-        else if (WalkState->ResultCount)
-        {
-            /* Since we have a real Return(), delete any implicit return */
-
-            AcpiDsClearImplicitReturn (WalkState);
-
-            /*
-             * The return value has come from a previous calculation.
-             *
-             * If value being returned is a Reference (such as
-             * an arg or local), resolve it now because it may
-             * cease to exist at the end of the method.
-             *
-             * Allow references created by the Index operator to return
-             * unchanged.
-             */
-            if ((ACPI_GET_DESCRIPTOR_TYPE (WalkState->Results->Results.ObjDesc[0]) ==
-                    ACPI_DESC_TYPE_OPERAND) &&
-                ((WalkState->Results->Results.ObjDesc [0])->Common.Type ==
-                    ACPI_TYPE_LOCAL_REFERENCE) &&
-                ((WalkState->Results->Results.ObjDesc [0])->Reference.Class !=
-                    ACPI_REFCLASS_INDEX))
-            {
-                Status = AcpiExResolveToValue (
-                    &WalkState->Results->Results.ObjDesc [0], WalkState);
-                if (ACPI_FAILURE (Status))
-                {
-                    return (Status);
-                }
-            }
-
-            WalkState->ReturnDesc = WalkState->Results->Results.ObjDesc [0];
-        }
-        else
-        {
-            /* No return operand */
-
-            if (WalkState->NumOperands)
-            {
-                AcpiUtRemoveReference (WalkState->Operands [0]);
-            }
-
-            WalkState->Operands[0] = NULL;
-            WalkState->NumOperands = 0;
-            WalkState->ReturnDesc = NULL;
-        }
-
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-            "Completed RETURN_OP State=%p, RetVal=%p\n",
-            WalkState, WalkState->ReturnDesc));
-
-        /* End the control method execution right now */
-
-        Status = AE_CTRL_TERMINATE;
-        break;
-
-    case AML_NOOP_OP:
-
-        /* Just do nothing! */
-
-        break;
-
-    case AML_BREAKPOINT_OP:
-
-        AcpiDbSignalBreakPoint (WalkState);
-
-        /* Call to the OSL in case OS wants a piece of the action */
-
-        Status = AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT,
-            "Executed AML Breakpoint opcode");
-        break;
-
-    case AML_BREAK_OP:
-    case AML_CONTINUE_OP: /* ACPI 2.0 */
-
-        /* Pop and delete control states until we find a while */
-
-        while (WalkState->ControlState &&
-                (WalkState->ControlState->Control.Opcode != AML_WHILE_OP))
-        {
-            ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
-            AcpiUtDeleteGenericState (ControlState);
-        }
-
-        /* No while found? */
-
-        if (!WalkState->ControlState)
-        {
-            return (AE_AML_NO_WHILE);
-        }
-
-        /* Was: WalkState->AmlLastWhile = WalkState->ControlState->Control.AmlPredicateStart; */
-
-        WalkState->AmlLastWhile =
-            WalkState->ControlState->Control.PackageEnd;
-
-        /* Return status depending on opcode */
-
-        if (Op->Common.AmlOpcode == AML_BREAK_OP)
-        {
-            Status = AE_CTRL_BREAK;
-        }
-        else
-        {
-            Status = AE_CTRL_CONTINUE;
-        }
-        break;
-
-    default:
-
-        ACPI_ERROR ((AE_INFO, "Unknown control opcode=0x%X Op=%p",
-            Op->Common.AmlOpcode, Op));
-
-        Status = AE_AML_BAD_OPCODE;
-        break;
-    }
-
-    return (Status);
-}

+ 0 - 257
h2o/localdep/acpica/dispatcher/dsdebug.c

@@ -1,257 +0,0 @@
-/******************************************************************************
- *
- * Module Name: dsdebug - Parser/Interpreter interface - debugging
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acdispat.h"
-#include "acnamesp.h"
-#include "acdisasm.h"
-#include "acinterp.h"
-
-
-#define _COMPONENT          ACPI_DISPATCHER
-        ACPI_MODULE_NAME    ("dsdebug")
-
-
-#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
-
-/* Local prototypes */
-
-static void
-AcpiDsPrintNodePathname (
-    ACPI_NAMESPACE_NODE     *Node,
-    const char              *Message);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsPrintNodePathname
- *
- * PARAMETERS:  Node            - Object
- *              Message         - Prefix message
- *
- * DESCRIPTION: Print an object's full namespace pathname
- *              Manages allocation/freeing of a pathname buffer
- *
- ******************************************************************************/
-
-static void
-AcpiDsPrintNodePathname (
-    ACPI_NAMESPACE_NODE     *Node,
-    const char              *Message)
-{
-    ACPI_BUFFER             Buffer;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (DsPrintNodePathname);
-
-    if (!Node)
-    {
-        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DISPATCH, "[NULL NAME]"));
-        return_VOID;
-    }
-
-    /* Convert handle to full pathname and print it (with supplied message) */
-
-    Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
-
-    Status = AcpiNsHandleToPathname (Node, &Buffer, TRUE);
-    if (ACPI_SUCCESS (Status))
-    {
-        if (Message)
-        {
-            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DISPATCH, "%s ", Message));
-        }
-
-        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DISPATCH, "[%s] (Node %p)",
-            (char *) Buffer.Pointer, Node));
-        ACPI_FREE (Buffer.Pointer);
-    }
-
-    return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsDumpMethodStack
- *
- * PARAMETERS:  Status          - Method execution status
- *              WalkState       - Current state of the parse tree walk
- *              Op              - Executing parse op
- *
- * RETURN:      None
- *
- * DESCRIPTION: Called when a method has been aborted because of an error.
- *              Dumps the method execution stack.
- *
- ******************************************************************************/
-
-void
-AcpiDsDumpMethodStack (
-    ACPI_STATUS             Status,
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Op)
-{
-    ACPI_PARSE_OBJECT       *Next;
-    ACPI_THREAD_STATE       *Thread;
-    ACPI_WALK_STATE         *NextWalkState;
-    ACPI_NAMESPACE_NODE     *PreviousMethod = NULL;
-    ACPI_OPERAND_OBJECT     *MethodDesc;
-
-
-    ACPI_FUNCTION_TRACE (DsDumpMethodStack);
-
-
-    /* Ignore control codes, they are not errors */
-
-    if ((Status & AE_CODE_MASK) == AE_CODE_CONTROL)
-    {
-        return_VOID;
-    }
-
-    /* We may be executing a deferred opcode */
-
-    if (WalkState->DeferredNode)
-    {
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-            "Executing subtree for Buffer/Package/Region\n"));
-        return_VOID;
-    }
-
-    /*
-     * If there is no Thread, we are not actually executing a method.
-     * This can happen when the iASL compiler calls the interpreter
-     * to perform constant folding.
-     */
-    Thread = WalkState->Thread;
-    if (!Thread)
-    {
-        return_VOID;
-    }
-
-    /* Display exception and method name */
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-        "\n**** Exception %s during execution of method ",
-        AcpiFormatException (Status)));
-
-    AcpiDsPrintNodePathname (WalkState->MethodNode, NULL);
-
-    /* Display stack of executing methods */
-
-    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DISPATCH,
-        "\n\nMethod Execution Stack:\n"));
-    NextWalkState = Thread->WalkStateList;
-
-    /* Walk list of linked walk states */
-
-    while (NextWalkState)
-    {
-        MethodDesc = NextWalkState->MethodDesc;
-        if (MethodDesc)
-        {
-            AcpiExStopTraceMethod (
-                (ACPI_NAMESPACE_NODE *) MethodDesc->Method.Node,
-                MethodDesc, WalkState);
-        }
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-            "    Method [%4.4s] executing: ",
-            AcpiUtGetNodeName (NextWalkState->MethodNode)));
-
-        /* First method is the currently executing method */
-
-        if (NextWalkState == WalkState)
-        {
-            if (Op)
-            {
-                /* Display currently executing ASL statement */
-
-                Next = Op->Common.Next;
-                Op->Common.Next = NULL;
-
-#ifdef ACPI_DISASSEMBLER
-                if (WalkState->MethodNode != AcpiGbl_RootNode)
-                {
-                    /* More verbose if not module-level code */
-
-                    AcpiOsPrintf ("Failed at ");
-                    AcpiDmDisassemble (NextWalkState, Op, ACPI_UINT32_MAX);
-                }
-#endif
-                Op->Common.Next = Next;
-            }
-        }
-        else
-        {
-            /*
-             * This method has called another method
-             * NOTE: the method call parse subtree is already deleted at
-             * this point, so we cannot disassemble the method invocation.
-             */
-            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DISPATCH, "Call to method "));
-            AcpiDsPrintNodePathname (PreviousMethod, NULL);
-        }
-
-        PreviousMethod = NextWalkState->MethodNode;
-        NextWalkState = NextWalkState->Next;
-        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DISPATCH, "\n"));
-    }
-
-    return_VOID;
-}
-
-#else
-
-void
-AcpiDsDumpMethodStack (
-    ACPI_STATUS             Status,
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Op)
-{
-    return;
-}
-
-#endif

+ 0 - 884
h2o/localdep/acpica/dispatcher/dsfield.c

@@ -1,884 +0,0 @@
-/******************************************************************************
- *
- * Module Name: dsfield - Dispatcher field routines
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "amlcode.h"
-#include "acdispat.h"
-#include "acinterp.h"
-#include "acnamesp.h"
-#include "acparser.h"
-
-#ifdef ACPI_EXEC_APP
-#include "aecommon.h"
-#endif
-
-
-#define _COMPONENT          ACPI_DISPATCHER
-        ACPI_MODULE_NAME    ("dsfield")
-
-/* Local prototypes */
-
-#ifdef ACPI_ASL_COMPILER
-#include "acdisasm.h"
-
-static ACPI_STATUS
-AcpiDsCreateExternalRegion (
-    ACPI_STATUS             LookupStatus,
-    ACPI_PARSE_OBJECT       *Op,
-    char                    *Path,
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_NAMESPACE_NODE     **Node);
-#endif
-
-static ACPI_STATUS
-AcpiDsGetFieldNames (
-    ACPI_CREATE_FIELD_INFO  *Info,
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Arg);
-
-
-#ifdef ACPI_ASL_COMPILER
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsCreateExternalRegion (iASL Disassembler only)
- *
- * PARAMETERS:  LookupStatus    - Status from NsLookup operation
- *              Op              - Op containing the Field definition and args
- *              Path            - Pathname of the region
- *  `           WalkState       - Current method state
- *              Node            - Where the new region node is returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Add region to the external list if NOT_FOUND. Create a new
- *              region node/object.
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiDsCreateExternalRegion (
-    ACPI_STATUS             LookupStatus,
-    ACPI_PARSE_OBJECT       *Op,
-    char                    *Path,
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_NAMESPACE_NODE     **Node)
-{
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-
-
-    if (LookupStatus != AE_NOT_FOUND)
-    {
-        return (LookupStatus);
-    }
-
-    /*
-     * Table disassembly:
-     * OperationRegion not found. Generate an External for it, and
-     * insert the name into the namespace.
-     */
-    AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_REGION, 0, 0);
-
-    Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_REGION,
-       ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, WalkState, Node);
-    if (ACPI_FAILURE (Status))
-    {
-        return (Status);
-    }
-
-    /* Must create and install a region object for the new node */
-
-    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
-    if (!ObjDesc)
-    {
-        return (AE_NO_MEMORY);
-    }
-
-    ObjDesc->Region.Node = *Node;
-    Status = AcpiNsAttachObject (*Node, ObjDesc, ACPI_TYPE_REGION);
-    return (Status);
-}
-#endif
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsCreateBufferField
- *
- * PARAMETERS:  Op                  - Current parse op (CreateXXField)
- *              WalkState           - Current state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Execute the CreateField operators:
- *              CreateBitFieldOp,
- *              CreateByteFieldOp,
- *              CreateWordFieldOp,
- *              CreateDwordFieldOp,
- *              CreateQwordFieldOp,
- *              CreateFieldOp       (all of which define a field in a buffer)
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsCreateBufferField (
-    ACPI_PARSE_OBJECT       *Op,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_PARSE_OBJECT       *Arg;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_OPERAND_OBJECT     *SecondDesc = NULL;
-    UINT32                  Flags;
-
-
-    ACPI_FUNCTION_TRACE (DsCreateBufferField);
-
-
-    /*
-     * Get the NameString argument (name of the new BufferField)
-     */
-    if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
-    {
-        /* For CreateField, name is the 4th argument */
-
-        Arg = AcpiPsGetArg (Op, 3);
-    }
-    else
-    {
-        /* For all other CreateXXXField operators, name is the 3rd argument */
-
-        Arg = AcpiPsGetArg (Op, 2);
-    }
-
-    if (!Arg)
-    {
-        return_ACPI_STATUS (AE_AML_NO_OPERAND);
-    }
-
-    if (WalkState->DeferredNode)
-    {
-        Node = WalkState->DeferredNode;
-        Status = AE_OK;
-    }
-    else
-    {
-        /* Execute flag should always be set when this function is entered */
-
-        if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
-        {
-            ACPI_ERROR ((AE_INFO,
-                "Parse execute mode is not set"));
-            return_ACPI_STATUS (AE_AML_INTERNAL);
-        }
-
-        /* Creating new namespace node, should not already exist */
-
-        Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
-            ACPI_NS_ERROR_IF_FOUND;
-
-        /*
-         * Mark node temporary if we are executing a normal control
-         * method. (Don't mark if this is a module-level code method)
-         */
-        if (WalkState->MethodNode &&
-            !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
-        {
-            Flags |= ACPI_NS_TEMPORARY;
-        }
-
-        /* Enter the NameString into the namespace */
-
-        Status = AcpiNsLookup (WalkState->ScopeInfo,
-            Arg->Common.Value.String, ACPI_TYPE_ANY,
-            ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
-                Arg->Common.Value.String, Status);
-            return_ACPI_STATUS (Status);
-        }
-    }
-
-    /*
-     * We could put the returned object (Node) on the object stack for later,
-     * but for now, we will put it in the "op" object that the parser uses,
-     * so we can get it again at the end of this scope.
-     */
-    Op->Common.Node = Node;
-
-    /*
-     * If there is no object attached to the node, this node was just created
-     * and we need to create the field object. Otherwise, this was a lookup
-     * of an existing node and we don't want to create the field object again.
-     */
-    ObjDesc = AcpiNsGetAttachedObject (Node);
-    if (ObjDesc)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /*
-     * The Field definition is not fully parsed at this time.
-     * (We must save the address of the AML for the buffer and index operands)
-     */
-
-    /* Create the buffer field object */
-
-    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER_FIELD);
-    if (!ObjDesc)
-    {
-        Status = AE_NO_MEMORY;
-        goto Cleanup;
-    }
-
-    /*
-     * Remember location in AML stream of the field unit opcode and operands
-     * -- since the buffer and index operands must be evaluated.
-     */
-    SecondDesc = ObjDesc->Common.NextObject;
-    SecondDesc->Extra.AmlStart = Op->Named.Data;
-    SecondDesc->Extra.AmlLength = Op->Named.Length;
-    ObjDesc->BufferField.Node = Node;
-
-    /* Attach constructed field descriptors to parent node */
-
-    Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_BUFFER_FIELD);
-    if (ACPI_FAILURE (Status))
-    {
-        goto Cleanup;
-    }
-
-
-Cleanup:
-
-    /* Remove local reference to the object */
-
-    AcpiUtRemoveReference (ObjDesc);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsGetFieldNames
- *
- * PARAMETERS:  Info            - CreateField info structure
- *  `           WalkState       - Current method state
- *              Arg             - First parser arg for the field name list
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Process all named fields in a field declaration. Names are
- *              entered into the namespace.
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiDsGetFieldNames (
-    ACPI_CREATE_FIELD_INFO  *Info,
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Arg)
-{
-    ACPI_STATUS             Status;
-    UINT64                  Position;
-    ACPI_PARSE_OBJECT       *Child;
-
-#ifdef ACPI_EXEC_APP
-    UINT64                  Value = 0;
-    ACPI_OPERAND_OBJECT     *ResultDesc;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    char                    *NamePath;
-#endif
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsGetFieldNames, Info);
-
-
-    /* First field starts at bit zero */
-
-    Info->FieldBitPosition = 0;
-
-    /* Process all elements in the field list (of parse nodes) */
-
-    while (Arg)
-    {
-        /*
-         * Four types of field elements are handled:
-         * 1) Name - Enters a new named field into the namespace
-         * 2) Offset - specifies a bit offset
-         * 3) AccessAs - changes the access mode/attributes
-         * 4) Connection - Associate a resource template with the field
-         */
-        switch (Arg->Common.AmlOpcode)
-        {
-        case AML_INT_RESERVEDFIELD_OP:
-
-            Position = (UINT64) Info->FieldBitPosition +
-                (UINT64) Arg->Common.Value.Size;
-
-            if (Position > ACPI_UINT32_MAX)
-            {
-                ACPI_ERROR ((AE_INFO,
-                    "Bit offset within field too large (> 0xFFFFFFFF)"));
-                return_ACPI_STATUS (AE_SUPPORT);
-            }
-
-            Info->FieldBitPosition = (UINT32) Position;
-            break;
-
-        case AML_INT_ACCESSFIELD_OP:
-        case AML_INT_EXTACCESSFIELD_OP:
-            /*
-             * Get new AccessType, AccessAttribute, and AccessLength fields
-             * -- to be used for all field units that follow, until the
-             * end-of-field or another AccessAs keyword is encountered.
-             * NOTE. These three bytes are encoded in the integer value
-             * of the parseop for convenience.
-             *
-             * In FieldFlags, preserve the flag bits other than the
-             * ACCESS_TYPE bits.
-             */
-
-            /* AccessType (ByteAcc, WordAcc, etc.) */
-
-            Info->FieldFlags = (UINT8)
-                ((Info->FieldFlags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
-                ((UINT8) ((UINT32) (Arg->Common.Value.Integer & 0x07))));
-
-            /* AccessAttribute (AttribQuick, AttribByte, etc.) */
-
-            Info->Attribute = (UINT8)
-                ((Arg->Common.Value.Integer >> 8) & 0xFF);
-
-            /* AccessLength (for serial/buffer protocols) */
-
-            Info->AccessLength = (UINT8)
-                ((Arg->Common.Value.Integer >> 16) & 0xFF);
-            break;
-
-        case AML_INT_CONNECTION_OP:
-            /*
-             * Clear any previous connection. New connection is used for all
-             * fields that follow, similar to AccessAs
-             */
-            Info->ResourceBuffer = NULL;
-            Info->ConnectionNode = NULL;
-            Info->PinNumberIndex = 0;
-
-            /*
-             * A Connection() is either an actual resource descriptor (buffer)
-             * or a named reference to a resource template
-             */
-            Child = Arg->Common.Value.Arg;
-            if (Child->Common.AmlOpcode == AML_INT_BYTELIST_OP)
-            {
-                Info->ResourceBuffer = Child->Named.Data;
-                Info->ResourceLength = (UINT16) Child->Named.Value.Integer;
-            }
-            else
-            {
-                /* Lookup the Connection() namepath, it should already exist */
-
-                Status = AcpiNsLookup (WalkState->ScopeInfo,
-                    Child->Common.Value.Name, ACPI_TYPE_ANY,
-                    ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
-                    WalkState, &Info->ConnectionNode);
-                if (ACPI_FAILURE (Status))
-                {
-                    ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
-                        Child->Common.Value.Name, Status);
-                    return_ACPI_STATUS (Status);
-                }
-            }
-            break;
-
-        case AML_INT_NAMEDFIELD_OP:
-
-            /* Lookup the name, it should already exist */
-
-            Status = AcpiNsLookup (WalkState->ScopeInfo,
-                (char *) &Arg->Named.Name, Info->FieldType,
-                ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
-                WalkState, &Info->FieldNode);
-            if (ACPI_FAILURE (Status))
-            {
-                ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
-                    (char *) &Arg->Named.Name, Status);
-                return_ACPI_STATUS (Status);
-            }
-            else
-            {
-                Arg->Common.Node = Info->FieldNode;
-                Info->FieldBitLength = Arg->Common.Value.Size;
-
-                /*
-                 * If there is no object attached to the node, this node was
-                 * just created and we need to create the field object.
-                 * Otherwise, this was a lookup of an existing node and we
-                 * don't want to create the field object again.
-                 */
-                if (!AcpiNsGetAttachedObject (Info->FieldNode))
-                {
-                    Status = AcpiExPrepFieldValue (Info);
-                    if (ACPI_FAILURE (Status))
-                    {
-                        return_ACPI_STATUS (Status);
-                    }
-#ifdef ACPI_EXEC_APP
-                    NamePath = AcpiNsGetExternalPathname (Info->FieldNode);
-                    ObjDesc = AcpiUtCreateIntegerObject (Value);
-                    if (ACPI_SUCCESS (AeLookupInitFileEntry (NamePath, &Value)))
-                    {
-                        AcpiExWriteDataToField (ObjDesc,
-                            AcpiNsGetAttachedObject (Info->FieldNode),
-                            &ResultDesc);
-                    }
-                    AcpiUtRemoveReference (ObjDesc);
-                    ACPI_FREE (NamePath);
-#endif
-                }
-            }
-
-            /* Keep track of bit position for the next field */
-
-            Position = (UINT64) Info->FieldBitPosition +
-                (UINT64) Arg->Common.Value.Size;
-
-            if (Position > ACPI_UINT32_MAX)
-            {
-                ACPI_ERROR ((AE_INFO,
-                    "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
-                    ACPI_CAST_PTR (char, &Info->FieldNode->Name)));
-                return_ACPI_STATUS (AE_SUPPORT);
-            }
-
-            Info->FieldBitPosition += Info->FieldBitLength;
-            Info->PinNumberIndex++; /* Index relative to previous Connection() */
-            break;
-
-        default:
-
-            ACPI_ERROR ((AE_INFO,
-                "Invalid opcode in field list: 0x%X",
-                Arg->Common.AmlOpcode));
-            return_ACPI_STATUS (AE_AML_BAD_OPCODE);
-        }
-
-        Arg = Arg->Common.Next;
-    }
-
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsCreateField
- *
- * PARAMETERS:  Op              - Op containing the Field definition and args
- *              RegionNode      - Object for the containing Operation Region
- *  `           WalkState       - Current method state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Create a new field in the specified operation region
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsCreateField (
-    ACPI_PARSE_OBJECT       *Op,
-    ACPI_NAMESPACE_NODE     *RegionNode,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status;
-    ACPI_PARSE_OBJECT       *Arg;
-    ACPI_CREATE_FIELD_INFO  Info;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsCreateField, Op);
-
-
-    /* First arg is the name of the parent OpRegion (must already exist) */
-
-    Arg = Op->Common.Value.Arg;
-
-    if (!RegionNode)
-    {
-        Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
-            ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
-            ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
-#ifdef ACPI_ASL_COMPILER
-        Status = AcpiDsCreateExternalRegion (Status, Arg,
-            Arg->Common.Value.Name, WalkState, &RegionNode);
-#endif
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
-                Arg->Common.Value.Name, Status);
-            return_ACPI_STATUS (Status);
-        }
-    }
-
-    memset (&Info, 0, sizeof (ACPI_CREATE_FIELD_INFO));
-
-    /* Second arg is the field flags */
-
-    Arg = Arg->Common.Next;
-    Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
-    Info.Attribute = 0;
-
-    /* Each remaining arg is a Named Field */
-
-    Info.FieldType = ACPI_TYPE_LOCAL_REGION_FIELD;
-    Info.RegionNode = RegionNode;
-
-    Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
-    if (Info.RegionNode->Object->Region.SpaceId == ACPI_ADR_SPACE_PLATFORM_COMM &&
-        !(RegionNode->Object->Field.InternalPccBuffer
-        = ACPI_ALLOCATE_ZEROED(Info.RegionNode->Object->Region.Length)))
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsInitFieldObjects
- *
- * PARAMETERS:  Op              - Op containing the Field definition and args
- *  `           WalkState       - Current method state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: For each "Field Unit" name in the argument list that is
- *              part of the field declaration, enter the name into the
- *              namespace.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsInitFieldObjects (
-    ACPI_PARSE_OBJECT       *Op,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status;
-    ACPI_PARSE_OBJECT       *Arg = NULL;
-    ACPI_NAMESPACE_NODE     *Node;
-    UINT8                   Type = 0;
-    UINT32                  Flags;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsInitFieldObjects, Op);
-
-
-    /* Execute flag should always be set when this function is entered */
-
-    if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
-    {
-        if (WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)
-        {
-            /* BankField Op is deferred, just return OK */
-
-            return_ACPI_STATUS (AE_OK);
-        }
-
-        ACPI_ERROR ((AE_INFO,
-            "Parse deferred mode is not set"));
-        return_ACPI_STATUS (AE_AML_INTERNAL);
-    }
-
-    /*
-     * Get the FieldList argument for this opcode. This is the start of the
-     * list of field elements.
-     */
-    switch (WalkState->Opcode)
-    {
-    case AML_FIELD_OP:
-
-        Arg = AcpiPsGetArg (Op, 2);
-        Type = ACPI_TYPE_LOCAL_REGION_FIELD;
-        break;
-
-    case AML_BANK_FIELD_OP:
-
-        Arg = AcpiPsGetArg (Op, 4);
-        Type = ACPI_TYPE_LOCAL_BANK_FIELD;
-        break;
-
-    case AML_INDEX_FIELD_OP:
-
-        Arg = AcpiPsGetArg (Op, 3);
-        Type = ACPI_TYPE_LOCAL_INDEX_FIELD;
-        break;
-
-    default:
-
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    /* Creating new namespace node(s), should not already exist */
-
-    Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
-        ACPI_NS_ERROR_IF_FOUND;
-
-    /*
-     * Mark node(s) temporary if we are executing a normal control
-     * method. (Don't mark if this is a module-level code method)
-     */
-    if (WalkState->MethodNode &&
-        !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
-    {
-        Flags |= ACPI_NS_TEMPORARY;
-    }
-
-#ifdef ACPI_EXEC_APP
-        Flags |= ACPI_NS_OVERRIDE_IF_FOUND;
-#endif
-    /*
-     * Walk the list of entries in the FieldList
-     * Note: FieldList can be of zero length. In this case, Arg will be NULL.
-     */
-    while (Arg)
-    {
-        /*
-         * Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested
-         * in the field names in order to enter them into the namespace.
-         */
-        if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
-        {
-            Status = AcpiNsLookup (WalkState->ScopeInfo,
-                (char *) &Arg->Named.Name, Type, ACPI_IMODE_LOAD_PASS1,
-                Flags, WalkState, &Node);
-            if (ACPI_FAILURE (Status))
-            {
-                ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
-                    (char *) &Arg->Named.Name, Status);
-                if (Status != AE_ALREADY_EXISTS)
-                {
-                    return_ACPI_STATUS (Status);
-                }
-
-                /* Name already exists, just ignore this error */
-
-                Status = AE_OK;
-            }
-
-            Arg->Common.Node = Node;
-        }
-
-        /* Get the next field element in the list */
-
-        Arg = Arg->Common.Next;
-    }
-
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsCreateBankField
- *
- * PARAMETERS:  Op              - Op containing the Field definition and args
- *              RegionNode      - Object for the containing Operation Region
- *              WalkState       - Current method state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Create a new bank field in the specified operation region
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsCreateBankField (
-    ACPI_PARSE_OBJECT       *Op,
-    ACPI_NAMESPACE_NODE     *RegionNode,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status;
-    ACPI_PARSE_OBJECT       *Arg;
-    ACPI_CREATE_FIELD_INFO  Info;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsCreateBankField, Op);
-
-
-    /* First arg is the name of the parent OpRegion (must already exist) */
-
-    Arg = Op->Common.Value.Arg;
-    if (!RegionNode)
-    {
-        Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
-            ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
-            ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
-#ifdef ACPI_ASL_COMPILER
-        Status = AcpiDsCreateExternalRegion (Status, Arg,
-            Arg->Common.Value.Name, WalkState, &RegionNode);
-#endif
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
-                Arg->Common.Value.Name, Status);
-            return_ACPI_STATUS (Status);
-        }
-    }
-
-    /* Second arg is the Bank Register (Field) (must already exist) */
-
-    Arg = Arg->Common.Next;
-    Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
-        ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
-        ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
-            Arg->Common.Value.String, Status);
-        return_ACPI_STATUS (Status);
-    }
-
-    /*
-     * Third arg is the BankValue
-     * This arg is a TermArg, not a constant
-     * It will be evaluated later, by AcpiDsEvalBankFieldOperands
-     */
-    Arg = Arg->Common.Next;
-
-    /* Fourth arg is the field flags */
-
-    Arg = Arg->Common.Next;
-    Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
-
-    /* Each remaining arg is a Named Field */
-
-    Info.FieldType = ACPI_TYPE_LOCAL_BANK_FIELD;
-    Info.RegionNode = RegionNode;
-
-    /*
-     * Use Info.DataRegisterNode to store BankField Op
-     * It's safe because DataRegisterNode will never be used when create
-     * bank field \we store AmlStart and AmlLength in the BankField Op for
-     * late evaluation. Used in AcpiExPrepFieldValue(Info)
-     *
-     * TBD: Or, should we add a field in ACPI_CREATE_FIELD_INFO, like
-     * "void *ParentOp"?
-     */
-    Info.DataRegisterNode = (ACPI_NAMESPACE_NODE*) Op;
-
-    Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsCreateIndexField
- *
- * PARAMETERS:  Op              - Op containing the Field definition and args
- *              RegionNode      - Object for the containing Operation Region
- *  `           WalkState       - Current method state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Create a new index field in the specified operation region
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsCreateIndexField (
-    ACPI_PARSE_OBJECT       *Op,
-    ACPI_NAMESPACE_NODE     *RegionNode,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status;
-    ACPI_PARSE_OBJECT       *Arg;
-    ACPI_CREATE_FIELD_INFO  Info;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsCreateIndexField, Op);
-
-
-    /* First arg is the name of the Index register (must already exist) */
-
-    Arg = Op->Common.Value.Arg;
-    Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
-        ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
-        ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
-            Arg->Common.Value.String, Status);
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Second arg is the data register (must already exist) */
-
-    Arg = Arg->Common.Next;
-    Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
-        ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
-        ACPI_NS_SEARCH_PARENT, WalkState, &Info.DataRegisterNode);
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
-            Arg->Common.Value.String, Status);
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Next arg is the field flags */
-
-    Arg = Arg->Common.Next;
-    Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
-
-    /* Each remaining arg is a Named Field */
-
-    Info.FieldType = ACPI_TYPE_LOCAL_INDEX_FIELD;
-    Info.RegionNode = RegionNode;
-
-    Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
-    return_ACPI_STATUS (Status);
-}

+ 0 - 274
h2o/localdep/acpica/dispatcher/dsinit.c

@@ -1,274 +0,0 @@
-/******************************************************************************
- *
- * Module Name: dsinit - Object initialization namespace walk
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acdispat.h"
-#include "acnamesp.h"
-#include "actables.h"
-#include "acinterp.h"
-
-#define _COMPONENT          ACPI_DISPATCHER
-        ACPI_MODULE_NAME    ("dsinit")
-
-
-/* Local prototypes */
-
-static ACPI_STATUS
-AcpiDsInitOneObject (
-    ACPI_HANDLE             ObjHandle,
-    UINT32                  Level,
-    void                    *Context,
-    void                    **ReturnValue);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsInitOneObject
- *
- * PARAMETERS:  ObjHandle       - Node for the object
- *              Level           - Current nesting level
- *              Context         - Points to a init info struct
- *              ReturnValue     - Not used
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object
- *              within the namespace.
- *
- *              Currently, the only objects that require initialization are:
- *              1) Methods
- *              2) Operation Regions
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiDsInitOneObject (
-    ACPI_HANDLE             ObjHandle,
-    UINT32                  Level,
-    void                    *Context,
-    void                    **ReturnValue)
-{
-    ACPI_INIT_WALK_INFO     *Info = (ACPI_INIT_WALK_INFO *) Context;
-    ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-
-
-    ACPI_FUNCTION_ENTRY ();
-
-
-    /*
-     * We are only interested in NS nodes owned by the table that
-     * was just loaded
-     */
-    if (Node->OwnerId != Info->OwnerId)
-    {
-        return (AE_OK);
-    }
-
-    Info->ObjectCount++;
-
-    /* And even then, we are only interested in a few object types */
-
-    switch (AcpiNsGetType (ObjHandle))
-    {
-    case ACPI_TYPE_REGION:
-
-        Status = AcpiDsInitializeRegion (ObjHandle);
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_EXCEPTION ((AE_INFO, Status,
-                "During Region initialization %p [%4.4s]",
-                ObjHandle, AcpiUtGetNodeName (ObjHandle)));
-        }
-
-        Info->OpRegionCount++;
-        break;
-
-    case ACPI_TYPE_METHOD:
-        /*
-         * Auto-serialization support. We will examine each method that is
-         * NotSerialized to determine if it creates any Named objects. If
-         * it does, it will be marked serialized to prevent problems if
-         * the method is entered by two or more threads and an attempt is
-         * made to create the same named object twice -- which results in
-         * an AE_ALREADY_EXISTS exception and method abort.
-         */
-        Info->MethodCount++;
-        ObjDesc = AcpiNsGetAttachedObject (Node);
-        if (!ObjDesc)
-        {
-            break;
-        }
-
-        /* Ignore if already serialized */
-
-        if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
-        {
-            Info->SerialMethodCount++;
-            break;
-        }
-
-        if (AcpiGbl_AutoSerializeMethods)
-        {
-            /* Parse/scan method and serialize it if necessary */
-
-            AcpiDsAutoSerializeMethod (Node, ObjDesc);
-            if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
-            {
-                /* Method was just converted to Serialized */
-
-                Info->SerialMethodCount++;
-                Info->SerializedMethodCount++;
-                break;
-            }
-        }
-
-        Info->NonSerialMethodCount++;
-        break;
-
-    case ACPI_TYPE_DEVICE:
-
-        Info->DeviceCount++;
-        break;
-
-    default:
-
-        break;
-    }
-
-    /*
-     * We ignore errors from above, and always return OK, since
-     * we don't want to abort the walk on a single error.
-     */
-    return (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsInitializeObjects
- *
- * PARAMETERS:  TableDesc       - Descriptor for parent ACPI table
- *              StartNode       - Root of subtree to be initialized.
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
- *              necessary initialization on the objects found therein
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsInitializeObjects (
-    UINT32                  TableIndex,
-    ACPI_NAMESPACE_NODE     *StartNode)
-{
-    ACPI_STATUS             Status;
-    ACPI_INIT_WALK_INFO     Info;
-    ACPI_TABLE_HEADER       *Table;
-    ACPI_OWNER_ID           OwnerId;
-
-
-    ACPI_FUNCTION_TRACE (DsInitializeObjects);
-
-
-    Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-        "**** Starting initialization of namespace objects ****\n"));
-
-    /* Set all init info to zero */
-
-    memset (&Info, 0, sizeof (ACPI_INIT_WALK_INFO));
-
-    Info.OwnerId = OwnerId;
-    Info.TableIndex = TableIndex;
-
-    /* Walk entire namespace from the supplied root */
-
-    /*
-     * We don't use AcpiWalkNamespace since we do not want to acquire
-     * the namespace reader lock.
-     */
-    Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, StartNode, ACPI_UINT32_MAX,
-        ACPI_NS_WALK_NO_UNLOCK, AcpiDsInitOneObject, NULL, &Info, NULL);
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace"));
-    }
-
-    Status = AcpiGetTableByIndex (TableIndex, &Table);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* DSDT is always the first AML table */
-
-    if (ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_DSDT))
-    {
-        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
-            "\nInitializing Namespace objects:\n"));
-    }
-
-    /* Summary of objects initialized */
-
-    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
-        "Table [%4.4s: %-8.8s] (id %.2X) - %4u Objects with %3u Devices, "
-        "%3u Regions, %4u Methods (%u/%u/%u Serial/Non/Cvt)\n",
-        Table->Signature, Table->OemTableId, OwnerId, Info.ObjectCount,
-        Info.DeviceCount,Info.OpRegionCount, Info.MethodCount,
-        Info.SerialMethodCount, Info.NonSerialMethodCount,
-        Info.SerializedMethodCount));
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n",
-        Info.MethodCount, Info.OpRegionCount));
-
-    return_ACPI_STATUS (AE_OK);
-}

+ 0 - 934
h2o/localdep/acpica/dispatcher/dsmethod.c

@@ -1,934 +0,0 @@
-/******************************************************************************
- *
- * Module Name: dsmethod - Parser/Interpreter interface - control method parsing
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acdispat.h"
-#include "acinterp.h"
-#include "acnamesp.h"
-#include "acparser.h"
-#include "amlcode.h"
-#include "acdebug.h"
-
-
-#define _COMPONENT          ACPI_DISPATCHER
-        ACPI_MODULE_NAME    ("dsmethod")
-
-/* Local prototypes */
-
-static ACPI_STATUS
-AcpiDsDetectNamedOpcodes (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       **OutOp);
-
-static ACPI_STATUS
-AcpiDsCreateMethodMutex (
-    ACPI_OPERAND_OBJECT     *MethodDesc);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsAutoSerializeMethod
- *
- * PARAMETERS:  Node                        - Namespace Node of the method
- *              ObjDesc                     - Method object attached to node
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Parse a control method AML to scan for control methods that
- *              need serialization due to the creation of named objects.
- *
- * NOTE: It is a bit of overkill to mark all such methods serialized, since
- * there is only a problem if the method actually blocks during execution.
- * A blocking operation is, for example, a Sleep() operation, or any access
- * to an operation region. However, it is probably not possible to easily
- * detect whether a method will block or not, so we simply mark all suspicious
- * methods as serialized.
- *
- * NOTE2: This code is essentially a generic routine for parsing a single
- * control method.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsAutoSerializeMethod (
-    ACPI_NAMESPACE_NODE     *Node,
-    ACPI_OPERAND_OBJECT     *ObjDesc)
-{
-    ACPI_STATUS             Status;
-    ACPI_PARSE_OBJECT       *Op = NULL;
-    ACPI_WALK_STATE         *WalkState;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsAutoSerializeMethod, Node);
-
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
-        "Method auto-serialization parse [%4.4s] %p\n",
-        AcpiUtGetNodeName (Node), Node));
-
-    /* Create/Init a root op for the method parse tree */
-
-    Op = AcpiPsAllocOp (AML_METHOD_OP, ObjDesc->Method.AmlStart);
-    if (!Op)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    AcpiPsSetName (Op, Node->Name.Integer);
-    Op->Common.Node = Node;
-
-    /* Create and initialize a new walk state */
-
-    WalkState = AcpiDsCreateWalkState (Node->OwnerId, NULL, NULL, NULL);
-    if (!WalkState)
-    {
-        AcpiPsFreeOp (Op);
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    Status = AcpiDsInitAmlWalk (WalkState, Op, Node,
-        ObjDesc->Method.AmlStart, ObjDesc->Method.AmlLength, NULL, 0);
-    if (ACPI_FAILURE (Status))
-    {
-        AcpiDsDeleteWalkState (WalkState);
-        AcpiPsFreeOp (Op);
-        return_ACPI_STATUS (Status);
-    }
-
-    WalkState->DescendingCallback = AcpiDsDetectNamedOpcodes;
-
-    /* Parse the method, scan for creation of named objects */
-
-    Status = AcpiPsParseAml (WalkState);
-
-    AcpiPsDeleteParseTree (Op);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsDetectNamedOpcodes
- *
- * PARAMETERS:  WalkState       - Current state of the parse tree walk
- *              OutOp           - Unused, required for parser interface
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Descending callback used during the loading of ACPI tables.
- *              Currently used to detect methods that must be marked serialized
- *              in order to avoid problems with the creation of named objects.
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiDsDetectNamedOpcodes (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       **OutOp)
-{
-
-    ACPI_FUNCTION_NAME (AcpiDsDetectNamedOpcodes);
-
-
-    /* We are only interested in opcodes that create a new name */
-
-    if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_CREATE | AML_FIELD)))
-    {
-        return (AE_OK);
-    }
-
-    /*
-     * At this point, we know we have a Named object opcode.
-     * Mark the method as serialized. Later code will create a mutex for
-     * this method to enforce serialization.
-     *
-     * Note, ACPI_METHOD_IGNORE_SYNC_LEVEL flag means that we will ignore the
-     * Sync Level mechanism for this method, even though it is now serialized.
-     * Otherwise, there can be conflicts with existing ASL code that actually
-     * uses sync levels.
-     */
-    WalkState->MethodDesc->Method.SyncLevel = 0;
-    WalkState->MethodDesc->Method.InfoFlags |=
-        (ACPI_METHOD_SERIALIZED | ACPI_METHOD_IGNORE_SYNC_LEVEL);
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
-        "Method serialized [%4.4s] %p - [%s] (%4.4X)\n",
-        WalkState->MethodNode->Name.Ascii, WalkState->MethodNode,
-        WalkState->OpInfo->Name, WalkState->Opcode));
-
-    /* Abort the parse, no need to examine this method any further */
-
-    return (AE_CTRL_TERMINATE);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsMethodError
- *
- * PARAMETERS:  Status          - Execution status
- *              WalkState       - Current state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Called on method error. Invoke the global exception handler if
- *              present, dump the method data if the debugger is configured
- *
- *              Note: Allows the exception handler to change the status code
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsMethodError (
-    ACPI_STATUS             Status,
-    ACPI_WALK_STATE         *WalkState)
-{
-    UINT32                  AmlOffset;
-    ACPI_NAME               Name = 0;
-
-
-    ACPI_FUNCTION_ENTRY ();
-
-
-    /* Ignore AE_OK and control exception codes */
-
-    if (ACPI_SUCCESS (Status) ||
-        (Status & AE_CODE_CONTROL))
-    {
-        return (Status);
-    }
-
-    /* Invoke the global exception handler */
-
-    if (AcpiGbl_ExceptionHandler)
-    {
-        /* Exit the interpreter, allow handler to execute methods */
-
-        AcpiExExitInterpreter ();
-
-        /*
-         * Handler can map the exception code to anything it wants, including
-         * AE_OK, in which case the executing method will not be aborted.
-         */
-        AmlOffset = (UINT32) ACPI_PTR_DIFF (WalkState->Aml,
-            WalkState->ParserState.AmlStart);
-
-        if (WalkState->MethodNode)
-        {
-            Name = WalkState->MethodNode->Name.Integer;
-        }
-        else if (WalkState->DeferredNode)
-        {
-            Name = WalkState->DeferredNode->Name.Integer;
-        }
-
-        Status = AcpiGbl_ExceptionHandler (Status, Name,
-            WalkState->Opcode, AmlOffset, NULL);
-        AcpiExEnterInterpreter ();
-    }
-
-    AcpiDsClearImplicitReturn (WalkState);
-
-    if (ACPI_FAILURE (Status))
-    {
-        AcpiDsDumpMethodStack (Status, WalkState, WalkState->Op);
-
-        /* Display method locals/args if debugger is present */
-
-#ifdef ACPI_DEBUGGER
-        AcpiDbDumpMethodInfo (Status, WalkState);
-#endif
-    }
-
-    return (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsCreateMethodMutex
- *
- * PARAMETERS:  ObjDesc             - The method object
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Create a mutex object for a serialized control method
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiDsCreateMethodMutex (
-    ACPI_OPERAND_OBJECT     *MethodDesc)
-{
-    ACPI_OPERAND_OBJECT     *MutexDesc;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (DsCreateMethodMutex);
-
-
-    /* Create the new mutex object */
-
-    MutexDesc = AcpiUtCreateInternalObject (ACPI_TYPE_MUTEX);
-    if (!MutexDesc)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    /* Create the actual OS Mutex */
-
-    Status = AcpiOsCreateMutex (&MutexDesc->Mutex.OsMutex);
-    if (ACPI_FAILURE (Status))
-    {
-        AcpiUtDeleteObjectDesc (MutexDesc);
-        return_ACPI_STATUS (Status);
-    }
-
-    MutexDesc->Mutex.SyncLevel = MethodDesc->Method.SyncLevel;
-    MethodDesc->Method.Mutex = MutexDesc;
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsBeginMethodExecution
- *
- * PARAMETERS:  MethodNode          - Node of the method
- *              ObjDesc             - The method object
- *              WalkState           - current state, NULL if not yet executing
- *                                    a method.
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Prepare a method for execution. Parses the method if necessary,
- *              increments the thread count, and waits at the method semaphore
- *              for clearance to execute.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsBeginMethodExecution (
-    ACPI_NAMESPACE_NODE     *MethodNode,
-    ACPI_OPERAND_OBJECT     *ObjDesc,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status = AE_OK;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsBeginMethodExecution, MethodNode);
-
-
-    if (!MethodNode)
-    {
-        return_ACPI_STATUS (AE_NULL_ENTRY);
-    }
-
-    AcpiExStartTraceMethod (MethodNode, ObjDesc, WalkState);
-
-    /* Prevent wraparound of thread count */
-
-    if (ObjDesc->Method.ThreadCount == ACPI_UINT8_MAX)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "Method reached maximum reentrancy limit (255)"));
-        return_ACPI_STATUS (AE_AML_METHOD_LIMIT);
-    }
-
-    /*
-     * If this method is serialized, we need to acquire the method mutex.
-     */
-    if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
-    {
-        /*
-         * Create a mutex for the method if it is defined to be Serialized
-         * and a mutex has not already been created. We defer the mutex creation
-         * until a method is actually executed, to minimize the object count
-         */
-        if (!ObjDesc->Method.Mutex)
-        {
-            Status = AcpiDsCreateMethodMutex (ObjDesc);
-            if (ACPI_FAILURE (Status))
-            {
-                return_ACPI_STATUS (Status);
-            }
-        }
-
-        /*
-         * The CurrentSyncLevel (per-thread) must be less than or equal to
-         * the sync level of the method. This mechanism provides some
-         * deadlock prevention.
-         *
-         * If the method was auto-serialized, we just ignore the sync level
-         * mechanism, because auto-serialization of methods can interfere
-         * with ASL code that actually uses sync levels.
-         *
-         * Top-level method invocation has no walk state at this point
-         */
-        if (WalkState &&
-            (!(ObjDesc->Method.InfoFlags & ACPI_METHOD_IGNORE_SYNC_LEVEL)) &&
-            (WalkState->Thread->CurrentSyncLevel >
-                ObjDesc->Method.Mutex->Mutex.SyncLevel))
-        {
-            ACPI_ERROR ((AE_INFO,
-                "Cannot acquire Mutex for method [%4.4s]"
-                ", current SyncLevel is too large (%u)",
-                AcpiUtGetNodeName (MethodNode),
-                WalkState->Thread->CurrentSyncLevel));
-
-            return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
-        }
-
-        /*
-         * Obtain the method mutex if necessary. Do not acquire mutex for a
-         * recursive call.
-         */
-        if (!WalkState ||
-            !ObjDesc->Method.Mutex->Mutex.ThreadId ||
-            (WalkState->Thread->ThreadId !=
-                ObjDesc->Method.Mutex->Mutex.ThreadId))
-        {
-            /*
-             * Acquire the method mutex. This releases the interpreter if we
-             * block (and reacquires it before it returns)
-             */
-            Status = AcpiExSystemWaitMutex (
-                ObjDesc->Method.Mutex->Mutex.OsMutex, ACPI_WAIT_FOREVER);
-            if (ACPI_FAILURE (Status))
-            {
-                return_ACPI_STATUS (Status);
-            }
-
-            /* Update the mutex and walk info and save the original SyncLevel */
-
-            if (WalkState)
-            {
-                ObjDesc->Method.Mutex->Mutex.OriginalSyncLevel =
-                    WalkState->Thread->CurrentSyncLevel;
-
-                ObjDesc->Method.Mutex->Mutex.ThreadId =
-                    WalkState->Thread->ThreadId;
-
-                /*
-                 * Update the current SyncLevel only if this is not an auto-
-                 * serialized method. In the auto case, we have to ignore
-                 * the sync level for the method mutex (created for the
-                 * auto-serialization) because we have no idea of what the
-                 * sync level should be. Therefore, just ignore it.
-                 */
-                if (!(ObjDesc->Method.InfoFlags &
-                    ACPI_METHOD_IGNORE_SYNC_LEVEL))
-                {
-                    WalkState->Thread->CurrentSyncLevel =
-                        ObjDesc->Method.SyncLevel;
-                }
-            }
-            else
-            {
-                ObjDesc->Method.Mutex->Mutex.OriginalSyncLevel =
-                    ObjDesc->Method.Mutex->Mutex.SyncLevel;
-
-                ObjDesc->Method.Mutex->Mutex.ThreadId =
-                    AcpiOsGetThreadId ();
-            }
-        }
-
-        /* Always increase acquisition depth */
-
-        ObjDesc->Method.Mutex->Mutex.AcquisitionDepth++;
-    }
-
-    /*
-     * Allocate an Owner ID for this method, only if this is the first thread
-     * to begin concurrent execution. We only need one OwnerId, even if the
-     * method is invoked recursively.
-     */
-    if (!ObjDesc->Method.OwnerId)
-    {
-        Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
-        if (ACPI_FAILURE (Status))
-        {
-            goto Cleanup;
-        }
-    }
-
-    /*
-     * Increment the method parse tree thread count since it has been
-     * reentered one more time (even if it is the same thread)
-     */
-    ObjDesc->Method.ThreadCount++;
-    AcpiMethodCount++;
-    return_ACPI_STATUS (Status);
-
-
-Cleanup:
-    /* On error, must release the method mutex (if present) */
-
-    if (ObjDesc->Method.Mutex)
-    {
-        AcpiOsReleaseMutex (ObjDesc->Method.Mutex->Mutex.OsMutex);
-    }
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsCallControlMethod
- *
- * PARAMETERS:  Thread              - Info for this thread
- *              ThisWalkState       - Current walk state
- *              Op                  - Current Op to be walked
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Transfer execution to a called control method
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsCallControlMethod (
-    ACPI_THREAD_STATE       *Thread,
-    ACPI_WALK_STATE         *ThisWalkState,
-    ACPI_PARSE_OBJECT       *Op)
-{
-    ACPI_STATUS             Status;
-    ACPI_NAMESPACE_NODE     *MethodNode;
-    ACPI_WALK_STATE         *NextWalkState = NULL;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_EVALUATE_INFO      *Info;
-    UINT32                  i;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsCallControlMethod, ThisWalkState);
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-        "Calling method %p, currentstate=%p\n",
-        ThisWalkState->PrevOp, ThisWalkState));
-
-    /*
-     * Get the namespace entry for the control method we are about to call
-     */
-    MethodNode = ThisWalkState->MethodCallNode;
-    if (!MethodNode)
-    {
-        return_ACPI_STATUS (AE_NULL_ENTRY);
-    }
-
-    ObjDesc = AcpiNsGetAttachedObject (MethodNode);
-    if (!ObjDesc)
-    {
-        return_ACPI_STATUS (AE_NULL_OBJECT);
-    }
-
-    /* Init for new method, possibly wait on method mutex */
-
-    Status = AcpiDsBeginMethodExecution (
-        MethodNode, ObjDesc, ThisWalkState);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Begin method parse/execution. Create a new walk state */
-
-    NextWalkState = AcpiDsCreateWalkState (
-        ObjDesc->Method.OwnerId, NULL, ObjDesc, Thread);
-    if (!NextWalkState)
-    {
-        Status = AE_NO_MEMORY;
-        goto Cleanup;
-    }
-
-    /*
-     * The resolved arguments were put on the previous walk state's operand
-     * stack. Operands on the previous walk state stack always
-     * start at index 0. Also, null terminate the list of arguments
-     */
-    ThisWalkState->Operands [ThisWalkState->NumOperands] = NULL;
-
-    /*
-     * Allocate and initialize the evaluation information block
-     * TBD: this is somewhat inefficient, should change interface to
-     * DsInitAmlWalk. For now, keeps this struct off the CPU stack
-     */
-    Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
-    if (!Info)
-    {
-        Status = AE_NO_MEMORY;
-        goto Cleanup;
-    }
-
-    Info->Parameters = &ThisWalkState->Operands[0];
-
-    Status = AcpiDsInitAmlWalk (NextWalkState, NULL, MethodNode,
-        ObjDesc->Method.AmlStart, ObjDesc->Method.AmlLength,
-        Info, ACPI_IMODE_EXECUTE);
-
-    ACPI_FREE (Info);
-    if (ACPI_FAILURE (Status))
-    {
-        goto Cleanup;
-    }
-
-    NextWalkState->MethodNestingDepth = ThisWalkState->MethodNestingDepth + 1;
-
-    /*
-     * Delete the operands on the previous walkstate operand stack
-     * (they were copied to new objects)
-     */
-    for (i = 0; i < ObjDesc->Method.ParamCount; i++)
-    {
-        AcpiUtRemoveReference (ThisWalkState->Operands [i]);
-        ThisWalkState->Operands [i] = NULL;
-    }
-
-    /* Clear the operand stack */
-
-    ThisWalkState->NumOperands = 0;
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-        "**** Begin nested execution of [%4.4s] **** WalkState=%p\n",
-        MethodNode->Name.Ascii, NextWalkState));
-
-    ThisWalkState->MethodPathname = AcpiNsGetNormalizedPathname (MethodNode, TRUE);
-    ThisWalkState->MethodIsNested = TRUE;
-
-    /* Optional object evaluation log */
-
-    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EVALUATION,
-        "%-26s:  %*s%s\n", "   Nested method call",
-        NextWalkState->MethodNestingDepth * 3, " ",
-        &ThisWalkState->MethodPathname[1]));
-
-    /* Invoke an internal method if necessary */
-
-    if (ObjDesc->Method.InfoFlags & ACPI_METHOD_INTERNAL_ONLY)
-    {
-        Status = ObjDesc->Method.Dispatch.Implementation (NextWalkState);
-        if (Status == AE_OK)
-        {
-            Status = AE_CTRL_TERMINATE;
-        }
-    }
-
-    return_ACPI_STATUS (Status);
-
-
-Cleanup:
-
-    /* On error, we must terminate the method properly */
-
-    AcpiDsTerminateControlMethod (ObjDesc, NextWalkState);
-    AcpiDsDeleteWalkState (NextWalkState);
-
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsRestartControlMethod
- *
- * PARAMETERS:  WalkState           - State for preempted method (caller)
- *              ReturnDesc          - Return value from the called method
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Restart a method that was preempted by another (nested) method
- *              invocation. Handle the return value (if any) from the callee.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsRestartControlMethod (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_OPERAND_OBJECT     *ReturnDesc)
-{
-    ACPI_STATUS             Status;
-    int                     SameAsImplicitReturn;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsRestartControlMethod, WalkState);
-
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-        "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",
-        AcpiUtGetNodeName (WalkState->MethodNode),
-        WalkState->MethodCallOp, ReturnDesc));
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-        "    ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n",
-        WalkState->ReturnUsed,
-        WalkState->Results, WalkState));
-
-    /* Did the called method return a value? */
-
-    if (ReturnDesc)
-    {
-        /* Is the implicit return object the same as the return desc? */
-
-        SameAsImplicitReturn = (WalkState->ImplicitReturnObj == ReturnDesc);
-
-        /* Are we actually going to use the return value? */
-
-        if (WalkState->ReturnUsed)
-        {
-            /* Save the return value from the previous method */
-
-            Status = AcpiDsResultPush (ReturnDesc, WalkState);
-            if (ACPI_FAILURE (Status))
-            {
-                AcpiUtRemoveReference (ReturnDesc);
-                return_ACPI_STATUS (Status);
-            }
-
-            /*
-             * Save as THIS method's return value in case it is returned
-             * immediately to yet another method
-             */
-            WalkState->ReturnDesc = ReturnDesc;
-        }
-
-        /*
-         * The following code is the optional support for the so-called
-         * "implicit return". Some AML code assumes that the last value of the
-         * method is "implicitly" returned to the caller, in the absence of an
-         * explicit return value.
-         *
-         * Just save the last result of the method as the return value.
-         *
-         * NOTE: this is optional because the ASL language does not actually
-         * support this behavior.
-         */
-        else if (!AcpiDsDoImplicitReturn (ReturnDesc, WalkState, FALSE) ||
-                 SameAsImplicitReturn)
-        {
-            /*
-             * Delete the return value if it will not be used by the
-             * calling method or remove one reference if the explicit return
-             * is the same as the implicit return value.
-             */
-            AcpiUtRemoveReference (ReturnDesc);
-        }
-    }
-
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsTerminateControlMethod
- *
- * PARAMETERS:  MethodDesc          - Method object
- *              WalkState           - State associated with the method
- *
- * RETURN:      None
- *
- * DESCRIPTION: Terminate a control method. Delete everything that the method
- *              created, delete all locals and arguments, and delete the parse
- *              tree if requested.
- *
- * MUTEX:       Interpreter is locked
- *
- ******************************************************************************/
-
-void
-AcpiDsTerminateControlMethod (
-    ACPI_OPERAND_OBJECT     *MethodDesc,
-    ACPI_WALK_STATE         *WalkState)
-{
-
-    ACPI_FUNCTION_TRACE_PTR (DsTerminateControlMethod, WalkState);
-
-
-    /* MethodDesc is required, WalkState is optional */
-
-    if (!MethodDesc)
-    {
-        return_VOID;
-    }
-
-    if (WalkState)
-    {
-        /* Delete all arguments and locals */
-
-        AcpiDsMethodDataDeleteAll (WalkState);
-
-        /*
-         * Delete any namespace objects created anywhere within the
-         * namespace by the execution of this method. Unless:
-         * 1) This method is a module-level executable code method, in which
-         *    case we want make the objects permanent.
-         * 2) There are other threads executing the method, in which case we
-         *    will wait until the last thread has completed.
-         */
-        if (!(MethodDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL) &&
-             (MethodDesc->Method.ThreadCount == 1))
-        {
-            /* Delete any direct children of (created by) this method */
-
-            (void) AcpiExExitInterpreter ();
-            AcpiNsDeleteNamespaceSubtree (WalkState->MethodNode);
-            (void) AcpiExEnterInterpreter ();
-
-            /*
-             * Delete any objects that were created by this method
-             * elsewhere in the namespace (if any were created).
-             * Use of the ACPI_METHOD_MODIFIED_NAMESPACE optimizes the
-             * deletion such that we don't have to perform an entire
-             * namespace walk for every control method execution.
-             */
-            if (MethodDesc->Method.InfoFlags & ACPI_METHOD_MODIFIED_NAMESPACE)
-            {
-                (void) AcpiExExitInterpreter ();
-                AcpiNsDeleteNamespaceByOwner (MethodDesc->Method.OwnerId);
-                (void) AcpiExEnterInterpreter ();
-                MethodDesc->Method.InfoFlags &=
-                    ~ACPI_METHOD_MODIFIED_NAMESPACE;
-            }
-        }
-
-        /*
-         * If method is serialized, release the mutex and restore the
-         * current sync level for this thread
-         */
-        if (MethodDesc->Method.Mutex)
-        {
-            /* Acquisition Depth handles recursive calls */
-
-            MethodDesc->Method.Mutex->Mutex.AcquisitionDepth--;
-            if (!MethodDesc->Method.Mutex->Mutex.AcquisitionDepth)
-            {
-                WalkState->Thread->CurrentSyncLevel =
-                    MethodDesc->Method.Mutex->Mutex.OriginalSyncLevel;
-
-                AcpiOsReleaseMutex (
-                    MethodDesc->Method.Mutex->Mutex.OsMutex);
-                MethodDesc->Method.Mutex->Mutex.ThreadId = 0;
-            }
-        }
-    }
-
-    /* Decrement the thread count on the method */
-
-    if (MethodDesc->Method.ThreadCount)
-    {
-        MethodDesc->Method.ThreadCount--;
-    }
-    else
-    {
-        ACPI_ERROR ((AE_INFO,
-            "Invalid zero thread count in method"));
-    }
-
-    /* Are there any other threads currently executing this method? */
-
-    if (MethodDesc->Method.ThreadCount)
-    {
-        /*
-         * Additional threads. Do not release the OwnerId in this case,
-         * we immediately reuse it for the next thread executing this method
-         */
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-            "*** Completed execution of one thread, %u threads remaining\n",
-            MethodDesc->Method.ThreadCount));
-    }
-    else
-    {
-        /* This is the only executing thread for this method */
-
-        /*
-         * Support to dynamically change a method from NotSerialized to
-         * Serialized if it appears that the method is incorrectly written and
-         * does not support multiple thread execution. The best example of this
-         * is if such a method creates namespace objects and blocks. A second
-         * thread will fail with an AE_ALREADY_EXISTS exception.
-         *
-         * This code is here because we must wait until the last thread exits
-         * before marking the method as serialized.
-         */
-        if (MethodDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED_PENDING)
-        {
-            if (WalkState)
-            {
-                ACPI_INFO ((
-                    "Marking method %4.4s as Serialized "
-                    "because of AE_ALREADY_EXISTS error",
-                    WalkState->MethodNode->Name.Ascii));
-            }
-
-            /*
-             * Method tried to create an object twice and was marked as
-             * "pending serialized". The probable cause is that the method
-             * cannot handle reentrancy.
-             *
-             * The method was created as NotSerialized, but it tried to create
-             * a named object and then blocked, causing the second thread
-             * entrance to begin and then fail. Workaround this problem by
-             * marking the method permanently as Serialized when the last
-             * thread exits here.
-             */
-            MethodDesc->Method.InfoFlags &=
-                ~ACPI_METHOD_SERIALIZED_PENDING;
-
-            MethodDesc->Method.InfoFlags |=
-                (ACPI_METHOD_SERIALIZED | ACPI_METHOD_IGNORE_SYNC_LEVEL);
-            MethodDesc->Method.SyncLevel = 0;
-        }
-
-        /* No more threads, we can free the OwnerId */
-
-        if (!(MethodDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL))
-        {
-            AcpiUtReleaseOwnerId (&MethodDesc->Method.OwnerId);
-        }
-    }
-
-    AcpiExStopTraceMethod ((ACPI_NAMESPACE_NODE *) MethodDesc->Method.Node,
-        MethodDesc, WalkState);
-
-    return_VOID;
-}

+ 0 - 778
h2o/localdep/acpica/dispatcher/dsmthdat.c

@@ -1,778 +0,0 @@
-/*******************************************************************************
- *
- * Module Name: dsmthdat - control method arguments and local variables
- *
- ******************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acdispat.h"
-#include "acnamesp.h"
-#include "acinterp.h"
-
-
-#define _COMPONENT          ACPI_DISPATCHER
-        ACPI_MODULE_NAME    ("dsmthdat")
-
-/* Local prototypes */
-
-static void
-AcpiDsMethodDataDeleteValue (
-    UINT8                   Type,
-    UINT32                  Index,
-    ACPI_WALK_STATE         *WalkState);
-
-static ACPI_STATUS
-AcpiDsMethodDataSetValue (
-    UINT8                   Type,
-    UINT32                  Index,
-    ACPI_OPERAND_OBJECT     *Object,
-    ACPI_WALK_STATE         *WalkState);
-
-#ifdef ACPI_OBSOLETE_FUNCTIONS
-ACPI_OBJECT_TYPE
-AcpiDsMethodDataGetType (
-    UINT16                  Opcode,
-    UINT32                  Index,
-    ACPI_WALK_STATE         *WalkState);
-#endif
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsMethodDataInit
- *
- * PARAMETERS:  WalkState           - Current walk state object
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Initialize the data structures that hold the method's arguments
- *              and locals. The data struct is an array of namespace nodes for
- *              each - this allows RefOf and DeRefOf to work properly for these
- *              special data types.
- *
- * NOTES:       WalkState fields are initialized to zero by the
- *              ACPI_ALLOCATE_ZEROED().
- *
- *              A pseudo-Namespace Node is assigned to each argument and local
- *              so that RefOf() can return a pointer to the Node.
- *
- ******************************************************************************/
-
-void
-AcpiDsMethodDataInit (
-    ACPI_WALK_STATE         *WalkState)
-{
-    UINT32                  i;
-
-
-    ACPI_FUNCTION_TRACE (DsMethodDataInit);
-
-
-    /* Init the method arguments */
-
-    for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
-    {
-        ACPI_MOVE_32_TO_32 (&WalkState->Arguments[i].Name,
-            NAMEOF_ARG_NTE);
-
-        WalkState->Arguments[i].Name.Integer |= (i << 24);
-        WalkState->Arguments[i].DescriptorType = ACPI_DESC_TYPE_NAMED;
-        WalkState->Arguments[i].Type = ACPI_TYPE_ANY;
-        WalkState->Arguments[i].Flags = ANOBJ_METHOD_ARG;
-    }
-
-    /* Init the method locals */
-
-    for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)
-    {
-        ACPI_MOVE_32_TO_32 (&WalkState->LocalVariables[i].Name,
-            NAMEOF_LOCAL_NTE);
-
-        WalkState->LocalVariables[i].Name.Integer |= (i << 24);
-        WalkState->LocalVariables[i].DescriptorType = ACPI_DESC_TYPE_NAMED;
-        WalkState->LocalVariables[i].Type = ACPI_TYPE_ANY;
-        WalkState->LocalVariables[i].Flags = ANOBJ_METHOD_LOCAL;
-    }
-
-    return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsMethodDataDeleteAll
- *
- * PARAMETERS:  WalkState           - Current walk state object
- *
- * RETURN:      None
- *
- * DESCRIPTION: Delete method locals and arguments. Arguments are only
- *              deleted if this method was called from another method.
- *
- ******************************************************************************/
-
-void
-AcpiDsMethodDataDeleteAll (
-    ACPI_WALK_STATE         *WalkState)
-{
-    UINT32                  Index;
-
-
-    ACPI_FUNCTION_TRACE (DsMethodDataDeleteAll);
-
-
-    /* Detach the locals */
-
-    for (Index = 0; Index < ACPI_METHOD_NUM_LOCALS; Index++)
-    {
-        if (WalkState->LocalVariables[Index].Object)
-        {
-            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%u=%p\n",
-                Index, WalkState->LocalVariables[Index].Object));
-
-            /* Detach object (if present) and remove a reference */
-
-            AcpiNsDetachObject (&WalkState->LocalVariables[Index]);
-        }
-    }
-
-    /* Detach the arguments */
-
-    for (Index = 0; Index < ACPI_METHOD_NUM_ARGS; Index++)
-    {
-        if (WalkState->Arguments[Index].Object)
-        {
-            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%u=%p\n",
-                Index, WalkState->Arguments[Index].Object));
-
-            /* Detach object (if present) and remove a reference */
-
-            AcpiNsDetachObject (&WalkState->Arguments[Index]);
-        }
-    }
-
-    return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsMethodDataInitArgs
- *
- * PARAMETERS:  *Params         - Pointer to a parameter list for the method
- *              MaxParamCount   - The arg count for this method
- *              WalkState       - Current walk state object
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Initialize arguments for a method. The parameter list is a list
- *              of ACPI operand objects, either null terminated or whose length
- *              is defined by MaxParamCount.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsMethodDataInitArgs (
-    ACPI_OPERAND_OBJECT     **Params,
-    UINT32                  MaxParamCount,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status;
-    UINT32                  Index = 0;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsMethodDataInitArgs, Params);
-
-
-    if (!Params)
-    {
-        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-            "No parameter list passed to method\n"));
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Copy passed parameters into the new method stack frame */
-
-    while ((Index < ACPI_METHOD_NUM_ARGS) &&
-           (Index < MaxParamCount)        &&
-            Params[Index])
-    {
-        /*
-         * A valid parameter.
-         * Store the argument in the method/walk descriptor.
-         * Do not copy the arg in order to implement call by reference
-         */
-        Status = AcpiDsMethodDataSetValue (
-            ACPI_REFCLASS_ARG, Index, Params[Index], WalkState);
-        if (ACPI_FAILURE (Status))
-        {
-            return_ACPI_STATUS (Status);
-        }
-
-        Index++;
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%u args passed to method\n", Index));
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsMethodDataGetNode
- *
- * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
- *                                    ACPI_REFCLASS_ARG
- *              Index               - Which Local or Arg whose type to get
- *              WalkState           - Current walk state object
- *              Node                - Where the node is returned.
- *
- * RETURN:      Status and node
- *
- * DESCRIPTION: Get the Node associated with a local or arg.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsMethodDataGetNode (
-    UINT8                   Type,
-    UINT32                  Index,
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_NAMESPACE_NODE     **Node)
-{
-    ACPI_FUNCTION_TRACE (DsMethodDataGetNode);
-
-
-    /*
-     * Method Locals and Arguments are supported
-     */
-    switch (Type)
-    {
-    case ACPI_REFCLASS_LOCAL:
-
-        if (Index > ACPI_METHOD_MAX_LOCAL)
-        {
-            ACPI_ERROR ((AE_INFO,
-                "Local index %u is invalid (max %u)",
-                Index, ACPI_METHOD_MAX_LOCAL));
-            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
-        }
-
-        /* Return a pointer to the pseudo-node */
-
-        *Node = &WalkState->LocalVariables[Index];
-        break;
-
-    case ACPI_REFCLASS_ARG:
-
-        if (Index > ACPI_METHOD_MAX_ARG)
-        {
-            ACPI_ERROR ((AE_INFO,
-                "Arg index %u is invalid (max %u)",
-                Index, ACPI_METHOD_MAX_ARG));
-            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
-        }
-
-        /* Return a pointer to the pseudo-node */
-
-        *Node = &WalkState->Arguments[Index];
-        break;
-
-    default:
-
-        ACPI_ERROR ((AE_INFO, "Type %u is invalid", Type));
-        return_ACPI_STATUS (AE_TYPE);
-    }
-
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsMethodDataSetValue
- *
- * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
- *                                    ACPI_REFCLASS_ARG
- *              Index               - Which Local or Arg to get
- *              Object              - Object to be inserted into the stack entry
- *              WalkState           - Current walk state object
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
- *              Note: There is no "implicit conversion" for locals.
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiDsMethodDataSetValue (
-    UINT8                   Type,
-    UINT32                  Index,
-    ACPI_OPERAND_OBJECT     *Object,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status;
-    ACPI_NAMESPACE_NODE     *Node;
-
-
-    ACPI_FUNCTION_TRACE (DsMethodDataSetValue);
-
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-        "NewObj %p Type %2.2X, Refs=%u [%s]\n", Object,
-        Type, Object->Common.ReferenceCount,
-        AcpiUtGetTypeName (Object->Common.Type)));
-
-    /* Get the namespace node for the arg/local */
-
-    Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /*
-     * Increment ref count so object can't be deleted while installed.
-     * NOTE: We do not copy the object in order to preserve the call by
-     * reference semantics of ACPI Control Method invocation.
-     * (See ACPI Specification 2.0C)
-     */
-    AcpiUtAddReference (Object);
-
-    /* Install the object */
-
-    Node->Object = Object;
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsMethodDataGetValue
- *
- * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
- *                                    ACPI_REFCLASS_ARG
- *              Index               - Which localVar or argument to get
- *              WalkState           - Current walk state object
- *              DestDesc            - Where Arg or Local value is returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Retrieve value of selected Arg or Local for this method
- *              Used only in AcpiExResolveToValue().
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsMethodDataGetValue (
-    UINT8                   Type,
-    UINT32                  Index,
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_OPERAND_OBJECT     **DestDesc)
-{
-    ACPI_STATUS             Status;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_OPERAND_OBJECT     *Object;
-
-
-    ACPI_FUNCTION_TRACE (DsMethodDataGetValue);
-
-
-    /* Validate the object descriptor */
-
-    if (!DestDesc)
-    {
-        ACPI_ERROR ((AE_INFO, "Null object descriptor pointer"));
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    /* Get the namespace node for the arg/local */
-
-    Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Get the object from the node */
-
-    Object = Node->Object;
-
-    /* Examine the returned object, it must be valid. */
-
-    if (!Object)
-    {
-        /*
-         * Index points to uninitialized object.
-         * This means that either 1) The expected argument was
-         * not passed to the method, or 2) A local variable
-         * was referenced by the method (via the ASL)
-         * before it was initialized. Either case is an error.
-         */
-
-        /* If slack enabled, init the LocalX/ArgX to an Integer of value zero */
-
-        if (AcpiGbl_EnableInterpreterSlack)
-        {
-            Object = AcpiUtCreateIntegerObject ((UINT64) 0);
-            if (!Object)
-            {
-                return_ACPI_STATUS (AE_NO_MEMORY);
-            }
-
-            Node->Object = Object;
-        }
-
-        /* Otherwise, return the error */
-
-        else switch (Type)
-        {
-        case ACPI_REFCLASS_ARG:
-
-            ACPI_ERROR ((AE_INFO,
-                "Uninitialized Arg[%u] at node %p",
-                Index, Node));
-
-            return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
-
-        case ACPI_REFCLASS_LOCAL:
-            /*
-             * No error message for this case, will be trapped again later to
-             * detect and ignore cases of Store(LocalX,LocalX)
-             */
-            return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
-
-        default:
-
-            ACPI_ERROR ((AE_INFO, "Not a Arg/Local opcode: 0x%X", Type));
-            return_ACPI_STATUS (AE_AML_INTERNAL);
-        }
-    }
-
-    /*
-     * The Index points to an initialized and valid object.
-     * Return an additional reference to the object
-     */
-    *DestDesc = Object;
-    AcpiUtAddReference (Object);
-
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsMethodDataDeleteValue
- *
- * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
- *                                    ACPI_REFCLASS_ARG
- *              Index               - Which localVar or argument to delete
- *              WalkState           - Current walk state object
- *
- * RETURN:      None
- *
- * DESCRIPTION: Delete the entry at Opcode:Index. Inserts
- *              a null into the stack slot after the object is deleted.
- *
- ******************************************************************************/
-
-static void
-AcpiDsMethodDataDeleteValue (
-    UINT8                   Type,
-    UINT32                  Index,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_OPERAND_OBJECT     *Object;
-
-
-    ACPI_FUNCTION_TRACE (DsMethodDataDeleteValue);
-
-
-    /* Get the namespace node for the arg/local */
-
-    Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
-    if (ACPI_FAILURE (Status))
-    {
-        return_VOID;
-    }
-
-    /* Get the associated object */
-
-    Object = AcpiNsGetAttachedObject (Node);
-
-    /*
-     * Undefine the Arg or Local by setting its descriptor
-     * pointer to NULL. Locals/Args can contain both
-     * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
-     */
-    Node->Object = NULL;
-
-    if ((Object) &&
-        (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND))
-    {
-        /*
-         * There is a valid object.
-         * Decrement the reference count by one to balance the
-         * increment when the object was stored.
-         */
-        AcpiUtRemoveReference (Object);
-    }
-
-    return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsStoreObjectToLocal
- *
- * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
- *                                    ACPI_REFCLASS_ARG
- *              Index               - Which Local or Arg to set
- *              ObjDesc             - Value to be stored
- *              WalkState           - Current walk state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Store a value in an Arg or Local. The ObjDesc is installed
- *              as the new value for the Arg or Local and the reference count
- *              for ObjDesc is incremented.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsStoreObjectToLocal (
-    UINT8                   Type,
-    UINT32                  Index,
-    ACPI_OPERAND_OBJECT     *ObjDesc,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_OPERAND_OBJECT     *CurrentObjDesc;
-    ACPI_OPERAND_OBJECT     *NewObjDesc;
-
-
-    ACPI_FUNCTION_TRACE (DsStoreObjectToLocal);
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Type=%2.2X Index=%u Obj=%p\n",
-        Type, Index, ObjDesc));
-
-    /* Parameter validation */
-
-    if (!ObjDesc)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    /* Get the namespace node for the arg/local */
-
-    Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    CurrentObjDesc = AcpiNsGetAttachedObject (Node);
-    if (CurrentObjDesc == ObjDesc)
-    {
-        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n",
-            ObjDesc));
-        return_ACPI_STATUS (Status);
-    }
-
-    /*
-     * If the reference count on the object is more than one, we must
-     * take a copy of the object before we store. A reference count
-     * of exactly 1 means that the object was just created during the
-     * evaluation of an expression, and we can safely use it since it
-     * is not used anywhere else.
-     */
-    NewObjDesc = ObjDesc;
-    if (ObjDesc->Common.ReferenceCount > 1)
-    {
-        Status = AcpiUtCopyIobjectToIobject (
-            ObjDesc, &NewObjDesc, WalkState);
-        if (ACPI_FAILURE (Status))
-        {
-            return_ACPI_STATUS (Status);
-        }
-    }
-
-    /*
-     * If there is an object already in this slot, we either
-     * have to delete it, or if this is an argument and there
-     * is an object reference stored there, we have to do
-     * an indirect store!
-     */
-    if (CurrentObjDesc)
-    {
-        /*
-         * Check for an indirect store if an argument
-         * contains an object reference (stored as an Node).
-         * We don't allow this automatic dereferencing for
-         * locals, since a store to a local should overwrite
-         * anything there, including an object reference.
-         *
-         * If both Arg0 and Local0 contain RefOf (Local4):
-         *
-         * Store (1, Arg0)             - Causes indirect store to local4
-         * Store (1, Local0)           - Stores 1 in local0, overwriting
-         *                                  the reference to local4
-         * Store (1, DeRefof (Local0)) - Causes indirect store to local4
-         *
-         * Weird, but true.
-         */
-        if (Type == ACPI_REFCLASS_ARG)
-        {
-            /*
-             * If we have a valid reference object that came from RefOf(),
-             * do the indirect store
-             */
-            if ((ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) ==
-                    ACPI_DESC_TYPE_OPERAND) &&
-                (CurrentObjDesc->Common.Type ==
-                    ACPI_TYPE_LOCAL_REFERENCE) &&
-                (CurrentObjDesc->Reference.Class ==
-                    ACPI_REFCLASS_REFOF))
-            {
-                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-                    "Arg (%p) is an ObjRef(Node), storing in node %p\n",
-                    NewObjDesc, CurrentObjDesc));
-
-                /*
-                 * Store this object to the Node (perform the indirect store)
-                 * NOTE: No implicit conversion is performed, as per the ACPI
-                 * specification rules on storing to Locals/Args.
-                 */
-                Status = AcpiExStoreObjectToNode (NewObjDesc,
-                    CurrentObjDesc->Reference.Object, WalkState,
-                    ACPI_NO_IMPLICIT_CONVERSION);
-
-                /* Remove local reference if we copied the object above */
-
-                if (NewObjDesc != ObjDesc)
-                {
-                    AcpiUtRemoveReference (NewObjDesc);
-                }
-
-                return_ACPI_STATUS (Status);
-            }
-        }
-
-        /* Delete the existing object before storing the new one */
-
-        AcpiDsMethodDataDeleteValue (Type, Index, WalkState);
-    }
-
-    /*
-     * Install the Obj descriptor (*NewObjDesc) into
-     * the descriptor for the Arg or Local.
-     * (increments the object reference count by one)
-     */
-    Status = AcpiDsMethodDataSetValue (Type, Index, NewObjDesc, WalkState);
-
-    /* Remove local reference if we copied the object above */
-
-    if (NewObjDesc != ObjDesc)
-    {
-        AcpiUtRemoveReference (NewObjDesc);
-    }
-
-    return_ACPI_STATUS (Status);
-}
-
-
-#ifdef ACPI_OBSOLETE_FUNCTIONS
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsMethodDataGetType
- *
- * PARAMETERS:  Opcode              - Either AML_FIRST LOCAL_OP or
- *                                    AML_FIRST_ARG_OP
- *              Index               - Which Local or Arg whose type to get
- *              WalkState           - Current walk state object
- *
- * RETURN:      Data type of current value of the selected Arg or Local
- *
- * DESCRIPTION: Get the type of the object stored in the Local or Arg
- *
- ******************************************************************************/
-
-ACPI_OBJECT_TYPE
-AcpiDsMethodDataGetType (
-    UINT16                  Opcode,
-    UINT32                  Index,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_OPERAND_OBJECT     *Object;
-
-
-    ACPI_FUNCTION_TRACE (DsMethodDataGetType);
-
-
-    /* Get the namespace node for the arg/local */
-
-    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
-    if (ACPI_FAILURE (Status))
-    {
-        return_VALUE ((ACPI_TYPE_NOT_FOUND));
-    }
-
-    /* Get the object */
-
-    Object = AcpiNsGetAttachedObject (Node);
-    if (!Object)
-    {
-        /* Uninitialized local/arg, return TYPE_ANY */
-
-        return_VALUE (ACPI_TYPE_ANY);
-    }
-
-    /* Get the object type */
-
-    return_VALUE (Object->Type);
-}
-#endif

+ 0 - 590
h2o/localdep/acpica/dispatcher/dsobject.c

@@ -1,590 +0,0 @@
-/******************************************************************************
- *
- * Module Name: dsobject - Dispatcher object management routines
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acparser.h"
-#include "amlcode.h"
-#include "acdispat.h"
-#include "acnamesp.h"
-#include "acinterp.h"
-
-#define _COMPONENT          ACPI_DISPATCHER
-        ACPI_MODULE_NAME    ("dsobject")
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsBuildInternalObject
- *
- * PARAMETERS:  WalkState       - Current walk state
- *              Op              - Parser object to be translated
- *              ObjDescPtr      - Where the ACPI internal object is returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
- *              Simple objects are any objects other than a package object!
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsBuildInternalObject (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Op,
-    ACPI_OPERAND_OBJECT     **ObjDescPtr)
-{
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (DsBuildInternalObject);
-
-
-    *ObjDescPtr = NULL;
-    if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
-    {
-        /*
-         * This is a named object reference. If this name was
-         * previously looked up in the namespace, it was stored in
-         * this op. Otherwise, go ahead and look it up now
-         */
-        if (!Op->Common.Node)
-        {
-            /* Check if we are resolving a named reference within a package */
-
-            if ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
-                (Op->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP))
-            {
-                /*
-                 * We won't resolve package elements here, we will do this
-                 * after all ACPI tables are loaded into the namespace. This
-                 * behavior supports both forward references to named objects
-                 * and external references to objects in other tables.
-                 */
-                goto CreateNewObject;
-            }
-            else
-            {
-                Status = AcpiNsLookup (WalkState->ScopeInfo,
-                    Op->Common.Value.String,
-                    ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
-                    ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL,
-                    ACPI_CAST_INDIRECT_PTR (
-                        ACPI_NAMESPACE_NODE, &(Op->Common.Node)));
-                if (ACPI_FAILURE (Status))
-                {
-                    ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
-                        Op->Common.Value.String, Status);
-                    return_ACPI_STATUS (Status);
-                }
-            }
-        }
-    }
-
-CreateNewObject:
-
-    /* Create and init a new internal ACPI object */
-
-    ObjDesc = AcpiUtCreateInternalObject (
-        (AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode))->ObjectType);
-    if (!ObjDesc)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    Status = AcpiDsInitObjectFromOp (
-        WalkState, Op, Op->Common.AmlOpcode, &ObjDesc);
-    if (ACPI_FAILURE (Status))
-    {
-        AcpiUtRemoveReference (ObjDesc);
-        return_ACPI_STATUS (Status);
-    }
-
-    /*
-     * Handling for unresolved package reference elements.
-     * These are elements that are namepaths.
-     */
-    if ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
-        (Op->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP))
-    {
-        ObjDesc->Reference.Resolved = TRUE;
-
-        if ((Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
-            !ObjDesc->Reference.Node)
-        {
-            /*
-             * Name was unresolved above.
-             * Get the prefix node for later lookup
-             */
-            ObjDesc->Reference.Node = WalkState->ScopeInfo->Scope.Node;
-            ObjDesc->Reference.Aml = Op->Common.Aml;
-            ObjDesc->Reference.Resolved = FALSE;
-        }
-    }
-
-    *ObjDescPtr = ObjDesc;
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsBuildInternalBufferObj
- *
- * PARAMETERS:  WalkState       - Current walk state
- *              Op              - Parser object to be translated
- *              BufferLength    - Length of the buffer
- *              ObjDescPtr      - Where the ACPI internal object is returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Translate a parser Op package object to the equivalent
- *              namespace object
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsBuildInternalBufferObj (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Op,
-    UINT32                  BufferLength,
-    ACPI_OPERAND_OBJECT     **ObjDescPtr)
-{
-    ACPI_PARSE_OBJECT       *Arg;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_PARSE_OBJECT       *ByteList;
-    UINT32                  ByteListLength = 0;
-
-
-    ACPI_FUNCTION_TRACE (DsBuildInternalBufferObj);
-
-
-    /*
-     * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
-     * The buffer object already exists (from the NS node), otherwise it must
-     * be created.
-     */
-    ObjDesc = *ObjDescPtr;
-    if (!ObjDesc)
-    {
-        /* Create a new buffer object */
-
-        ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
-        *ObjDescPtr = ObjDesc;
-        if (!ObjDesc)
-        {
-            return_ACPI_STATUS (AE_NO_MEMORY);
-        }
-    }
-
-    /*
-     * Second arg is the buffer data (optional) ByteList can be either
-     * individual bytes or a string initializer. In either case, a
-     * ByteList appears in the AML.
-     */
-    Arg = Op->Common.Value.Arg;         /* skip first arg */
-
-    ByteList = Arg->Named.Next;
-    if (ByteList)
-    {
-        if (ByteList->Common.AmlOpcode != AML_INT_BYTELIST_OP)
-        {
-            ACPI_ERROR ((AE_INFO,
-                "Expecting bytelist, found AML opcode 0x%X in op %p",
-                ByteList->Common.AmlOpcode, ByteList));
-
-            AcpiUtRemoveReference (ObjDesc);
-            return (AE_TYPE);
-        }
-
-        ByteListLength = (UINT32) ByteList->Common.Value.Integer;
-    }
-
-    /*
-     * The buffer length (number of bytes) will be the larger of:
-     * 1) The specified buffer length and
-     * 2) The length of the initializer byte list
-     */
-    ObjDesc->Buffer.Length = BufferLength;
-    if (ByteListLength > BufferLength)
-    {
-        ObjDesc->Buffer.Length = ByteListLength;
-    }
-
-    /* Allocate the buffer */
-
-    if (ObjDesc->Buffer.Length == 0)
-    {
-        ObjDesc->Buffer.Pointer = NULL;
-        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-            "Buffer defined with zero length in AML, creating\n"));
-    }
-    else
-    {
-        ObjDesc->Buffer.Pointer =
-            ACPI_ALLOCATE_ZEROED (ObjDesc->Buffer.Length);
-        if (!ObjDesc->Buffer.Pointer)
-        {
-            AcpiUtDeleteObjectDesc (ObjDesc);
-            return_ACPI_STATUS (AE_NO_MEMORY);
-        }
-
-        /* Initialize buffer from the ByteList (if present) */
-
-        if (ByteList)
-        {
-            memcpy (ObjDesc->Buffer.Pointer, ByteList->Named.Data,
-                ByteListLength);
-        }
-    }
-
-    ObjDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
-    Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
-    return_ACPI_STATUS (AE_OK);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsCreateNode
- *
- * PARAMETERS:  WalkState       - Current walk state
- *              Node            - NS Node to be initialized
- *              Op              - Parser object to be translated
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Create the object to be associated with a namespace node
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsCreateNode (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_NAMESPACE_NODE     *Node,
-    ACPI_PARSE_OBJECT       *Op)
-{
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsCreateNode, Op);
-
-
-    /*
-     * Because of the execution pass through the non-control-method
-     * parts of the table, we can arrive here twice. Only init
-     * the named object node the first time through
-     */
-    if (AcpiNsGetAttachedObject (Node))
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    if (!Op->Common.Value.Arg)
-    {
-        /* No arguments, there is nothing to do */
-
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Build an internal object for the argument(s) */
-
-    Status = AcpiDsBuildInternalObject (
-        WalkState, Op->Common.Value.Arg, &ObjDesc);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Re-type the object according to its argument */
-
-    Node->Type = ObjDesc->Common.Type;
-
-    /* Attach obj to node */
-
-    Status = AcpiNsAttachObject (Node, ObjDesc, Node->Type);
-
-    /* Remove local reference to the object */
-
-    AcpiUtRemoveReference (ObjDesc);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsInitObjectFromOp
- *
- * PARAMETERS:  WalkState       - Current walk state
- *              Op              - Parser op used to init the internal object
- *              Opcode          - AML opcode associated with the object
- *              RetObjDesc      - Namespace object to be initialized
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Initialize a namespace object from a parser Op and its
- *              associated arguments. The namespace object is a more compact
- *              representation of the Op and its arguments.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsInitObjectFromOp (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Op,
-    UINT16                  Opcode,
-    ACPI_OPERAND_OBJECT     **RetObjDesc)
-{
-    const ACPI_OPCODE_INFO  *OpInfo;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_STATUS             Status = AE_OK;
-
-
-    ACPI_FUNCTION_TRACE (DsInitObjectFromOp);
-
-
-    ObjDesc = *RetObjDesc;
-    OpInfo = AcpiPsGetOpcodeInfo (Opcode);
-    if (OpInfo->Class == AML_CLASS_UNKNOWN)
-    {
-        /* Unknown opcode */
-
-        return_ACPI_STATUS (AE_TYPE);
-    }
-
-    /* Perform per-object initialization */
-
-    switch (ObjDesc->Common.Type)
-    {
-    case ACPI_TYPE_BUFFER:
-        /*
-         * Defer evaluation of Buffer TermArg operand
-         */
-        ObjDesc->Buffer.Node = ACPI_CAST_PTR (
-            ACPI_NAMESPACE_NODE, WalkState->Operands[0]);
-        ObjDesc->Buffer.AmlStart = Op->Named.Data;
-        ObjDesc->Buffer.AmlLength = Op->Named.Length;
-        break;
-
-    case ACPI_TYPE_PACKAGE:
-        /*
-         * Defer evaluation of Package TermArg operand and all
-         * package elements. (01/2017): We defer the element
-         * resolution to allow forward references from the package
-         * in order to provide compatibility with other ACPI
-         * implementations.
-         */
-        ObjDesc->Package.Node = ACPI_CAST_PTR (
-            ACPI_NAMESPACE_NODE, WalkState->Operands[0]);
-
-        if (!Op->Named.Data)
-        {
-            return_ACPI_STATUS (AE_OK);
-        }
-
-        ObjDesc->Package.AmlStart = Op->Named.Data;
-        ObjDesc->Package.AmlLength = Op->Named.Length;
-        break;
-
-    case ACPI_TYPE_INTEGER:
-
-        switch (OpInfo->Type)
-        {
-        case AML_TYPE_CONSTANT:
-            /*
-             * Resolve AML Constants here - AND ONLY HERE!
-             * All constants are integers.
-             * We mark the integer with a flag that indicates that it started
-             * life as a constant -- so that stores to constants will perform
-             * as expected (noop). ZeroOp is used as a placeholder for optional
-             * target operands.
-             */
-            ObjDesc->Common.Flags = AOPOBJ_AML_CONSTANT;
-
-            switch (Opcode)
-            {
-            case AML_ZERO_OP:
-
-                ObjDesc->Integer.Value = 0;
-                break;
-
-            case AML_ONE_OP:
-
-                ObjDesc->Integer.Value = 1;
-                break;
-
-            case AML_ONES_OP:
-
-                ObjDesc->Integer.Value = ACPI_UINT64_MAX;
-
-                /* Truncate value if we are executing from a 32-bit ACPI table */
-
-                (void) AcpiExTruncateFor32bitTable (ObjDesc);
-                break;
-
-            case AML_REVISION_OP:
-
-                ObjDesc->Integer.Value = ACPI_CA_VERSION;
-                break;
-
-            default:
-
-                ACPI_ERROR ((AE_INFO,
-                    "Unknown constant opcode 0x%X", Opcode));
-                Status = AE_AML_OPERAND_TYPE;
-                break;
-            }
-            break;
-
-        case AML_TYPE_LITERAL:
-
-            ObjDesc->Integer.Value = Op->Common.Value.Integer;
-
-            if (AcpiExTruncateFor32bitTable (ObjDesc))
-            {
-                /* Warn if we found a 64-bit constant in a 32-bit table */
-
-                ACPI_WARNING ((AE_INFO,
-                    "Truncated 64-bit constant found in 32-bit table: %8.8X%8.8X => %8.8X",
-                    ACPI_FORMAT_UINT64 (Op->Common.Value.Integer),
-                    (UINT32) ObjDesc->Integer.Value));
-            }
-            break;
-
-        default:
-
-            ACPI_ERROR ((AE_INFO, "Unknown Integer type 0x%X",
-                OpInfo->Type));
-            Status = AE_AML_OPERAND_TYPE;
-            break;
-        }
-        break;
-
-    case ACPI_TYPE_STRING:
-
-        ObjDesc->String.Pointer = Op->Common.Value.String;
-        ObjDesc->String.Length = (UINT32) strlen (Op->Common.Value.String);
-
-        /*
-         * The string is contained in the ACPI table, don't ever try
-         * to delete it
-         */
-        ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
-        break;
-
-    case ACPI_TYPE_METHOD:
-        break;
-
-    case ACPI_TYPE_LOCAL_REFERENCE:
-
-        switch (OpInfo->Type)
-        {
-        case AML_TYPE_LOCAL_VARIABLE:
-
-            /* Local ID (0-7) is (AML opcode - base AML_FIRST_LOCAL_OP) */
-
-            ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_FIRST_LOCAL_OP;
-            ObjDesc->Reference.Class = ACPI_REFCLASS_LOCAL;
-
-            Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_LOCAL,
-                ObjDesc->Reference.Value, WalkState,
-                ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
-                    &ObjDesc->Reference.Object));
-            break;
-
-        case AML_TYPE_METHOD_ARGUMENT:
-
-            /* Arg ID (0-6) is (AML opcode - base AML_FIRST_ARG_OP) */
-
-            ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_FIRST_ARG_OP;
-            ObjDesc->Reference.Class = ACPI_REFCLASS_ARG;
-
-            Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_ARG,
-                ObjDesc->Reference.Value, WalkState,
-                ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
-                    &ObjDesc->Reference.Object));
-            break;
-
-        default: /* Object name or Debug object */
-
-            switch (Op->Common.AmlOpcode)
-            {
-            case AML_INT_NAMEPATH_OP:
-
-                /* Node was saved in Op */
-
-                ObjDesc->Reference.Node = Op->Common.Node;
-                ObjDesc->Reference.Class = ACPI_REFCLASS_NAME;
-                if (Op->Common.Node)
-                {
-                    ObjDesc->Reference.Object = Op->Common.Node->Object;
-                }
-                break;
-
-            case AML_DEBUG_OP:
-
-                ObjDesc->Reference.Class = ACPI_REFCLASS_DEBUG;
-                break;
-
-            default:
-
-                ACPI_ERROR ((AE_INFO,
-                    "Unimplemented reference type for AML opcode: 0x%4.4X", Opcode));
-                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
-            }
-            break;
-        }
-        break;
-
-    default:
-
-        ACPI_ERROR ((AE_INFO, "Unimplemented data type: 0x%X",
-            ObjDesc->Common.Type));
-
-        Status = AE_AML_OPERAND_TYPE;
-        break;
-    }
-
-    return_ACPI_STATUS (Status);
-}

+ 0 - 840
h2o/localdep/acpica/dispatcher/dsopcode.c

@@ -1,840 +0,0 @@
-/******************************************************************************
- *
- * Module Name: dsopcode - Dispatcher support for regions and fields
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acparser.h"
-#include "amlcode.h"
-#include "acdispat.h"
-#include "acinterp.h"
-#include "acnamesp.h"
-#include "acevents.h"
-#include "actables.h"
-
-#define _COMPONENT          ACPI_DISPATCHER
-        ACPI_MODULE_NAME    ("dsopcode")
-
-/* Local prototypes */
-
-static ACPI_STATUS
-AcpiDsInitBufferField (
-    UINT16                  AmlOpcode,
-    ACPI_OPERAND_OBJECT     *ObjDesc,
-    ACPI_OPERAND_OBJECT     *BufferDesc,
-    ACPI_OPERAND_OBJECT     *OffsetDesc,
-    ACPI_OPERAND_OBJECT     *LengthDesc,
-    ACPI_OPERAND_OBJECT     *ResultDesc);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsInitializeRegion
- *
- * PARAMETERS:  ObjHandle       - Region namespace node
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Front end to EvInitializeRegion
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsInitializeRegion (
-    ACPI_HANDLE             ObjHandle)
-{
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_STATUS             Status;
-
-
-    ObjDesc = AcpiNsGetAttachedObject (ObjHandle);
-
-    /* Namespace is NOT locked */
-
-    Status = AcpiEvInitializeRegion (ObjDesc);
-    return (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsInitBufferField
- *
- * PARAMETERS:  AmlOpcode       - CreateXxxField
- *              ObjDesc         - BufferField object
- *              BufferDesc      - Host Buffer
- *              OffsetDesc      - Offset into buffer
- *              LengthDesc      - Length of field (CREATE_FIELD_OP only)
- *              ResultDesc      - Where to store the result
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Perform actual initialization of a buffer field
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiDsInitBufferField (
-    UINT16                  AmlOpcode,
-    ACPI_OPERAND_OBJECT     *ObjDesc,
-    ACPI_OPERAND_OBJECT     *BufferDesc,
-    ACPI_OPERAND_OBJECT     *OffsetDesc,
-    ACPI_OPERAND_OBJECT     *LengthDesc,
-    ACPI_OPERAND_OBJECT     *ResultDesc)
-{
-    UINT32                  Offset;
-    UINT32                  BitOffset;
-    UINT32                  BitCount;
-    UINT8                   FieldFlags;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsInitBufferField, ObjDesc);
-
-
-    /* Host object must be a Buffer */
-
-    if (BufferDesc->Common.Type != ACPI_TYPE_BUFFER)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "Target of Create Field is not a Buffer object - %s",
-            AcpiUtGetObjectTypeName (BufferDesc)));
-
-        Status = AE_AML_OPERAND_TYPE;
-        goto Cleanup;
-    }
-
-    /*
-     * The last parameter to all of these opcodes (ResultDesc) started
-     * out as a NameString, and should therefore now be a NS node
-     * after resolution in AcpiExResolveOperands().
-     */
-    if (ACPI_GET_DESCRIPTOR_TYPE (ResultDesc) != ACPI_DESC_TYPE_NAMED)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "(%s) destination not a NS Node [%s]",
-            AcpiPsGetOpcodeName (AmlOpcode),
-            AcpiUtGetDescriptorName (ResultDesc)));
-
-        Status = AE_AML_OPERAND_TYPE;
-        goto Cleanup;
-    }
-
-    Offset = (UINT32) OffsetDesc->Integer.Value;
-
-    /*
-     * Setup the Bit offsets and counts, according to the opcode
-     */
-    switch (AmlOpcode)
-    {
-    case AML_CREATE_FIELD_OP:
-
-        /* Offset is in bits, count is in bits */
-
-        FieldFlags = AML_FIELD_ACCESS_BYTE;
-        BitOffset  = Offset;
-        BitCount   = (UINT32) LengthDesc->Integer.Value;
-
-        /* Must have a valid (>0) bit count */
-
-        if (BitCount == 0)
-        {
-            ACPI_BIOS_ERROR ((AE_INFO,
-                "Attempt to CreateField of length zero"));
-            Status = AE_AML_OPERAND_VALUE;
-            goto Cleanup;
-        }
-        break;
-
-    case AML_CREATE_BIT_FIELD_OP:
-
-        /* Offset is in bits, Field is one bit */
-
-        BitOffset  = Offset;
-        BitCount   = 1;
-        FieldFlags = AML_FIELD_ACCESS_BYTE;
-        break;
-
-    case AML_CREATE_BYTE_FIELD_OP:
-
-        /* Offset is in bytes, field is one byte */
-
-        BitOffset  = 8 * Offset;
-        BitCount   = 8;
-        FieldFlags = AML_FIELD_ACCESS_BYTE;
-        break;
-
-    case AML_CREATE_WORD_FIELD_OP:
-
-        /* Offset is in bytes, field is one word */
-
-        BitOffset  = 8 * Offset;
-        BitCount   = 16;
-        FieldFlags = AML_FIELD_ACCESS_WORD;
-        break;
-
-    case AML_CREATE_DWORD_FIELD_OP:
-
-        /* Offset is in bytes, field is one dword */
-
-        BitOffset  = 8 * Offset;
-        BitCount   = 32;
-        FieldFlags = AML_FIELD_ACCESS_DWORD;
-        break;
-
-    case AML_CREATE_QWORD_FIELD_OP:
-
-        /* Offset is in bytes, field is one qword */
-
-        BitOffset  = 8 * Offset;
-        BitCount   = 64;
-        FieldFlags = AML_FIELD_ACCESS_QWORD;
-        break;
-
-    default:
-
-        ACPI_ERROR ((AE_INFO,
-            "Unknown field creation opcode 0x%02X",
-            AmlOpcode));
-        Status = AE_AML_BAD_OPCODE;
-        goto Cleanup;
-    }
-
-    /* Entire field must fit within the current length of the buffer */
-
-    if ((BitOffset + BitCount) >
-        (8 * (UINT32) BufferDesc->Buffer.Length))
-    {
-        Status = AE_AML_BUFFER_LIMIT;
-        ACPI_BIOS_EXCEPTION ((AE_INFO, Status,
-            "Field [%4.4s] at bit offset/length %u/%u "
-            "exceeds size of target Buffer (%u bits)",
-            AcpiUtGetNodeName (ResultDesc), BitOffset, BitCount,
-            8 * (UINT32) BufferDesc->Buffer.Length));
-        goto Cleanup;
-    }
-
-    /*
-     * Initialize areas of the field object that are common to all fields
-     * For FieldFlags, use LOCK_RULE = 0 (NO_LOCK),
-     * UPDATE_RULE = 0 (UPDATE_PRESERVE)
-     */
-    Status = AcpiExPrepCommonFieldObject (
-        ObjDesc, FieldFlags, 0, BitOffset, BitCount);
-    if (ACPI_FAILURE (Status))
-    {
-        goto Cleanup;
-    }
-
-    ObjDesc->BufferField.BufferObj = BufferDesc;
-
-    /* Reference count for BufferDesc inherits ObjDesc count */
-
-    BufferDesc->Common.ReferenceCount = (UINT16)
-        (BufferDesc->Common.ReferenceCount + ObjDesc->Common.ReferenceCount);
-
-
-Cleanup:
-
-    /* Always delete the operands */
-
-    AcpiUtRemoveReference (OffsetDesc);
-    AcpiUtRemoveReference (BufferDesc);
-
-    if (AmlOpcode == AML_CREATE_FIELD_OP)
-    {
-        AcpiUtRemoveReference (LengthDesc);
-    }
-
-    /* On failure, delete the result descriptor */
-
-    if (ACPI_FAILURE (Status))
-    {
-        AcpiUtRemoveReference (ResultDesc);     /* Result descriptor */
-    }
-    else
-    {
-        /* Now the address and length are valid for this BufferField */
-
-        ObjDesc->BufferField.Flags |= AOPOBJ_DATA_VALID;
-    }
-
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsEvalBufferFieldOperands
- *
- * PARAMETERS:  WalkState       - Current walk
- *              Op              - A valid BufferField Op object
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Get BufferField Buffer and Index
- *              Called from AcpiDsExecEndOp during BufferField parse tree walk
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsEvalBufferFieldOperands (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Op)
-{
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_PARSE_OBJECT       *NextOp;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsEvalBufferFieldOperands, Op);
-
-
-    /*
-     * This is where we evaluate the address and length fields of the
-     * CreateXxxField declaration
-     */
-    Node =  Op->Common.Node;
-
-    /* NextOp points to the op that holds the Buffer */
-
-    NextOp = Op->Common.Value.Arg;
-
-    /* Evaluate/create the address and length operands */
-
-    Status = AcpiDsCreateOperands (WalkState, NextOp);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    ObjDesc = AcpiNsGetAttachedObject (Node);
-    if (!ObjDesc)
-    {
-        return_ACPI_STATUS (AE_NOT_EXIST);
-    }
-
-    /* Resolve the operands */
-
-    Status = AcpiExResolveOperands (
-        Op->Common.AmlOpcode, ACPI_WALK_OPERANDS, WalkState);
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_ERROR ((AE_INFO, "(%s) bad operand(s), status 0x%X",
-            AcpiPsGetOpcodeName (Op->Common.AmlOpcode), Status));
-
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Initialize the Buffer Field */
-
-    if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
-    {
-        /* NOTE: Slightly different operands for this opcode */
-
-        Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
-            WalkState->Operands[0], WalkState->Operands[1],
-            WalkState->Operands[2], WalkState->Operands[3]);
-    }
-    else
-    {
-        /* All other, CreateXxxField opcodes */
-
-        Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
-            WalkState->Operands[0], WalkState->Operands[1],
-            NULL, WalkState->Operands[2]);
-    }
-
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsEvalRegionOperands
- *
- * PARAMETERS:  WalkState       - Current walk
- *              Op              - A valid region Op object
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Get region address and length
- *              Called from AcpiDsExecEndOp during OpRegion parse tree walk
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsEvalRegionOperands (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Op)
-{
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_OPERAND_OBJECT     *OperandDesc;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_PARSE_OBJECT       *NextOp;
-    ACPI_ADR_SPACE_TYPE     SpaceId;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsEvalRegionOperands, Op);
-
-
-    /*
-     * This is where we evaluate the address and length fields of the
-     * OpRegion declaration
-     */
-    Node = Op->Common.Node;
-
-    /* NextOp points to the op that holds the SpaceID */
-
-    NextOp = Op->Common.Value.Arg;
-    SpaceId = (ACPI_ADR_SPACE_TYPE) NextOp->Common.Value.Integer;
-
-    /* NextOp points to address op */
-
-    NextOp = NextOp->Common.Next;
-
-    /* Evaluate/create the address and length operands */
-
-    Status = AcpiDsCreateOperands (WalkState, NextOp);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Resolve the length and address operands to numbers */
-
-    Status = AcpiExResolveOperands (
-        Op->Common.AmlOpcode, ACPI_WALK_OPERANDS, WalkState);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    ObjDesc = AcpiNsGetAttachedObject (Node);
-    if (!ObjDesc)
-    {
-        return_ACPI_STATUS (AE_NOT_EXIST);
-    }
-
-    /*
-     * Get the length operand and save it
-     * (at Top of stack)
-     */
-    OperandDesc = WalkState->Operands[WalkState->NumOperands - 1];
-
-    ObjDesc->Region.Length = (UINT32) OperandDesc->Integer.Value;
-    AcpiUtRemoveReference (OperandDesc);
-
-    /* A zero-length operation region is unusable. Just warn */
-
-    if (!ObjDesc->Region.Length && (SpaceId < ACPI_NUM_PREDEFINED_REGIONS))
-    {
-        ACPI_WARNING ((AE_INFO,
-            "Operation Region [%4.4s] has zero length (SpaceId %X)",
-            Node->Name.Ascii, SpaceId));
-    }
-
-    /*
-     * Get the address and save it
-     * (at top of stack - 1)
-     */
-    OperandDesc = WalkState->Operands[WalkState->NumOperands - 2];
-
-    ObjDesc->Region.Address = (ACPI_PHYSICAL_ADDRESS)
-        OperandDesc->Integer.Value;
-    AcpiUtRemoveReference (OperandDesc);
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
-        ObjDesc, ACPI_FORMAT_UINT64 (ObjDesc->Region.Address),
-        ObjDesc->Region.Length));
-
-    Status = AcpiUtAddAddressRange (ObjDesc->Region.SpaceId,
-        ObjDesc->Region.Address, ObjDesc->Region.Length, Node);
-
-    /* Now the address and length are valid for this opregion */
-
-    ObjDesc->Region.Flags |= AOPOBJ_DATA_VALID;
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsEvalTableRegionOperands
- *
- * PARAMETERS:  WalkState       - Current walk
- *              Op              - A valid region Op object
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Get region address and length.
- *              Called from AcpiDsExecEndOp during DataTableRegion parse
- *              tree walk.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsEvalTableRegionOperands (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Op)
-{
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_OPERAND_OBJECT     **Operand;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_PARSE_OBJECT       *NextOp;
-    ACPI_TABLE_HEADER       *Table;
-    UINT32                  TableIndex;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsEvalTableRegionOperands, Op);
-
-
-    /*
-     * This is where we evaluate the Signature string, OemId string,
-     * and OemTableId string of the Data Table Region declaration
-     */
-    Node =  Op->Common.Node;
-
-    /* NextOp points to Signature string op */
-
-    NextOp = Op->Common.Value.Arg;
-
-    /*
-     * Evaluate/create the Signature string, OemId string,
-     * and OemTableId string operands
-     */
-    Status = AcpiDsCreateOperands (WalkState, NextOp);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    Operand = &WalkState->Operands[0];
-
-    /*
-     * Resolve the Signature string, OemId string,
-     * and OemTableId string operands
-     */
-    Status = AcpiExResolveOperands (
-        Op->Common.AmlOpcode, ACPI_WALK_OPERANDS, WalkState);
-    if (ACPI_FAILURE (Status))
-    {
-        goto Cleanup;
-    }
-
-    /* Find the ACPI table */
-
-    Status = AcpiTbFindTable (
-        Operand[0]->String.Pointer,
-        Operand[1]->String.Pointer,
-        Operand[2]->String.Pointer, &TableIndex);
-    if (ACPI_FAILURE (Status))
-    {
-        if (Status == AE_NOT_FOUND)
-        {
-            ACPI_ERROR ((AE_INFO,
-                "ACPI Table [%4.4s] OEM:(%s, %s) not found in RSDT/XSDT",
-                Operand[0]->String.Pointer,
-                Operand[1]->String.Pointer,
-                Operand[2]->String.Pointer));
-        }
-        goto Cleanup;
-    }
-
-    Status = AcpiGetTableByIndex (TableIndex, &Table);
-    if (ACPI_FAILURE (Status))
-    {
-        goto Cleanup;
-    }
-
-    ObjDesc = AcpiNsGetAttachedObject (Node);
-    if (!ObjDesc)
-    {
-        Status = AE_NOT_EXIST;
-        goto Cleanup;
-    }
-
-    ObjDesc->Region.Address = ACPI_PTR_TO_PHYSADDR (Table);
-    ObjDesc->Region.Length = Table->Length;
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
-        ObjDesc, ACPI_FORMAT_UINT64 (ObjDesc->Region.Address),
-        ObjDesc->Region.Length));
-
-    /* Now the address and length are valid for this opregion */
-
-    ObjDesc->Region.Flags |= AOPOBJ_DATA_VALID;
-
-Cleanup:
-    AcpiUtRemoveReference (Operand[0]);
-    AcpiUtRemoveReference (Operand[1]);
-    AcpiUtRemoveReference (Operand[2]);
-
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsEvalDataObjectOperands
- *
- * PARAMETERS:  WalkState       - Current walk
- *              Op              - A valid DataObject Op object
- *              ObjDesc         - DataObject
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Get the operands and complete the following data object types:
- *              Buffer, Package.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsEvalDataObjectOperands (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Op,
-    ACPI_OPERAND_OBJECT     *ObjDesc)
-{
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     *ArgDesc;
-    UINT32                  Length;
-
-
-    ACPI_FUNCTION_TRACE (DsEvalDataObjectOperands);
-
-
-    /* The first operand (for all of these data objects) is the length */
-
-    /*
-     * Set proper index into operand stack for AcpiDsObjStackPush
-     * invoked inside AcpiDsCreateOperand.
-     */
-    WalkState->OperandIndex = WalkState->NumOperands;
-
-    /* Ignore if child is not valid */
-
-    if (!Op->Common.Value.Arg)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "Missing child while evaluating opcode %4.4X, Op %p",
-            Op->Common.AmlOpcode, Op));
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    Status = AcpiDsCreateOperand (WalkState, Op->Common.Value.Arg, 1);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    Status = AcpiExResolveOperands (WalkState->Opcode,
-        &(WalkState->Operands [WalkState->NumOperands -1]),
-        WalkState);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Extract length operand */
-
-    ArgDesc = WalkState->Operands [WalkState->NumOperands - 1];
-    Length = (UINT32) ArgDesc->Integer.Value;
-
-    /* Cleanup for length operand */
-
-    Status = AcpiDsObjStackPop (1, WalkState);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    AcpiUtRemoveReference (ArgDesc);
-
-    /*
-     * Create the actual data object
-     */
-    switch (Op->Common.AmlOpcode)
-    {
-    case AML_BUFFER_OP:
-
-        Status = AcpiDsBuildInternalBufferObj (
-            WalkState, Op, Length, &ObjDesc);
-        break;
-
-    case AML_PACKAGE_OP:
-    case AML_VARIABLE_PACKAGE_OP:
-
-        Status = AcpiDsBuildInternalPackageObj (
-            WalkState, Op, Length, &ObjDesc);
-        break;
-
-    default:
-
-        return_ACPI_STATUS (AE_AML_BAD_OPCODE);
-    }
-
-    if (ACPI_SUCCESS (Status))
-    {
-        /*
-         * Return the object in the WalkState, unless the parent is a package -
-         * in this case, the return object will be stored in the parse tree
-         * for the package.
-         */
-        if ((!Op->Common.Parent) ||
-            ((Op->Common.Parent->Common.AmlOpcode != AML_PACKAGE_OP) &&
-             (Op->Common.Parent->Common.AmlOpcode != AML_VARIABLE_PACKAGE_OP) &&
-             (Op->Common.Parent->Common.AmlOpcode != AML_NAME_OP)))
-        {
-            WalkState->ResultObj = ObjDesc;
-        }
-    }
-
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsEvalBankFieldOperands
- *
- * PARAMETERS:  WalkState       - Current walk
- *              Op              - A valid BankField Op object
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Get BankField BankValue
- *              Called from AcpiDsExecEndOp during BankField parse tree walk
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsEvalBankFieldOperands (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Op)
-{
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_OPERAND_OBJECT     *OperandDesc;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_PARSE_OBJECT       *NextOp;
-    ACPI_PARSE_OBJECT       *Arg;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsEvalBankFieldOperands, Op);
-
-
-    /*
-     * This is where we evaluate the BankValue field of the
-     * BankField declaration
-     */
-
-    /* NextOp points to the op that holds the Region */
-
-    NextOp = Op->Common.Value.Arg;
-
-    /* NextOp points to the op that holds the Bank Register */
-
-    NextOp = NextOp->Common.Next;
-
-    /* NextOp points to the op that holds the Bank Value */
-
-    NextOp = NextOp->Common.Next;
-
-    /*
-     * Set proper index into operand stack for AcpiDsObjStackPush
-     * invoked inside AcpiDsCreateOperand.
-     *
-     * We use WalkState->Operands[0] to store the evaluated BankValue
-     */
-    WalkState->OperandIndex = 0;
-
-    Status = AcpiDsCreateOperand (WalkState, NextOp, 0);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    Status = AcpiExResolveToValue (&WalkState->Operands[0], WalkState);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS,
-        AcpiPsGetOpcodeName (Op->Common.AmlOpcode), 1);
-    /*
-     * Get the BankValue operand and save it
-     * (at Top of stack)
-     */
-    OperandDesc = WalkState->Operands[0];
-
-    /* Arg points to the start Bank Field */
-
-    Arg = AcpiPsGetArg (Op, 4);
-    while (Arg)
-    {
-        /* Ignore OFFSET and ACCESSAS terms here */
-
-        if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
-        {
-            Node = Arg->Common.Node;
-
-            ObjDesc = AcpiNsGetAttachedObject (Node);
-            if (!ObjDesc)
-            {
-                return_ACPI_STATUS (AE_NOT_EXIST);
-            }
-
-            ObjDesc->BankField.Value = (UINT32) OperandDesc->Integer.Value;
-        }
-
-        /* Move to next field in the list */
-
-        Arg = Arg->Common.Next;
-    }
-
-    AcpiUtRemoveReference (OperandDesc);
-    return_ACPI_STATUS (Status);
-}

+ 0 - 594
h2o/localdep/acpica/dispatcher/dspkginit.c

@@ -1,594 +0,0 @@
-/******************************************************************************
- *
- * Module Name: dspkginit - Completion of deferred package initialization
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acnamesp.h"
-#include "amlcode.h"
-#include "acdispat.h"
-#include "acinterp.h"
-#include "acparser.h"
-
-
-#define _COMPONENT          ACPI_NAMESPACE
-        ACPI_MODULE_NAME    ("dspkginit")
-
-
-/* Local prototypes */
-
-static void
-AcpiDsResolvePackageElement (
-    ACPI_OPERAND_OBJECT     **Element);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsBuildInternalPackageObj
- *
- * PARAMETERS:  WalkState       - Current walk state
- *              Op              - Parser object to be translated
- *              ElementCount    - Number of elements in the package - this is
- *                                the NumElements argument to Package()
- *              ObjDescPtr      - Where the ACPI internal object is returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Translate a parser Op package object to the equivalent
- *              namespace object
- *
- * NOTE: The number of elements in the package will be always be the NumElements
- * count, regardless of the number of elements in the package list. If
- * NumElements is smaller, only that many package list elements are used.
- * if NumElements is larger, the Package object is padded out with
- * objects of type Uninitialized (as per ACPI spec.)
- *
- * Even though the ASL compilers do not allow NumElements to be smaller
- * than the Package list length (for the fixed length package opcode), some
- * BIOS code modifies the AML on the fly to adjust the NumElements, and
- * this code compensates for that. This also provides compatibility with
- * other AML interpreters.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsBuildInternalPackageObj (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Op,
-    UINT32                  ElementCount,
-    ACPI_OPERAND_OBJECT     **ObjDescPtr)
-{
-    ACPI_PARSE_OBJECT       *Arg;
-    ACPI_PARSE_OBJECT       *Parent;
-    ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
-    ACPI_STATUS             Status = AE_OK;
-    BOOLEAN                 ModuleLevelCode = FALSE;
-    UINT16                  ReferenceCount;
-    UINT32                  Index;
-    UINT32                  i;
-
-
-    ACPI_FUNCTION_TRACE (DsBuildInternalPackageObj);
-
-
-    /* Check if we are executing module level code */
-
-    if (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL)
-    {
-        ModuleLevelCode = TRUE;
-    }
-
-    /* Find the parent of a possibly nested package */
-
-    Parent = Op->Common.Parent;
-    while ((Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
-           (Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP))
-    {
-        Parent = Parent->Common.Parent;
-    }
-
-    /*
-     * If we are evaluating a Named package object of the form:
-     *      Name (xxxx, Package)
-     * the package object already exists, otherwise it must be created.
-     */
-    ObjDesc = *ObjDescPtr;
-    if (!ObjDesc)
-    {
-        ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
-        *ObjDescPtr = ObjDesc;
-        if (!ObjDesc)
-        {
-            return_ACPI_STATUS (AE_NO_MEMORY);
-        }
-
-        ObjDesc->Package.Node = Parent->Common.Node;
-    }
-
-    if (ObjDesc->Package.Flags & AOPOBJ_DATA_VALID) /* Just in case */
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /*
-     * Allocate the element array (array of pointers to the individual
-     * objects) if necessary. the count is based on the NumElements
-     * parameter. Add an extra pointer slot so that the list is always
-     * null terminated.
-     */
-    if (!ObjDesc->Package.Elements)
-    {
-        ObjDesc->Package.Elements = ACPI_ALLOCATE_ZEROED (
-            ((ACPI_SIZE) ElementCount + 1) * sizeof (void *));
-
-        if (!ObjDesc->Package.Elements)
-        {
-            AcpiUtDeleteObjectDesc (ObjDesc);
-            return_ACPI_STATUS (AE_NO_MEMORY);
-        }
-
-        ObjDesc->Package.Count = ElementCount;
-    }
-
-    /* First arg is element count. Second arg begins the initializer list */
-
-    Arg = Op->Common.Value.Arg;
-    Arg = Arg->Common.Next;
-
-    /*
-     * If we are executing module-level code, we will defer the
-     * full resolution of the package elements in order to support
-     * forward references from the elements. This provides
-     * compatibility with other ACPI implementations.
-     */
-    if (ModuleLevelCode)
-    {
-        ObjDesc->Package.AmlStart = WalkState->Aml;
-        ObjDesc->Package.AmlLength = 0;
-
-        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_PARSE,
-            "%s: Deferring resolution of Package elements\n",
-            ACPI_GET_FUNCTION_NAME));
-    }
-
-    /*
-     * Initialize the elements of the package, up to the NumElements count.
-     * Package is automatically padded with uninitialized (NULL) elements
-     * if NumElements is greater than the package list length. Likewise,
-     * Package is truncated if NumElements is less than the list length.
-     */
-    for (i = 0; Arg && (i < ElementCount); i++)
-    {
-        if (Arg->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP)
-        {
-            if (!Arg->Common.Node)
-            {
-                /*
-                 * This is the case where an expression has returned a value.
-                 * The use of expressions (TermArgs) within individual
-                 * package elements is not supported by the AML interpreter,
-                 * even though the ASL grammar supports it. Example:
-                 *
-                 *      Name (INT1, 0x1234)
-                 *
-                 *      Name (PKG3, Package () {
-                 *          Add (INT1, 0xAAAA0000)
-                 *      })
-                 *
-                 *  1) No known AML interpreter supports this type of construct
-                 *  2) This fixes a fault if the construct is encountered
-                 */
-                ACPI_EXCEPTION ((AE_INFO, AE_SUPPORT,
-                    "Expressions within package elements are not supported"));
-
-                /* Cleanup the return object, it is not needed */
-
-                AcpiUtRemoveReference (WalkState->Results->Results.ObjDesc[0]);
-                return_ACPI_STATUS (AE_SUPPORT);
-            }
-
-            if (Arg->Common.Node->Type == ACPI_TYPE_METHOD)
-            {
-                /*
-                 * A method reference "looks" to the parser to be a method
-                 * invocation, so we special case it here
-                 */
-                Arg->Common.AmlOpcode = AML_INT_NAMEPATH_OP;
-                Status = AcpiDsBuildInternalObject (
-                    WalkState, Arg, &ObjDesc->Package.Elements[i]);
-            }
-            else
-            {
-                /* This package element is already built, just get it */
-
-                ObjDesc->Package.Elements[i] =
-                    ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node);
-            }
-        }
-        else
-        {
-            Status = AcpiDsBuildInternalObject (
-                WalkState, Arg, &ObjDesc->Package.Elements[i]);
-            if (Status == AE_NOT_FOUND)
-            {
-                ACPI_ERROR ((AE_INFO, "%-48s", "****DS namepath not found"));
-            }
-
-            if (!ModuleLevelCode)
-            {
-                /*
-                 * Initialize this package element. This function handles the
-                 * resolution of named references within the package.
-                 * Forward references from module-level code are deferred
-                 * until all ACPI tables are loaded.
-                 */
-                AcpiDsInitPackageElement (0, ObjDesc->Package.Elements[i],
-                    NULL, &ObjDesc->Package.Elements[i]);
-            }
-        }
-
-        if (*ObjDescPtr)
-        {
-            /* Existing package, get existing reference count */
-
-            ReferenceCount = (*ObjDescPtr)->Common.ReferenceCount;
-            if (ReferenceCount > 1)
-            {
-                /* Make new element ref count match original ref count */
-                /* TBD: Probably need an AcpiUtAddReferences function */
-
-                for (Index = 0; Index < ((UINT32) ReferenceCount - 1); Index++)
-                {
-                    AcpiUtAddReference ((ObjDesc->Package.Elements[i]));
-                }
-            }
-        }
-
-        Arg = Arg->Common.Next;
-    }
-
-    /* Check for match between NumElements and actual length of PackageList */
-
-    if (Arg)
-    {
-        /*
-         * NumElements was exhausted, but there are remaining elements in
-         * the PackageList. Truncate the package to NumElements.
-         *
-         * Note: technically, this is an error, from ACPI spec: "It is an
-         * error for NumElements to be less than the number of elements in
-         * the PackageList". However, we just print a message and no
-         * exception is returned. This provides compatibility with other
-         * ACPI implementations. Some firmware implementations will alter
-         * the NumElements on the fly, possibly creating this type of
-         * ill-formed package object.
-         */
-        while (Arg)
-        {
-            /*
-             * We must delete any package elements that were created earlier
-             * and are not going to be used because of the package truncation.
-             */
-            if (Arg->Common.Node)
-            {
-                AcpiUtRemoveReference (
-                    ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node));
-                Arg->Common.Node = NULL;
-            }
-
-            /* Find out how many elements there really are */
-
-            i++;
-            Arg = Arg->Common.Next;
-        }
-
-        ACPI_INFO ((
-            "Actual Package length (%u) is larger than "
-            "NumElements field (%u), truncated",
-            i, ElementCount));
-    }
-    else if (i < ElementCount)
-    {
-        /*
-         * Arg list (elements) was exhausted, but we did not reach
-         * NumElements count.
-         *
-         * Note: this is not an error, the package is padded out
-         * with NULLs as per the ACPI specification.
-         */
-        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO,
-            "%s: Package List length (%u) smaller than NumElements "
-            "count (%u), padded with null elements\n",
-            ACPI_GET_FUNCTION_NAME, i, ElementCount));
-    }
-
-    /* Module-level packages will be resolved later */
-
-    if (!ModuleLevelCode)
-    {
-        ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
-    }
-
-    Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsInitPackageElement
- *
- * PARAMETERS:  ACPI_PKG_CALLBACK
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Resolve a named reference element within a package object
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsInitPackageElement (
-    UINT8                   ObjectType,
-    ACPI_OPERAND_OBJECT     *SourceObject,
-    ACPI_GENERIC_STATE      *State,
-    void                    *Context)
-{
-    ACPI_OPERAND_OBJECT     **ElementPtr;
-
-
-    ACPI_FUNCTION_TRACE (DsInitPackageElement);
-
-
-    if (!SourceObject)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /*
-     * The following code is a bit of a hack to workaround a (current)
-     * limitation of the ACPI_PKG_CALLBACK interface. We need a pointer
-     * to the location within the element array because a new object
-     * may be created and stored there.
-     */
-    if (Context)
-    {
-        /* A direct call was made to this function */
-
-        ElementPtr = (ACPI_OPERAND_OBJECT **) Context;
-    }
-    else
-    {
-        /* Call came from AcpiUtWalkPackageTree */
-
-        ElementPtr = State->Pkg.ThisTargetObj;
-    }
-
-    /* We are only interested in reference objects/elements */
-
-    if (SourceObject->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
-    {
-        /* Attempt to resolve the (named) reference to a namespace node */
-
-        AcpiDsResolvePackageElement (ElementPtr);
-    }
-    else if (SourceObject->Common.Type == ACPI_TYPE_PACKAGE)
-    {
-        SourceObject->Package.Flags |= AOPOBJ_DATA_VALID;
-    }
-
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsResolvePackageElement
- *
- * PARAMETERS:  ElementPtr          - Pointer to a reference object
- *
- * RETURN:      Possible new element is stored to the indirect ElementPtr
- *
- * DESCRIPTION: Resolve a package element that is a reference to a named
- *              object.
- *
- ******************************************************************************/
-
-static void
-AcpiDsResolvePackageElement (
-    ACPI_OPERAND_OBJECT     **ElementPtr)
-{
-    ACPI_STATUS             Status;
-    ACPI_STATUS             Status2;
-    ACPI_GENERIC_STATE      ScopeInfo;
-    ACPI_OPERAND_OBJECT     *Element = *ElementPtr;
-    ACPI_NAMESPACE_NODE     *ResolvedNode;
-    ACPI_NAMESPACE_NODE     *OriginalNode;
-    char                    *ExternalPath = "";
-    ACPI_OBJECT_TYPE        Type;
-
-
-    ACPI_FUNCTION_TRACE (DsResolvePackageElement);
-
-
-    /* Check if reference element is already resolved */
-
-    if (Element->Reference.Resolved)
-    {
-        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_PARSE,
-            "%s: Package element is already resolved\n",
-            ACPI_GET_FUNCTION_NAME));
-
-        return_VOID;
-    }
-
-    /* Element must be a reference object of correct type */
-
-    ScopeInfo.Scope.Node = Element->Reference.Node; /* Prefix node */
-
-    Status = AcpiNsLookup (&ScopeInfo, (char *) Element->Reference.Aml,
-        ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
-        ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
-        NULL, &ResolvedNode);
-    if (ACPI_FAILURE (Status))
-    {
-        if ((Status == AE_NOT_FOUND) && AcpiGbl_IgnorePackageResolutionErrors)
-        {
-            /*
-             * Optionally be silent about the NOT_FOUND case for the referenced
-             * name. Although this is potentially a serious problem,
-             * it can generate a lot of noise/errors on platforms whose
-             * firmware carries around a bunch of unused Package objects.
-             * To disable these errors, set this global to TRUE:
-             *     AcpiGbl_IgnorePackageResolutionErrors
-             *
-             * If the AML actually tries to use such a package, the unresolved
-             * element(s) will be replaced with NULL elements.
-             */
-
-            /* Referenced name not found, set the element to NULL */
-
-            AcpiUtRemoveReference (*ElementPtr);
-            *ElementPtr = NULL;
-            return_VOID;
-        }
-
-        Status2 = AcpiNsExternalizeName (ACPI_UINT32_MAX,
-            (char *) Element->Reference.Aml, NULL, &ExternalPath);
-
-        ACPI_EXCEPTION ((AE_INFO, Status,
-            "While resolving a named reference package element - %s",
-            ExternalPath));
-        if (ACPI_SUCCESS (Status2))
-        {
-            ACPI_FREE (ExternalPath);
-        }
-
-        /* Could not resolve name, set the element to NULL */
-
-        AcpiUtRemoveReference (*ElementPtr);
-        *ElementPtr = NULL;
-        return_VOID;
-    }
-    else if (ResolvedNode->Type == ACPI_TYPE_ANY)
-    {
-        /* Named reference not resolved, return a NULL package element */
-
-        ACPI_ERROR ((AE_INFO,
-            "Could not resolve named package element [%4.4s] in [%4.4s]",
-            ResolvedNode->Name.Ascii, ScopeInfo.Scope.Node->Name.Ascii));
-        *ElementPtr = NULL;
-        return_VOID;
-    }
-
-    /*
-     * Special handling for Alias objects. We need ResolvedNode to point
-     * to the Alias target. This effectively "resolves" the alias.
-     */
-    if (ResolvedNode->Type == ACPI_TYPE_LOCAL_ALIAS)
-    {
-        ResolvedNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
-            ResolvedNode->Object);
-    }
-
-    /* Update the reference object */
-
-    Element->Reference.Resolved = TRUE;
-    Element->Reference.Node = ResolvedNode;
-    Type = Element->Reference.Node->Type;
-
-    /*
-     * Attempt to resolve the node to a value before we insert it into
-     * the package. If this is a reference to a common data type,
-     * resolve it immediately. According to the ACPI spec, package
-     * elements can only be "data objects" or method references.
-     * Attempt to resolve to an Integer, Buffer, String or Package.
-     * If cannot, return the named reference (for things like Devices,
-     * Methods, etc.) Buffer Fields and Fields will resolve to simple
-     * objects (int/buf/str/pkg).
-     *
-     * NOTE: References to things like Devices, Methods, Mutexes, etc.
-     * will remain as named references. This behavior is not described
-     * in the ACPI spec, but it appears to be an oversight.
-     */
-    OriginalNode = ResolvedNode;
-    Status = AcpiExResolveNodeToValue (&ResolvedNode, NULL);
-    if (ACPI_FAILURE (Status))
-    {
-        return_VOID;
-    }
-
-    switch (Type)
-    {
-    /*
-     * These object types are a result of named references, so we will
-     * leave them as reference objects. In other words, these types
-     * have no intrinsic "value".
-     */
-    case ACPI_TYPE_DEVICE:
-    case ACPI_TYPE_THERMAL:
-    case ACPI_TYPE_METHOD:
-        break;
-
-    case ACPI_TYPE_MUTEX:
-    case ACPI_TYPE_POWER:
-    case ACPI_TYPE_PROCESSOR:
-    case ACPI_TYPE_EVENT:
-    case ACPI_TYPE_REGION:
-
-        /* AcpiExResolveNodeToValue gave these an extra reference */
-
-        AcpiUtRemoveReference (OriginalNode->Object);
-        break;
-
-    default:
-        /*
-         * For all other types - the node was resolved to an actual
-         * operand object with a value, return the object. Remove
-         * a reference on the existing object.
-         */
-        AcpiUtRemoveReference (Element);
-        *ElementPtr = (ACPI_OPERAND_OBJECT *) ResolvedNode;
-        break;
-    }
-
-    return_VOID;
-}

+ 0 - 940
h2o/localdep/acpica/dispatcher/dsutils.c

@@ -1,940 +0,0 @@
-/*******************************************************************************
- *
- * Module Name: dsutils - Dispatcher utilities
- *
- ******************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acparser.h"
-#include "amlcode.h"
-#include "acdispat.h"
-#include "acinterp.h"
-#include "acnamesp.h"
-#include "acdebug.h"
-
-#define _COMPONENT          ACPI_DISPATCHER
-        ACPI_MODULE_NAME    ("dsutils")
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsClearImplicitReturn
- *
- * PARAMETERS:  WalkState           - Current State
- *
- * RETURN:      None.
- *
- * DESCRIPTION: Clear and remove a reference on an implicit return value. Used
- *              to delete "stale" return values (if enabled, the return value
- *              from every operator is saved at least momentarily, in case the
- *              parent method exits.)
- *
- ******************************************************************************/
-
-void
-AcpiDsClearImplicitReturn (
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_FUNCTION_NAME (DsClearImplicitReturn);
-
-
-    /*
-     * Slack must be enabled for this feature
-     */
-    if (!AcpiGbl_EnableInterpreterSlack)
-    {
-        return;
-    }
-
-    if (WalkState->ImplicitReturnObj)
-    {
-        /*
-         * Delete any "stale" implicit return. However, in
-         * complex statements, the implicit return value can be
-         * bubbled up several levels.
-         */
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-            "Removing reference on stale implicit return obj %p\n",
-            WalkState->ImplicitReturnObj));
-
-        AcpiUtRemoveReference (WalkState->ImplicitReturnObj);
-        WalkState->ImplicitReturnObj = NULL;
-    }
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsDoImplicitReturn
- *
- * PARAMETERS:  ReturnDesc          - The return value
- *              WalkState           - Current State
- *              AddReference        - True if a reference should be added to the
- *                                    return object
- *
- * RETURN:      TRUE if implicit return enabled, FALSE otherwise
- *
- * DESCRIPTION: Implements the optional "implicit return".  We save the result
- *              of every ASL operator and control method invocation in case the
- *              parent method exit. Before storing a new return value, we
- *              delete the previous return value.
- *
- ******************************************************************************/
-
-BOOLEAN
-AcpiDsDoImplicitReturn (
-    ACPI_OPERAND_OBJECT     *ReturnDesc,
-    ACPI_WALK_STATE         *WalkState,
-    BOOLEAN                 AddReference)
-{
-    ACPI_FUNCTION_NAME (DsDoImplicitReturn);
-
-
-    /*
-     * Slack must be enabled for this feature, and we must
-     * have a valid return object
-     */
-    if ((!AcpiGbl_EnableInterpreterSlack) ||
-        (!ReturnDesc))
-    {
-        return (FALSE);
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-        "Result %p will be implicitly returned; Prev=%p\n",
-        ReturnDesc,
-        WalkState->ImplicitReturnObj));
-
-    /*
-     * Delete any "stale" implicit return value first. However, in
-     * complex statements, the implicit return value can be
-     * bubbled up several levels, so we don't clear the value if it
-     * is the same as the ReturnDesc.
-     */
-    if (WalkState->ImplicitReturnObj)
-    {
-        if (WalkState->ImplicitReturnObj == ReturnDesc)
-        {
-            return (TRUE);
-        }
-        AcpiDsClearImplicitReturn (WalkState);
-    }
-
-    /* Save the implicit return value, add a reference if requested */
-
-    WalkState->ImplicitReturnObj = ReturnDesc;
-    if (AddReference)
-    {
-        AcpiUtAddReference (ReturnDesc);
-    }
-
-    return (TRUE);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsIsResultUsed
- *
- * PARAMETERS:  Op                  - Current Op
- *              WalkState           - Current State
- *
- * RETURN:      TRUE if result is used, FALSE otherwise
- *
- * DESCRIPTION: Check if a result object will be used by the parent
- *
- ******************************************************************************/
-
-BOOLEAN
-AcpiDsIsResultUsed (
-    ACPI_PARSE_OBJECT       *Op,
-    ACPI_WALK_STATE         *WalkState)
-{
-    const ACPI_OPCODE_INFO  *ParentInfo;
-
-    ACPI_FUNCTION_TRACE_PTR (DsIsResultUsed, Op);
-
-
-    /* Must have both an Op and a Result Object */
-
-    if (!Op)
-    {
-        ACPI_ERROR ((AE_INFO, "Null Op"));
-        return_UINT8 (TRUE);
-    }
-
-    /*
-     * We know that this operator is not a
-     * Return() operator (would not come here.) The following code is the
-     * optional support for a so-called "implicit return". Some AML code
-     * assumes that the last value of the method is "implicitly" returned
-     * to the caller. Just save the last result as the return value.
-     * NOTE: this is optional because the ASL language does not actually
-     * support this behavior.
-     */
-    (void) AcpiDsDoImplicitReturn (WalkState->ResultObj, WalkState, TRUE);
-
-    /*
-     * Now determine if the parent will use the result
-     *
-     * If there is no parent, or the parent is a ScopeOp, we are executing
-     * at the method level. An executing method typically has no parent,
-     * since each method is parsed separately. A method invoked externally
-     * via ExecuteControlMethod has a ScopeOp as the parent.
-     */
-    if ((!Op->Common.Parent) ||
-        (Op->Common.Parent->Common.AmlOpcode == AML_SCOPE_OP))
-    {
-        /* No parent, the return value cannot possibly be used */
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-            "At Method level, result of [%s] not used\n",
-            AcpiPsGetOpcodeName (Op->Common.AmlOpcode)));
-        return_UINT8 (FALSE);
-    }
-
-    /* Get info on the parent. The RootOp is AML_SCOPE */
-
-    ParentInfo = AcpiPsGetOpcodeInfo (Op->Common.Parent->Common.AmlOpcode);
-    if (ParentInfo->Class == AML_CLASS_UNKNOWN)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "Unknown parent opcode Op=%p", Op));
-        return_UINT8 (FALSE);
-    }
-
-    /*
-     * Decide what to do with the result based on the parent. If
-     * the parent opcode will not use the result, delete the object.
-     * Otherwise leave it as is, it will be deleted when it is used
-     * as an operand later.
-     */
-    switch (ParentInfo->Class)
-    {
-    case AML_CLASS_CONTROL:
-
-        switch (Op->Common.Parent->Common.AmlOpcode)
-        {
-        case AML_RETURN_OP:
-
-            /* Never delete the return value associated with a return opcode */
-
-            goto ResultUsed;
-
-        case AML_IF_OP:
-        case AML_WHILE_OP:
-            /*
-             * If we are executing the predicate AND this is the predicate op,
-             * we will use the return value
-             */
-            if ((WalkState->ControlState->Common.State ==
-                    ACPI_CONTROL_PREDICATE_EXECUTING) &&
-                (WalkState->ControlState->Control.PredicateOp == Op))
-            {
-                goto ResultUsed;
-            }
-            break;
-
-        default:
-
-            /* Ignore other control opcodes */
-
-            break;
-        }
-
-        /* The general control opcode returns no result */
-
-        goto ResultNotUsed;
-
-    case AML_CLASS_CREATE:
-        /*
-         * These opcodes allow TermArg(s) as operands and therefore
-         * the operands can be method calls. The result is used.
-         */
-        goto ResultUsed;
-
-    case AML_CLASS_NAMED_OBJECT:
-
-        if ((Op->Common.Parent->Common.AmlOpcode == AML_REGION_OP)       ||
-            (Op->Common.Parent->Common.AmlOpcode == AML_DATA_REGION_OP)  ||
-            (Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP)      ||
-            (Op->Common.Parent->Common.AmlOpcode == AML_BUFFER_OP)       ||
-            (Op->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP) ||
-            (Op->Common.Parent->Common.AmlOpcode == AML_INT_EVAL_SUBTREE_OP) ||
-            (Op->Common.Parent->Common.AmlOpcode == AML_BANK_FIELD_OP))
-        {
-            /*
-             * These opcodes allow TermArg(s) as operands and therefore
-             * the operands can be method calls. The result is used.
-             */
-            goto ResultUsed;
-        }
-
-        goto ResultNotUsed;
-
-    default:
-        /*
-         * In all other cases. the parent will actually use the return
-         * object, so keep it.
-         */
-        goto ResultUsed;
-    }
-
-
-ResultUsed:
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-        "Result of [%s] used by Parent [%s] Op=%p\n",
-        AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
-        AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode), Op));
-
-    return_UINT8 (TRUE);
-
-
-ResultNotUsed:
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-        "Result of [%s] not used by Parent [%s] Op=%p\n",
-        AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
-        AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode), Op));
-
-    return_UINT8 (FALSE);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsDeleteResultIfNotUsed
- *
- * PARAMETERS:  Op              - Current parse Op
- *              ResultObj       - Result of the operation
- *              WalkState       - Current state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Used after interpretation of an opcode. If there is an internal
- *              result descriptor, check if the parent opcode will actually use
- *              this result. If not, delete the result now so that it will
- *              not become orphaned.
- *
- ******************************************************************************/
-
-void
-AcpiDsDeleteResultIfNotUsed (
-    ACPI_PARSE_OBJECT       *Op,
-    ACPI_OPERAND_OBJECT     *ResultObj,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsDeleteResultIfNotUsed, ResultObj);
-
-
-    if (!Op)
-    {
-        ACPI_ERROR ((AE_INFO, "Null Op"));
-        return_VOID;
-    }
-
-    if (!ResultObj)
-    {
-        return_VOID;
-    }
-
-    if (!AcpiDsIsResultUsed (Op, WalkState))
-    {
-        /* Must pop the result stack (ObjDesc should be equal to ResultObj) */
-
-        Status = AcpiDsResultPop (&ObjDesc, WalkState);
-        if (ACPI_SUCCESS (Status))
-        {
-            AcpiUtRemoveReference (ResultObj);
-        }
-    }
-
-    return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsResolveOperands
- *
- * PARAMETERS:  WalkState           - Current walk state with operands on stack
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Resolve all operands to their values. Used to prepare
- *              arguments to a control method invocation (a call from one
- *              method to another.)
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsResolveOperands (
-    ACPI_WALK_STATE         *WalkState)
-{
-    UINT32                  i;
-    ACPI_STATUS             Status = AE_OK;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsResolveOperands, WalkState);
-
-
-    /*
-     * Attempt to resolve each of the valid operands
-     * Method arguments are passed by reference, not by value. This means
-     * that the actual objects are passed, not copies of the objects.
-     */
-    for (i = 0; i < WalkState->NumOperands; i++)
-    {
-        Status = AcpiExResolveToValue (&WalkState->Operands[i], WalkState);
-        if (ACPI_FAILURE (Status))
-        {
-            break;
-        }
-    }
-
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsClearOperands
- *
- * PARAMETERS:  WalkState           - Current walk state with operands on stack
- *
- * RETURN:      None
- *
- * DESCRIPTION: Clear all operands on the current walk state operand stack.
- *
- ******************************************************************************/
-
-void
-AcpiDsClearOperands (
-    ACPI_WALK_STATE         *WalkState)
-{
-    UINT32                  i;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsClearOperands, WalkState);
-
-
-    /* Remove a reference on each operand on the stack */
-
-    for (i = 0; i < WalkState->NumOperands; i++)
-    {
-        /*
-         * Remove a reference to all operands, including both
-         * "Arguments" and "Targets".
-         */
-        AcpiUtRemoveReference (WalkState->Operands[i]);
-        WalkState->Operands[i] = NULL;
-    }
-
-    WalkState->NumOperands = 0;
-    return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsCreateOperand
- *
- * PARAMETERS:  WalkState       - Current walk state
- *              Arg             - Parse object for the argument
- *              ArgIndex        - Which argument (zero based)
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Translate a parse tree object that is an argument to an AML
- *              opcode to the equivalent interpreter object. This may include
- *              looking up a name or entering a new name into the internal
- *              namespace.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsCreateOperand (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Arg,
-    UINT32                  ArgIndex)
-{
-    ACPI_STATUS             Status = AE_OK;
-    char                    *NameString;
-    UINT32                  NameLength;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_PARSE_OBJECT       *ParentOp;
-    UINT16                  Opcode;
-    ACPI_INTERPRETER_MODE   InterpreterMode;
-    const ACPI_OPCODE_INFO  *OpInfo;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsCreateOperand, Arg);
-
-
-    /* A valid name must be looked up in the namespace */
-
-    if ((Arg->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
-        (Arg->Common.Value.String) &&
-        !(Arg->Common.Flags & ACPI_PARSEOP_IN_STACK))
-    {
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Getting a name: Arg=%p\n", Arg));
-
-        /* Get the entire name string from the AML stream */
-
-        Status = AcpiExGetNameString (ACPI_TYPE_ANY,
-            Arg->Common.Value.Buffer, &NameString, &NameLength);
-
-        if (ACPI_FAILURE (Status))
-        {
-            return_ACPI_STATUS (Status);
-        }
-
-        /* All prefixes have been handled, and the name is in NameString */
-
-        /*
-         * Special handling for BufferField declarations. This is a deferred
-         * opcode that unfortunately defines the field name as the last
-         * parameter instead of the first. We get here when we are performing
-         * the deferred execution, so the actual name of the field is already
-         * in the namespace. We don't want to attempt to look it up again
-         * because we may be executing in a different scope than where the
-         * actual opcode exists.
-         */
-        if ((WalkState->DeferredNode) &&
-            (WalkState->DeferredNode->Type == ACPI_TYPE_BUFFER_FIELD) &&
-            (ArgIndex == (UINT32)
-                ((WalkState->Opcode == AML_CREATE_FIELD_OP) ? 3 : 2)))
-        {
-            ObjDesc = ACPI_CAST_PTR (
-                ACPI_OPERAND_OBJECT, WalkState->DeferredNode);
-            Status = AE_OK;
-        }
-        else    /* All other opcodes */
-        {
-            /*
-             * Differentiate between a namespace "create" operation
-             * versus a "lookup" operation (IMODE_LOAD_PASS2 vs.
-             * IMODE_EXECUTE) in order to support the creation of
-             * namespace objects during the execution of control methods.
-             */
-            ParentOp = Arg->Common.Parent;
-            OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Common.AmlOpcode);
-
-            if ((OpInfo->Flags & AML_NSNODE) &&
-                (ParentOp->Common.AmlOpcode != AML_INT_METHODCALL_OP) &&
-                (ParentOp->Common.AmlOpcode != AML_REGION_OP) &&
-                (ParentOp->Common.AmlOpcode != AML_INT_NAMEPATH_OP))
-            {
-                /* Enter name into namespace if not found */
-
-                InterpreterMode = ACPI_IMODE_LOAD_PASS2;
-            }
-            else
-            {
-                /* Return a failure if name not found */
-
-                InterpreterMode = ACPI_IMODE_EXECUTE;
-            }
-
-            Status = AcpiNsLookup (WalkState->ScopeInfo, NameString,
-                ACPI_TYPE_ANY, InterpreterMode,
-                ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, WalkState,
-                ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ObjDesc));
-            /*
-             * The only case where we pass through (ignore) a NOT_FOUND
-             * error is for the CondRefOf opcode.
-             */
-            if (Status == AE_NOT_FOUND)
-            {
-                if (ParentOp->Common.AmlOpcode == AML_CONDITIONAL_REF_OF_OP)
-                {
-                    /*
-                     * For the Conditional Reference op, it's OK if
-                     * the name is not found;  We just need a way to
-                     * indicate this to the interpreter, set the
-                     * object to the root
-                     */
-                    ObjDesc = ACPI_CAST_PTR (
-                        ACPI_OPERAND_OBJECT, AcpiGbl_RootNode);
-                    Status = AE_OK;
-                }
-                else if (ParentOp->Common.AmlOpcode == AML_EXTERNAL_OP)
-                {
-                    /*
-                     * This opcode should never appear here. It is used only
-                     * by AML disassemblers and is surrounded by an If(0)
-                     * by the ASL compiler.
-                     *
-                     * Therefore, if we see it here, it is a serious error.
-                     */
-                    Status = AE_AML_BAD_OPCODE;
-                }
-                else
-                {
-                    /*
-                     * We just plain didn't find it -- which is a
-                     * very serious error at this point
-                     */
-                    Status = AE_AML_NAME_NOT_FOUND;
-                }
-            }
-
-            if (ACPI_FAILURE (Status))
-            {
-                ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
-                    NameString, Status);
-            }
-        }
-
-        /* Free the namestring created above */
-
-        ACPI_FREE (NameString);
-
-        /* Check status from the lookup */
-
-        if (ACPI_FAILURE (Status))
-        {
-            return_ACPI_STATUS (Status);
-        }
-
-        /* Put the resulting object onto the current object stack */
-
-        Status = AcpiDsObjStackPush (ObjDesc, WalkState);
-        if (ACPI_FAILURE (Status))
-        {
-            return_ACPI_STATUS (Status);
-        }
-
-        AcpiDbDisplayArgumentObject (ObjDesc, WalkState);
-    }
-    else
-    {
-        /* Check for null name case */
-
-        if ((Arg->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
-            !(Arg->Common.Flags & ACPI_PARSEOP_IN_STACK))
-        {
-            /*
-             * If the name is null, this means that this is an
-             * optional result parameter that was not specified
-             * in the original ASL. Create a Zero Constant for a
-             * placeholder. (Store to a constant is a Noop.)
-             */
-            Opcode = AML_ZERO_OP;       /* Has no arguments! */
-
-            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-                "Null namepath: Arg=%p\n", Arg));
-        }
-        else
-        {
-            Opcode = Arg->Common.AmlOpcode;
-        }
-
-        /* Get the object type of the argument */
-
-        OpInfo = AcpiPsGetOpcodeInfo (Opcode);
-        if (OpInfo->ObjectType == ACPI_TYPE_INVALID)
-        {
-            return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
-        }
-
-        if ((OpInfo->Flags & AML_HAS_RETVAL) ||
-            (Arg->Common.Flags & ACPI_PARSEOP_IN_STACK))
-        {
-            /*
-             * Use value that was already previously returned
-             * by the evaluation of this argument
-             */
-            Status = AcpiDsResultPop (&ObjDesc, WalkState);
-            if (ACPI_FAILURE (Status))
-            {
-                /*
-                 * Only error is underflow, and this indicates
-                 * a missing or null operand!
-                 */
-                ACPI_EXCEPTION ((AE_INFO, Status,
-                    "Missing or null operand"));
-                return_ACPI_STATUS (Status);
-            }
-        }
-        else
-        {
-            /* Create an ACPI_INTERNAL_OBJECT for the argument */
-
-            ObjDesc = AcpiUtCreateInternalObject (OpInfo->ObjectType);
-            if (!ObjDesc)
-            {
-                return_ACPI_STATUS (AE_NO_MEMORY);
-            }
-
-            /* Initialize the new object */
-
-            Status = AcpiDsInitObjectFromOp (
-                WalkState, Arg, Opcode, &ObjDesc);
-            if (ACPI_FAILURE (Status))
-            {
-                AcpiUtDeleteObjectDesc (ObjDesc);
-                return_ACPI_STATUS (Status);
-            }
-        }
-
-        /* Put the operand object on the object stack */
-
-        Status = AcpiDsObjStackPush (ObjDesc, WalkState);
-        if (ACPI_FAILURE (Status))
-        {
-            return_ACPI_STATUS (Status);
-        }
-
-        AcpiDbDisplayArgumentObject (ObjDesc, WalkState);
-    }
-
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsCreateOperands
- *
- * PARAMETERS:  WalkState           - Current state
- *              FirstArg            - First argument of a parser argument tree
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Convert an operator's arguments from a parse tree format to
- *              namespace objects and place those argument object on the object
- *              stack in preparation for evaluation by the interpreter.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsCreateOperands (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *FirstArg)
-{
-    ACPI_STATUS             Status = AE_OK;
-    ACPI_PARSE_OBJECT       *Arg;
-    ACPI_PARSE_OBJECT       *Arguments[ACPI_OBJ_NUM_OPERANDS];
-    UINT32                  ArgCount = 0;
-    UINT32                  Index = WalkState->NumOperands;
-    UINT32                  i;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsCreateOperands, FirstArg);
-
-
-    /* Get all arguments in the list */
-
-    Arg = FirstArg;
-    while (Arg)
-    {
-        if (Index >= ACPI_OBJ_NUM_OPERANDS)
-        {
-            return_ACPI_STATUS (AE_BAD_DATA);
-        }
-
-        Arguments[Index] = Arg;
-        WalkState->Operands [Index] = NULL;
-
-        /* Move on to next argument, if any */
-
-        Arg = Arg->Common.Next;
-        ArgCount++;
-        Index++;
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-        "NumOperands %d, ArgCount %d, Index %d\n",
-        WalkState->NumOperands, ArgCount, Index));
-
-    /* Create the interpreter arguments, in reverse order */
-
-    Index--;
-    for (i = 0; i < ArgCount; i++)
-    {
-        Arg = Arguments[Index];
-        WalkState->OperandIndex = (UINT8) Index;
-
-        Status = AcpiDsCreateOperand (WalkState, Arg, Index);
-        if (ACPI_FAILURE (Status))
-        {
-            goto Cleanup;
-        }
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-            "Created Arg #%u (%p) %u args total\n",
-            Index, Arg, ArgCount));
-        Index--;
-    }
-
-    return_ACPI_STATUS (Status);
-
-
-Cleanup:
-    /*
-     * We must undo everything done above; meaning that we must
-     * pop everything off of the operand stack and delete those
-     * objects
-     */
-    AcpiDsObjStackPopAndDelete (ArgCount, WalkState);
-
-    ACPI_EXCEPTION ((AE_INFO, Status, "While creating Arg %u", Index));
-    return_ACPI_STATUS (Status);
-}
-
-
-/*****************************************************************************
- *
- * FUNCTION:    AcpiDsEvaluateNamePath
- *
- * PARAMETERS:  WalkState       - Current state of the parse tree walk,
- *                                the opcode of current operation should be
- *                                AML_INT_NAMEPATH_OP
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Translate the -NamePath- parse tree object to the equivalent
- *              interpreter object, convert it to value, if needed, duplicate
- *              it, if needed, and push it onto the current result stack.
- *
- ****************************************************************************/
-
-ACPI_STATUS
-AcpiDsEvaluateNamePath (
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status = AE_OK;
-    ACPI_PARSE_OBJECT       *Op = WalkState->Op;
-    ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
-    ACPI_OPERAND_OBJECT     *NewObjDesc;
-    UINT8                   Type;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsEvaluateNamePath, WalkState);
-
-
-    if (!Op->Common.Parent)
-    {
-        /* This happens after certain exception processing */
-
-        goto Exit;
-    }
-
-    if ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
-        (Op->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP) ||
-        (Op->Common.Parent->Common.AmlOpcode == AML_REF_OF_OP))
-    {
-        /* TBD: Should we specify this feature as a bit of OpInfo->Flags of these opcodes? */
-
-        goto Exit;
-    }
-
-    Status = AcpiDsCreateOperand (WalkState, Op, 0);
-    if (ACPI_FAILURE (Status))
-    {
-        goto Exit;
-    }
-
-    if (Op->Common.Flags & ACPI_PARSEOP_TARGET)
-    {
-        NewObjDesc = *Operand;
-        goto PushResult;
-    }
-
-    Type = (*Operand)->Common.Type;
-
-    Status = AcpiExResolveToValue (Operand, WalkState);
-    if (ACPI_FAILURE (Status))
-    {
-        goto Exit;
-    }
-
-    if (Type == ACPI_TYPE_INTEGER)
-    {
-        /* It was incremented by AcpiExResolveToValue */
-
-        AcpiUtRemoveReference (*Operand);
-
-        Status = AcpiUtCopyIobjectToIobject (
-            *Operand, &NewObjDesc, WalkState);
-        if (ACPI_FAILURE (Status))
-        {
-            goto Exit;
-        }
-    }
-    else
-    {
-        /*
-         * The object either was anew created or is
-         * a Namespace node - don't decrement it.
-         */
-        NewObjDesc = *Operand;
-    }
-
-    /* Cleanup for name-path operand */
-
-    Status = AcpiDsObjStackPop (1, WalkState);
-    if (ACPI_FAILURE (Status))
-    {
-        WalkState->ResultObj = NewObjDesc;
-        goto Exit;
-    }
-
-PushResult:
-
-    WalkState->ResultObj = NewObjDesc;
-
-    Status = AcpiDsResultPush (WalkState->ResultObj, WalkState);
-    if (ACPI_SUCCESS (Status))
-    {
-        /* Force to take it from stack */
-
-        Op->Common.Flags |= ACPI_PARSEOP_IN_STACK;
-    }
-
-Exit:
-
-    return_ACPI_STATUS (Status);
-}

+ 0 - 791
h2o/localdep/acpica/dispatcher/dswexec.c

@@ -1,791 +0,0 @@
-/******************************************************************************
- *
- * Module Name: dswexec - Dispatcher method execution callbacks;
- *                        dispatch to interpreter.
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acparser.h"
-#include "amlcode.h"
-#include "acdispat.h"
-#include "acinterp.h"
-#include "acnamesp.h"
-#include "acdebug.h"
-
-
-#define _COMPONENT          ACPI_DISPATCHER
-        ACPI_MODULE_NAME    ("dswexec")
-
-/*
- * Dispatch table for opcode classes
- */
-static ACPI_EXECUTE_OP      AcpiGbl_OpTypeDispatch [] =
-{
-    AcpiExOpcode_0A_0T_1R,
-    AcpiExOpcode_1A_0T_0R,
-    AcpiExOpcode_1A_0T_1R,
-    AcpiExOpcode_1A_1T_0R,
-    AcpiExOpcode_1A_1T_1R,
-    AcpiExOpcode_2A_0T_0R,
-    AcpiExOpcode_2A_0T_1R,
-    AcpiExOpcode_2A_1T_1R,
-    AcpiExOpcode_2A_2T_1R,
-    AcpiExOpcode_3A_0T_0R,
-    AcpiExOpcode_3A_1T_1R,
-    AcpiExOpcode_6A_0T_1R
-};
-
-
-/*****************************************************************************
- *
- * FUNCTION:    AcpiDsGetPredicateValue
- *
- * PARAMETERS:  WalkState       - Current state of the parse tree walk
- *              ResultObj       - if non-zero, pop result from result stack
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Get the result of a predicate evaluation
- *
- ****************************************************************************/
-
-ACPI_STATUS
-AcpiDsGetPredicateValue (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_OPERAND_OBJECT     *ResultObj)
-{
-    ACPI_STATUS             Status = AE_OK;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_OPERAND_OBJECT     *LocalObjDesc = NULL;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsGetPredicateValue, WalkState);
-
-
-    WalkState->ControlState->Common.State = 0;
-
-    if (ResultObj)
-    {
-        Status = AcpiDsResultPop (&ObjDesc, WalkState);
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_EXCEPTION ((AE_INFO, Status,
-                "Could not get result from predicate evaluation"));
-
-            return_ACPI_STATUS (Status);
-        }
-    }
-    else
-    {
-        Status = AcpiDsCreateOperand (WalkState, WalkState->Op, 0);
-        if (ACPI_FAILURE (Status))
-        {
-            return_ACPI_STATUS (Status);
-        }
-
-        Status = AcpiExResolveToValue (&WalkState->Operands [0], WalkState);
-        if (ACPI_FAILURE (Status))
-        {
-            return_ACPI_STATUS (Status);
-        }
-
-        ObjDesc = WalkState->Operands [0];
-    }
-
-    if (!ObjDesc)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "No predicate ObjDesc=%p State=%p",
-            ObjDesc, WalkState));
-
-        return_ACPI_STATUS (AE_AML_NO_OPERAND);
-    }
-
-    /*
-     * Result of predicate evaluation must be an Integer
-     * object. Implicitly convert the argument if necessary.
-     */
-    Status = AcpiExConvertToInteger (ObjDesc, &LocalObjDesc,
-        ACPI_IMPLICIT_CONVERSION);
-    if (ACPI_FAILURE (Status))
-    {
-        goto Cleanup;
-    }
-
-    if (LocalObjDesc->Common.Type != ACPI_TYPE_INTEGER)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "Bad predicate (not an integer) ObjDesc=%p State=%p Type=0x%X",
-            ObjDesc, WalkState, ObjDesc->Common.Type));
-
-        Status = AE_AML_OPERAND_TYPE;
-        goto Cleanup;
-    }
-
-    /* Truncate the predicate to 32-bits if necessary */
-
-    (void) AcpiExTruncateFor32bitTable (LocalObjDesc);
-
-    /*
-     * Save the result of the predicate evaluation on
-     * the control stack
-     */
-    if (LocalObjDesc->Integer.Value)
-    {
-        WalkState->ControlState->Common.Value = TRUE;
-    }
-    else
-    {
-        /*
-         * Predicate is FALSE, we will just toss the
-         * rest of the package
-         */
-        WalkState->ControlState->Common.Value = FALSE;
-        Status = AE_CTRL_FALSE;
-    }
-
-    /* Predicate can be used for an implicit return value */
-
-    (void) AcpiDsDoImplicitReturn (LocalObjDesc, WalkState, TRUE);
-
-
-Cleanup:
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-        "Completed a predicate eval=%X Op=%p\n",
-        WalkState->ControlState->Common.Value, WalkState->Op));
-
-    /* Break to debugger to display result */
-
-    AcpiDbDisplayResultObject (LocalObjDesc, WalkState);
-
-    /*
-     * Delete the predicate result object (we know that
-     * we don't need it anymore)
-     */
-    if (LocalObjDesc != ObjDesc)
-    {
-        AcpiUtRemoveReference (LocalObjDesc);
-    }
-    AcpiUtRemoveReference (ObjDesc);
-
-    WalkState->ControlState->Common.State = ACPI_CONTROL_NORMAL;
-    return_ACPI_STATUS (Status);
-}
-
-
-/*****************************************************************************
- *
- * FUNCTION:    AcpiDsExecBeginOp
- *
- * PARAMETERS:  WalkState       - Current state of the parse tree walk
- *              OutOp           - Where to return op if a new one is created
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Descending callback used during the execution of control
- *              methods. This is where most operators and operands are
- *              dispatched to the interpreter.
- *
- ****************************************************************************/
-
-ACPI_STATUS
-AcpiDsExecBeginOp (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       **OutOp)
-{
-    ACPI_PARSE_OBJECT       *Op;
-    ACPI_STATUS             Status = AE_OK;
-    UINT32                  OpcodeClass;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsExecBeginOp, WalkState);
-
-
-    Op = WalkState->Op;
-    if (!Op)
-    {
-        Status = AcpiDsLoad2BeginOp (WalkState, OutOp);
-        if (ACPI_FAILURE (Status))
-        {
-            goto ErrorExit;
-        }
-
-        Op = *OutOp;
-        WalkState->Op = Op;
-        WalkState->Opcode = Op->Common.AmlOpcode;
-        WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
-
-        if (AcpiNsOpensScope (WalkState->OpInfo->ObjectType))
-        {
-            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-                "(%s) Popping scope for Op %p\n",
-                AcpiUtGetTypeName (WalkState->OpInfo->ObjectType), Op));
-
-            Status = AcpiDsScopeStackPop (WalkState);
-            if (ACPI_FAILURE (Status))
-            {
-                goto ErrorExit;
-            }
-        }
-    }
-
-    if (Op == WalkState->Origin)
-    {
-        if (OutOp)
-        {
-            *OutOp = Op;
-        }
-
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /*
-     * If the previous opcode was a conditional, this opcode
-     * must be the beginning of the associated predicate.
-     * Save this knowledge in the current scope descriptor
-     */
-    if ((WalkState->ControlState) &&
-        (WalkState->ControlState->Common.State ==
-            ACPI_CONTROL_CONDITIONAL_EXECUTING))
-    {
-        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-            "Exec predicate Op=%p State=%p\n",
-            Op, WalkState));
-
-        WalkState->ControlState->Common.State =
-            ACPI_CONTROL_PREDICATE_EXECUTING;
-
-        /* Save start of predicate */
-
-        WalkState->ControlState->Control.PredicateOp = Op;
-    }
-
-
-    OpcodeClass = WalkState->OpInfo->Class;
-
-    /* We want to send namepaths to the load code */
-
-    if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
-    {
-        OpcodeClass = AML_CLASS_NAMED_OBJECT;
-    }
-
-    /*
-     * Handle the opcode based upon the opcode type
-     */
-    switch (OpcodeClass)
-    {
-    case AML_CLASS_CONTROL:
-
-        Status = AcpiDsExecBeginControlOp (WalkState, Op);
-        break;
-
-    case AML_CLASS_NAMED_OBJECT:
-
-        if (WalkState->WalkType & ACPI_WALK_METHOD)
-        {
-            /*
-             * Found a named object declaration during method execution;
-             * we must enter this object into the namespace. The created
-             * object is temporary and will be deleted upon completion of
-             * the execution of this method.
-             *
-             * Note 10/2010: Except for the Scope() op. This opcode does
-             * not actually create a new object, it refers to an existing
-             * object. However, for Scope(), we want to indeed open a
-             * new scope.
-             */
-            if (Op->Common.AmlOpcode != AML_SCOPE_OP)
-            {
-                Status = AcpiDsLoad2BeginOp (WalkState, NULL);
-            }
-            else
-            {
-                Status = AcpiDsScopeStackPush (
-                    Op->Named.Node, Op->Named.Node->Type, WalkState);
-                if (ACPI_FAILURE (Status))
-                {
-                    return_ACPI_STATUS (Status);
-                }
-            }
-        }
-        break;
-
-    case AML_CLASS_EXECUTE:
-    case AML_CLASS_CREATE:
-
-        break;
-
-    default:
-
-        break;
-    }
-
-    /* Nothing to do here during method execution */
-
-    return_ACPI_STATUS (Status);
-
-
-ErrorExit:
-    Status = AcpiDsMethodError (Status, WalkState);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*****************************************************************************
- *
- * FUNCTION:    AcpiDsExecEndOp
- *
- * PARAMETERS:  WalkState       - Current state of the parse tree walk
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Ascending callback used during the execution of control
- *              methods. The only thing we really need to do here is to
- *              notice the beginning of IF, ELSE, and WHILE blocks.
- *
- ****************************************************************************/
-
-ACPI_STATUS
-AcpiDsExecEndOp (
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_PARSE_OBJECT       *Op;
-    ACPI_STATUS             Status = AE_OK;
-    UINT32                  OpType;
-    UINT32                  OpClass;
-    ACPI_PARSE_OBJECT       *NextOp;
-    ACPI_PARSE_OBJECT       *FirstArg;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsExecEndOp, WalkState);
-
-
-    Op = WalkState->Op;
-    OpType = WalkState->OpInfo->Type;
-    OpClass = WalkState->OpInfo->Class;
-
-    if (OpClass == AML_CLASS_UNKNOWN)
-    {
-        ACPI_ERROR ((AE_INFO, "Unknown opcode 0x%X", Op->Common.AmlOpcode));
-        return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
-    }
-
-    FirstArg = Op->Common.Value.Arg;
-
-    /* Init the walk state */
-
-    WalkState->NumOperands = 0;
-    WalkState->OperandIndex = 0;
-    WalkState->ReturnDesc = NULL;
-    WalkState->ResultObj = NULL;
-
-    /* Call debugger for single step support (DEBUG build only) */
-
-    Status = AcpiDbSingleStep (WalkState, Op, OpClass);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Decode the Opcode Class */
-
-    switch (OpClass)
-    {
-    case AML_CLASS_ARGUMENT:    /* Constants, literals, etc. */
-
-        if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
-        {
-            Status = AcpiDsEvaluateNamePath (WalkState);
-            if (ACPI_FAILURE (Status))
-            {
-                goto Cleanup;
-            }
-        }
-        break;
-
-    case AML_CLASS_EXECUTE:     /* Most operators with arguments */
-
-        /* Build resolved operand stack */
-
-        Status = AcpiDsCreateOperands (WalkState, FirstArg);
-        if (ACPI_FAILURE (Status))
-        {
-            goto Cleanup;
-        }
-
-        /*
-         * All opcodes require operand resolution, with the only exceptions
-         * being the ObjectType and SizeOf operators.
-         */
-        if (!(WalkState->OpInfo->Flags & AML_NO_OPERAND_RESOLVE))
-        {
-            /* Resolve all operands */
-
-            Status = AcpiExResolveOperands (WalkState->Opcode,
-                &(WalkState->Operands [WalkState->NumOperands -1]),
-                WalkState);
-        }
-
-        if (ACPI_SUCCESS (Status))
-        {
-            /*
-             * Dispatch the request to the appropriate interpreter handler
-             * routine. There is one routine per opcode "type" based upon the
-             * number of opcode arguments and return type.
-             */
-            Status = AcpiGbl_OpTypeDispatch[OpType] (WalkState);
-        }
-        else
-        {
-            /*
-             * Treat constructs of the form "Store(LocalX,LocalX)" as noops when the
-             * Local is uninitialized.
-             */
-            if  ((Status == AE_AML_UNINITIALIZED_LOCAL) &&
-                (WalkState->Opcode == AML_STORE_OP) &&
-                (WalkState->Operands[0]->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
-                (WalkState->Operands[1]->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
-                (WalkState->Operands[0]->Reference.Class ==
-                 WalkState->Operands[1]->Reference.Class) &&
-                (WalkState->Operands[0]->Reference.Value ==
-                 WalkState->Operands[1]->Reference.Value))
-            {
-                Status = AE_OK;
-            }
-            else
-            {
-                ACPI_EXCEPTION ((AE_INFO, Status,
-                    "While resolving operands for [%s]",
-                    AcpiPsGetOpcodeName (WalkState->Opcode)));
-            }
-        }
-
-        /* Always delete the argument objects and clear the operand stack */
-
-        AcpiDsClearOperands (WalkState);
-
-        /*
-         * If a result object was returned from above, push it on the
-         * current result stack
-         */
-        if (ACPI_SUCCESS (Status) &&
-            WalkState->ResultObj)
-        {
-            Status = AcpiDsResultPush (WalkState->ResultObj, WalkState);
-        }
-        break;
-
-    default:
-
-        switch (OpType)
-        {
-        case AML_TYPE_CONTROL:    /* Type 1 opcode, IF/ELSE/WHILE/NOOP */
-
-            /* 1 Operand, 0 ExternalResult, 0 InternalResult */
-
-            Status = AcpiDsExecEndControlOp (WalkState, Op);
-
-            break;
-
-        case AML_TYPE_METHOD_CALL:
-            /*
-             * If the method is referenced from within a package
-             * declaration, it is not a invocation of the method, just
-             * a reference to it.
-             */
-            if ((Op->Asl.Parent) &&
-               ((Op->Asl.Parent->Asl.AmlOpcode == AML_PACKAGE_OP) ||
-                (Op->Asl.Parent->Asl.AmlOpcode == AML_VARIABLE_PACKAGE_OP)))
-            {
-                ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-                    "Method Reference in a Package, Op=%p\n", Op));
-
-                Op->Common.Node = (ACPI_NAMESPACE_NODE *)
-                    Op->Asl.Value.Arg->Asl.Node;
-                AcpiUtAddReference (Op->Asl.Value.Arg->Asl.Node->Object);
-                return_ACPI_STATUS (AE_OK);
-            }
-
-            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-                "Method invocation, Op=%p\n", Op));
-
-            /*
-             * (AML_METHODCALL) Op->Asl.Value.Arg->Asl.Node contains
-             * the method Node pointer
-             */
-            /* NextOp points to the op that holds the method name */
-
-            NextOp = FirstArg;
-
-            /* NextOp points to first argument op */
-
-            NextOp = NextOp->Common.Next;
-
-            /*
-             * Get the method's arguments and put them on the operand stack
-             */
-            Status = AcpiDsCreateOperands (WalkState, NextOp);
-            if (ACPI_FAILURE (Status))
-            {
-                break;
-            }
-
-            /*
-             * Since the operands will be passed to another control method,
-             * we must resolve all local references here (Local variables,
-             * arguments to *this* method, etc.)
-             */
-            Status = AcpiDsResolveOperands (WalkState);
-            if (ACPI_FAILURE (Status))
-            {
-                /* On error, clear all resolved operands */
-
-                AcpiDsClearOperands (WalkState);
-                break;
-            }
-
-            /*
-             * Tell the walk loop to preempt this running method and
-             * execute the new method
-             */
-            Status = AE_CTRL_TRANSFER;
-
-            /*
-             * Return now; we don't want to disturb anything,
-             * especially the operand count!
-             */
-            return_ACPI_STATUS (Status);
-
-        case AML_TYPE_CREATE_FIELD:
-
-            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-                "Executing CreateField Buffer/Index Op=%p\n", Op));
-
-            Status = AcpiDsLoad2EndOp (WalkState);
-            if (ACPI_FAILURE (Status))
-            {
-                break;
-            }
-
-            Status = AcpiDsEvalBufferFieldOperands (WalkState, Op);
-            break;
-
-
-        case AML_TYPE_CREATE_OBJECT:
-
-            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-                "Executing CreateObject (Buffer/Package) Op=%p Child=%p ParentOpcode=%4.4X\n",
-                Op, Op->Named.Value.Arg, Op->Common.Parent->Common.AmlOpcode));
-
-            switch (Op->Common.Parent->Common.AmlOpcode)
-            {
-            case AML_NAME_OP:
-                /*
-                 * Put the Node on the object stack (Contains the ACPI Name
-                 * of this object)
-                 */
-                WalkState->Operands[0] = (void *)
-                    Op->Common.Parent->Common.Node;
-                WalkState->NumOperands = 1;
-
-                Status = AcpiDsCreateNode (WalkState,
-                    Op->Common.Parent->Common.Node, Op->Common.Parent);
-                if (ACPI_FAILURE (Status))
-                {
-                    break;
-                }
-
-                /* Fall through */
-                /*lint -fallthrough */
-
-            case AML_INT_EVAL_SUBTREE_OP:
-
-                Status = AcpiDsEvalDataObjectOperands (WalkState, Op,
-                    AcpiNsGetAttachedObject (Op->Common.Parent->Common.Node));
-                break;
-
-            default:
-
-                Status = AcpiDsEvalDataObjectOperands (WalkState, Op, NULL);
-                break;
-            }
-
-            /*
-             * If a result object was returned from above, push it on the
-             * current result stack
-             */
-            if (WalkState->ResultObj)
-            {
-                Status = AcpiDsResultPush (WalkState->ResultObj, WalkState);
-            }
-            break;
-
-        case AML_TYPE_NAMED_FIELD:
-        case AML_TYPE_NAMED_COMPLEX:
-        case AML_TYPE_NAMED_SIMPLE:
-        case AML_TYPE_NAMED_NO_OBJ:
-
-            Status = AcpiDsLoad2EndOp (WalkState);
-            if (ACPI_FAILURE (Status))
-            {
-                break;
-            }
-
-            if (Op->Common.AmlOpcode == AML_REGION_OP)
-            {
-                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-                    "Executing OpRegion Address/Length Op=%p\n", Op));
-
-                Status = AcpiDsEvalRegionOperands (WalkState, Op);
-                if (ACPI_FAILURE (Status))
-                {
-                    break;
-                }
-            }
-            else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
-            {
-                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-                    "Executing DataTableRegion Strings Op=%p\n", Op));
-
-                Status = AcpiDsEvalTableRegionOperands (WalkState, Op);
-                if (ACPI_FAILURE (Status))
-                {
-                    break;
-                }
-            }
-            else if (Op->Common.AmlOpcode == AML_BANK_FIELD_OP)
-            {
-                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-                    "Executing BankField Op=%p\n", Op));
-
-                Status = AcpiDsEvalBankFieldOperands (WalkState, Op);
-                if (ACPI_FAILURE (Status))
-                {
-                    break;
-                }
-            }
-            break;
-
-        case AML_TYPE_UNDEFINED:
-
-            ACPI_ERROR ((AE_INFO,
-                "Undefined opcode type Op=%p", Op));
-            return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
-
-        case AML_TYPE_BOGUS:
-
-            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-                "Internal opcode=%X type Op=%p\n",
-                WalkState->Opcode, Op));
-            break;
-
-        default:
-
-            ACPI_ERROR ((AE_INFO,
-                "Unimplemented opcode, class=0x%X "
-                "type=0x%X Opcode=0x%X Op=%p",
-                OpClass, OpType, Op->Common.AmlOpcode, Op));
-
-            Status = AE_NOT_IMPLEMENTED;
-            break;
-        }
-    }
-
-    /*
-     * ACPI 2.0 support for 64-bit integers: Truncate numeric
-     * result value if we are executing from a 32-bit ACPI table
-     */
-    (void) AcpiExTruncateFor32bitTable (WalkState->ResultObj);
-
-    /*
-     * Check if we just completed the evaluation of a
-     * conditional predicate
-     */
-    if ((ACPI_SUCCESS (Status)) &&
-        (WalkState->ControlState) &&
-        (WalkState->ControlState->Common.State ==
-            ACPI_CONTROL_PREDICATE_EXECUTING) &&
-        (WalkState->ControlState->Control.PredicateOp == Op))
-    {
-        Status = AcpiDsGetPredicateValue (WalkState, WalkState->ResultObj);
-        WalkState->ResultObj = NULL;
-    }
-
-
-Cleanup:
-
-    if (WalkState->ResultObj)
-    {
-        /* Break to debugger to display result */
-
-        AcpiDbDisplayResultObject (WalkState->ResultObj,WalkState);
-
-        /*
-         * Delete the result op if and only if:
-         * Parent will not use the result -- such as any
-         * non-nested type2 op in a method (parent will be method)
-         */
-        AcpiDsDeleteResultIfNotUsed (Op, WalkState->ResultObj, WalkState);
-    }
-
-#ifdef _UNDER_DEVELOPMENT
-
-    if (WalkState->ParserState.Aml == WalkState->ParserState.AmlEnd)
-    {
-        AcpiDbMethodEnd (WalkState);
-    }
-#endif
-
-    /* Invoke exception handler on error */
-
-    if (ACPI_FAILURE (Status))
-    {
-        Status = AcpiDsMethodError (Status, WalkState);
-    }
-
-    /* Always clear the object stack */
-
-    WalkState->NumOperands = 0;
-    return_ACPI_STATUS (Status);
-}

+ 0 - 625
h2o/localdep/acpica/dispatcher/dswload.c

@@ -1,625 +0,0 @@
-/******************************************************************************
- *
- * Module Name: dswload - Dispatcher first pass namespace load callbacks
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acparser.h"
-#include "amlcode.h"
-#include "acdispat.h"
-#include "acinterp.h"
-#include "acnamesp.h"
-
-#ifdef ACPI_ASL_COMPILER
-#include "acdisasm.h"
-#endif
-
-#define _COMPONENT          ACPI_DISPATCHER
-        ACPI_MODULE_NAME    ("dswload")
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsInitCallbacks
- *
- * PARAMETERS:  WalkState       - Current state of the parse tree walk
- *              PassNumber      - 1, 2, or 3
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Init walk state callbacks
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsInitCallbacks (
-    ACPI_WALK_STATE         *WalkState,
-    UINT32                  PassNumber)
-{
-
-    switch (PassNumber)
-    {
-    case 0:
-
-        /* Parse only - caller will setup callbacks */
-
-        WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
-                                        ACPI_PARSE_DELETE_TREE |
-                                        ACPI_PARSE_DISASSEMBLE;
-        WalkState->DescendingCallback = NULL;
-        WalkState->AscendingCallback  = NULL;
-        break;
-
-    case 1:
-
-        /* Load pass 1 */
-
-        WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
-                                        ACPI_PARSE_DELETE_TREE;
-        WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
-        WalkState->AscendingCallback  = AcpiDsLoad1EndOp;
-        break;
-
-    case 2:
-
-        /* Load pass 2 */
-
-        WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
-                                        ACPI_PARSE_DELETE_TREE;
-        WalkState->DescendingCallback = AcpiDsLoad2BeginOp;
-        WalkState->AscendingCallback  = AcpiDsLoad2EndOp;
-        break;
-
-    case 3:
-
-        /* Execution pass */
-
-        WalkState->ParseFlags        |= ACPI_PARSE_EXECUTE  |
-                                        ACPI_PARSE_DELETE_TREE;
-        WalkState->DescendingCallback = AcpiDsExecBeginOp;
-        WalkState->AscendingCallback  = AcpiDsExecEndOp;
-        break;
-
-    default:
-
-        return (AE_BAD_PARAMETER);
-    }
-
-    return (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsLoad1BeginOp
- *
- * PARAMETERS:  WalkState       - Current state of the parse tree walk
- *              OutOp           - Where to return op if a new one is created
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Descending callback used during the loading of ACPI tables.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsLoad1BeginOp (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       **OutOp)
-{
-    ACPI_PARSE_OBJECT       *Op;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_STATUS             Status;
-    ACPI_OBJECT_TYPE        ObjectType;
-    char                    *Path;
-    UINT32                  Flags;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsLoad1BeginOp, WalkState->Op);
-
-
-    Op = WalkState->Op;
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
-
-    /* We are only interested in opcodes that have an associated name */
-
-    if (Op)
-    {
-        if (!(WalkState->OpInfo->Flags & AML_NAMED))
-        {
-            *OutOp = Op;
-            return_ACPI_STATUS (AE_OK);
-        }
-
-        /* Check if this object has already been installed in the namespace */
-
-        if (Op->Common.Node)
-        {
-            *OutOp = Op;
-            return_ACPI_STATUS (AE_OK);
-        }
-    }
-
-    Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
-
-    /* Map the raw opcode into an internal object type */
-
-    ObjectType = WalkState->OpInfo->ObjectType;
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-        "State=%p Op=%p [%s]\n", WalkState, Op,
-        AcpiUtGetTypeName (ObjectType)));
-
-    switch (WalkState->Opcode)
-    {
-    case AML_SCOPE_OP:
-        /*
-         * The target name of the Scope() operator must exist at this point so
-         * that we can actually open the scope to enter new names underneath it.
-         * Allow search-to-root for single namesegs.
-         */
-        Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
-            ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
-#ifdef ACPI_ASL_COMPILER
-        if (Status == AE_NOT_FOUND)
-        {
-            /*
-             * Table disassembly:
-             * Target of Scope() not found. Generate an External for it, and
-             * insert the name into the namespace.
-             */
-            AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_DEVICE, 0, 0);
-            Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
-               ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
-               WalkState, &Node);
-        }
-#endif
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo, Path, Status);
-            return_ACPI_STATUS (Status);
-        }
-
-        /*
-         * Check to make sure that the target is
-         * one of the opcodes that actually opens a scope
-         */
-        switch (Node->Type)
-        {
-        case ACPI_TYPE_ANY:
-        case ACPI_TYPE_LOCAL_SCOPE:         /* Scope  */
-        case ACPI_TYPE_DEVICE:
-        case ACPI_TYPE_POWER:
-        case ACPI_TYPE_PROCESSOR:
-        case ACPI_TYPE_THERMAL:
-
-            /* These are acceptable types */
-            break;
-
-        case ACPI_TYPE_INTEGER:
-        case ACPI_TYPE_STRING:
-        case ACPI_TYPE_BUFFER:
-            /*
-             * These types we will allow, but we will change the type.
-             * This enables some existing code of the form:
-             *
-             *  Name (DEB, 0)
-             *  Scope (DEB) { ... }
-             *
-             * Note: silently change the type here. On the second pass,
-             * we will report a warning
-             */
-            ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
-                "Type override - [%4.4s] had invalid type (%s) "
-                "for Scope operator, changed to type ANY\n",
-                AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
-
-            Node->Type = ACPI_TYPE_ANY;
-            WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
-            break;
-
-        case ACPI_TYPE_METHOD:
-            /*
-             * Allow scope change to root during execution of module-level
-             * code. Root is typed METHOD during this time.
-             */
-            if ((Node == AcpiGbl_RootNode) &&
-                (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
-            {
-                break;
-            }
-
-            /*lint -fallthrough */
-
-        default:
-
-            /* All other types are an error */
-
-            ACPI_ERROR ((AE_INFO,
-                "Invalid type (%s) for target of "
-                "Scope operator [%4.4s] (Cannot override)",
-                AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
-
-            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
-        }
-        break;
-
-    default:
-        /*
-         * For all other named opcodes, we will enter the name into
-         * the namespace.
-         *
-         * Setup the search flags.
-         * Since we are entering a name into the namespace, we do not want to
-         * enable the search-to-root upsearch.
-         *
-         * There are only two conditions where it is acceptable that the name
-         * already exists:
-         *    1) the Scope() operator can reopen a scoping object that was
-         *       previously defined (Scope, Method, Device, etc.)
-         *    2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
-         *       BufferField, or Package), the name of the object is already
-         *       in the namespace.
-         */
-        if (WalkState->DeferredNode)
-        {
-            /* This name is already in the namespace, get the node */
-
-            Node = WalkState->DeferredNode;
-            Status = AE_OK;
-            break;
-        }
-
-        /*
-         * If we are executing a method, do not create any namespace objects
-         * during the load phase, only during execution.
-         */
-        if (WalkState->MethodNode)
-        {
-            Node = NULL;
-            Status = AE_OK;
-            break;
-        }
-
-        Flags = ACPI_NS_NO_UPSEARCH;
-        if ((WalkState->Opcode != AML_SCOPE_OP) &&
-            (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
-        {
-            if (WalkState->NamespaceOverride)
-            {
-                Flags |= ACPI_NS_OVERRIDE_IF_FOUND;
-                ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Override allowed\n",
-                    AcpiUtGetTypeName (ObjectType)));
-            }
-            else
-            {
-                Flags |= ACPI_NS_ERROR_IF_FOUND;
-                ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
-                    AcpiUtGetTypeName (ObjectType)));
-            }
-        }
-        else
-        {
-            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-                "[%s] Both Find or Create allowed\n",
-                AcpiUtGetTypeName (ObjectType)));
-        }
-
-        /*
-         * Enter the named type into the internal namespace. We enter the name
-         * as we go downward in the parse tree. Any necessary subobjects that
-         * involve arguments to the opcode must be created as we go back up the
-         * parse tree later.
-         */
-        Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
-            ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
-        if (ACPI_FAILURE (Status))
-        {
-            if (Status == AE_ALREADY_EXISTS)
-            {
-                /* The name already exists in this scope */
-
-                if (Node->Flags & ANOBJ_IS_EXTERNAL)
-                {
-                    /*
-                     * Allow one create on an object or segment that was
-                     * previously declared External
-                     */
-                    Node->Flags &= ~ANOBJ_IS_EXTERNAL;
-                    Node->Type = (UINT8) ObjectType;
-
-                    /* Just retyped a node, probably will need to open a scope */
-
-                    if (AcpiNsOpensScope (ObjectType))
-                    {
-                        Status = AcpiDsScopeStackPush (
-                            Node, ObjectType, WalkState);
-                        if (ACPI_FAILURE (Status))
-                        {
-                            return_ACPI_STATUS (Status);
-                        }
-                    }
-
-                    Status = AE_OK;
-                }
-            }
-
-            if (ACPI_FAILURE (Status))
-            {
-                ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo, Path, Status);
-                return_ACPI_STATUS (Status);
-            }
-        }
-        break;
-    }
-
-    /* Common exit */
-
-    if (!Op)
-    {
-        /* Create a new op */
-
-        Op = AcpiPsAllocOp (WalkState->Opcode, WalkState->Aml);
-        if (!Op)
-        {
-            return_ACPI_STATUS (AE_NO_MEMORY);
-        }
-    }
-
-    /* Initialize the op */
-
-#ifdef ACPI_CONSTANT_EVAL_ONLY
-    Op->Named.Path = Path;
-#endif
-
-    if (Node)
-    {
-        /*
-         * Put the Node in the "op" object that the parser uses, so we
-         * can get it again quickly when this scope is closed
-         */
-        Op->Common.Node = Node;
-        Op->Named.Name = Node->Name.Integer;
-    }
-
-    AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
-    *OutOp = Op;
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsLoad1EndOp
- *
- * PARAMETERS:  WalkState       - Current state of the parse tree walk
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Ascending callback used during the loading of the namespace,
- *              both control methods and everything else.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsLoad1EndOp (
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_PARSE_OBJECT       *Op;
-    ACPI_OBJECT_TYPE        ObjectType;
-    ACPI_STATUS             Status = AE_OK;
-
-#ifdef ACPI_ASL_COMPILER
-    UINT8                   ParamCount;
-#endif
-
-
-    ACPI_FUNCTION_TRACE (DsLoad1EndOp);
-
-
-    Op = WalkState->Op;
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
-
-    /* We are only interested in opcodes that have an associated name */
-
-    if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Get the object type to determine if we should pop the scope */
-
-    ObjectType = WalkState->OpInfo->ObjectType;
-
-    if (WalkState->OpInfo->Flags & AML_FIELD)
-    {
-        /*
-         * If we are executing a method, do not create any namespace objects
-         * during the load phase, only during execution.
-         */
-        if (!WalkState->MethodNode)
-        {
-            if (WalkState->Opcode == AML_FIELD_OP          ||
-                WalkState->Opcode == AML_BANK_FIELD_OP     ||
-                WalkState->Opcode == AML_INDEX_FIELD_OP)
-            {
-                Status = AcpiDsInitFieldObjects (Op, WalkState);
-            }
-        }
-        return_ACPI_STATUS (Status);
-    }
-
-    /*
-     * If we are executing a method, do not create any namespace objects
-     * during the load phase, only during execution.
-     */
-    if (!WalkState->MethodNode)
-    {
-        if (Op->Common.AmlOpcode == AML_REGION_OP)
-        {
-            Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
-                (ACPI_ADR_SPACE_TYPE)
-                    ((Op->Common.Value.Arg)->Common.Value.Integer),
-                WalkState);
-            if (ACPI_FAILURE (Status))
-            {
-                return_ACPI_STATUS (Status);
-            }
-        }
-        else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
-        {
-            Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
-                ACPI_ADR_SPACE_DATA_TABLE, WalkState);
-            if (ACPI_FAILURE (Status))
-            {
-                return_ACPI_STATUS (Status);
-            }
-        }
-    }
-
-    if (Op->Common.AmlOpcode == AML_NAME_OP)
-    {
-        /* For Name opcode, get the object type from the argument */
-
-        if (Op->Common.Value.Arg)
-        {
-            ObjectType = (AcpiPsGetOpcodeInfo (
-                (Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
-
-            /* Set node type if we have a namespace node */
-
-            if (Op->Common.Node)
-            {
-                Op->Common.Node->Type = (UINT8) ObjectType;
-            }
-        }
-    }
-
-#ifdef ACPI_ASL_COMPILER
-    /*
-     * For external opcode, get the object type from the argument and
-     * get the parameter count from the argument's next.
-     */
-    if (AcpiGbl_DisasmFlag &&
-        Op->Common.Node &&
-        Op->Common.AmlOpcode == AML_EXTERNAL_OP)
-    {
-        /*
-         * Note, if this external is not a method
-         * Op->Common.Value.Arg->Common.Next->Common.Value.Integer == 0
-         * Therefore, ParamCount will be 0.
-         */
-        ParamCount = (UINT8) Op->Common.Value.Arg->Common.Next->Common.Value.Integer;
-        ObjectType = (UINT8) Op->Common.Value.Arg->Common.Value.Integer;
-        Op->Common.Node->Flags |= ANOBJ_IS_EXTERNAL;
-        Op->Common.Node->Type = (UINT8) ObjectType;
-
-        AcpiDmCreateSubobjectForExternal ((UINT8)ObjectType,
-            &Op->Common.Node, ParamCount);
-
-        /*
-         * Add the external to the external list because we may be
-         * emitting code based off of the items within the external list.
-         */
-        AcpiDmAddOpToExternalList (Op, Op->Named.Path, (UINT8)ObjectType, ParamCount,
-           ACPI_EXT_ORIGIN_FROM_OPCODE | ACPI_EXT_RESOLVED_REFERENCE);
-    }
-#endif
-
-    /*
-     * If we are executing a method, do not create any namespace objects
-     * during the load phase, only during execution.
-     */
-    if (!WalkState->MethodNode)
-    {
-        if (Op->Common.AmlOpcode == AML_METHOD_OP)
-        {
-            /*
-             * MethodOp PkgLength NameString MethodFlags TermList
-             *
-             * Note: We must create the method node/object pair as soon as we
-             * see the method declaration. This allows later pass1 parsing
-             * of invocations of the method (need to know the number of
-             * arguments.)
-             */
-            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-                "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
-                WalkState, Op, Op->Named.Node));
-
-            if (!AcpiNsGetAttachedObject (Op->Named.Node))
-            {
-                WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
-                WalkState->NumOperands = 1;
-
-                Status = AcpiDsCreateOperands (
-                    WalkState, Op->Common.Value.Arg);
-                if (ACPI_SUCCESS (Status))
-                {
-                    Status = AcpiExCreateMethod (Op->Named.Data,
-                        Op->Named.Length, WalkState);
-                }
-
-                WalkState->Operands[0] = NULL;
-                WalkState->NumOperands = 0;
-
-                if (ACPI_FAILURE (Status))
-                {
-                    return_ACPI_STATUS (Status);
-                }
-            }
-        }
-    }
-
-    /* Pop the scope stack (only if loading a table) */
-
-    if (!WalkState->MethodNode &&
-        Op->Common.AmlOpcode != AML_EXTERNAL_OP &&
-        AcpiNsOpensScope (ObjectType))
-    {
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
-            AcpiUtGetTypeName (ObjectType), Op));
-
-        Status = AcpiDsScopeStackPop (WalkState);
-    }
-
-    return_ACPI_STATUS (Status);
-}

+ 0 - 763
h2o/localdep/acpica/dispatcher/dswload2.c

@@ -1,763 +0,0 @@
-/******************************************************************************
- *
- * Module Name: dswload2 - Dispatcher second pass namespace load callbacks
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acparser.h"
-#include "amlcode.h"
-#include "acdispat.h"
-#include "acinterp.h"
-#include "acnamesp.h"
-#include "acevents.h"
-
-#define _COMPONENT          ACPI_DISPATCHER
-        ACPI_MODULE_NAME    ("dswload2")
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsLoad2BeginOp
- *
- * PARAMETERS:  WalkState       - Current state of the parse tree walk
- *              OutOp           - Where to return op if a new one is created
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Descending callback used during the loading of ACPI tables.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsLoad2BeginOp (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       **OutOp)
-{
-    ACPI_PARSE_OBJECT       *Op;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_STATUS             Status;
-    ACPI_OBJECT_TYPE        ObjectType;
-    char                    *BufferPtr;
-    UINT32                  Flags;
-
-
-    ACPI_FUNCTION_TRACE (DsLoad2BeginOp);
-
-
-    Op = WalkState->Op;
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
-
-    if (Op)
-    {
-        if ((WalkState->ControlState) &&
-            (WalkState->ControlState->Common.State ==
-                ACPI_CONTROL_CONDITIONAL_EXECUTING))
-        {
-            /* We are executing a while loop outside of a method */
-
-            Status = AcpiDsExecBeginOp (WalkState, OutOp);
-            return_ACPI_STATUS (Status);
-        }
-
-        /* We only care about Namespace opcodes here */
-
-        if ((!(WalkState->OpInfo->Flags & AML_NSOPCODE)   &&
-              (WalkState->Opcode != AML_INT_NAMEPATH_OP)) ||
-            (!(WalkState->OpInfo->Flags & AML_NAMED)))
-        {
-            return_ACPI_STATUS (AE_OK);
-        }
-
-        /* Get the name we are going to enter or lookup in the namespace */
-
-        if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
-        {
-            /* For Namepath op, get the path string */
-
-            BufferPtr = Op->Common.Value.String;
-            if (!BufferPtr)
-            {
-                /* No name, just exit */
-
-                return_ACPI_STATUS (AE_OK);
-            }
-        }
-        else
-        {
-            /* Get name from the op */
-
-            BufferPtr = ACPI_CAST_PTR (char, &Op->Named.Name);
-        }
-    }
-    else
-    {
-        /* Get the namestring from the raw AML */
-
-        BufferPtr = AcpiPsGetNextNamestring (&WalkState->ParserState);
-    }
-
-    /* Map the opcode into an internal object type */
-
-    ObjectType = WalkState->OpInfo->ObjectType;
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-        "State=%p Op=%p Type=%X\n", WalkState, Op, ObjectType));
-
-    switch (WalkState->Opcode)
-    {
-    case AML_FIELD_OP:
-    case AML_BANK_FIELD_OP:
-    case AML_INDEX_FIELD_OP:
-
-        Node = NULL;
-        Status = AE_OK;
-        break;
-
-    case AML_INT_NAMEPATH_OP:
-        /*
-         * The NamePath is an object reference to an existing object.
-         * Don't enter the name into the namespace, but look it up
-         * for use later.
-         */
-        Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
-            ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
-            WalkState, &(Node));
-        break;
-
-    case AML_SCOPE_OP:
-
-        /* Special case for Scope(\) -> refers to the Root node */
-
-        if (Op && (Op->Named.Node == AcpiGbl_RootNode))
-        {
-            Node = Op->Named.Node;
-
-            Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
-            if (ACPI_FAILURE (Status))
-            {
-                return_ACPI_STATUS (Status);
-            }
-        }
-        else
-        {
-            /*
-             * The Path is an object reference to an existing object.
-             * Don't enter the name into the namespace, but look it up
-             * for use later.
-             */
-            Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
-                ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
-                WalkState, &(Node));
-            if (ACPI_FAILURE (Status))
-            {
-#ifdef ACPI_ASL_COMPILER
-                if (Status == AE_NOT_FOUND)
-                {
-                    Status = AE_OK;
-                }
-                else
-                {
-                    ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
-                        BufferPtr, Status);
-                }
-#else
-                ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
-                    BufferPtr, Status);
-#endif
-                return_ACPI_STATUS (Status);
-            }
-        }
-
-        /*
-         * We must check to make sure that the target is
-         * one of the opcodes that actually opens a scope
-         */
-        switch (Node->Type)
-        {
-        case ACPI_TYPE_ANY:
-        case ACPI_TYPE_LOCAL_SCOPE:         /* Scope */
-        case ACPI_TYPE_DEVICE:
-        case ACPI_TYPE_POWER:
-        case ACPI_TYPE_PROCESSOR:
-        case ACPI_TYPE_THERMAL:
-
-            /* These are acceptable types */
-            break;
-
-        case ACPI_TYPE_INTEGER:
-        case ACPI_TYPE_STRING:
-        case ACPI_TYPE_BUFFER:
-
-            /*
-             * These types we will allow, but we will change the type.
-             * This enables some existing code of the form:
-             *
-             *  Name (DEB, 0)
-             *  Scope (DEB) { ... }
-             */
-            ACPI_WARNING ((AE_INFO,
-                "Type override - [%4.4s] had invalid type (%s) "
-                "for Scope operator, changed to type ANY",
-                AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
-
-            Node->Type = ACPI_TYPE_ANY;
-            WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
-            break;
-
-        case ACPI_TYPE_METHOD:
-
-            /*
-             * Allow scope change to root during execution of module-level
-             * code. Root is typed METHOD during this time.
-             */
-            if ((Node == AcpiGbl_RootNode) &&
-                (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
-            {
-                break;
-            }
-
-            /*lint -fallthrough */
-
-        default:
-
-            /* All other types are an error */
-
-            ACPI_ERROR ((AE_INFO,
-                "Invalid type (%s) for target of "
-                "Scope operator [%4.4s] (Cannot override)",
-                AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
-
-            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
-        }
-        break;
-
-    default:
-
-        /* All other opcodes */
-
-        if (Op && Op->Common.Node)
-        {
-            /* This op/node was previously entered into the namespace */
-
-            Node = Op->Common.Node;
-
-            if (AcpiNsOpensScope (ObjectType))
-            {
-                Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
-                if (ACPI_FAILURE (Status))
-                {
-                    return_ACPI_STATUS (Status);
-                }
-            }
-
-            return_ACPI_STATUS (AE_OK);
-        }
-
-        /*
-         * Enter the named type into the internal namespace. We enter the name
-         * as we go downward in the parse tree. Any necessary subobjects that
-         * involve arguments to the opcode must be created as we go back up the
-         * parse tree later.
-         *
-         * Note: Name may already exist if we are executing a deferred opcode.
-         */
-        if (WalkState->DeferredNode)
-        {
-            /* This name is already in the namespace, get the node */
-
-            Node = WalkState->DeferredNode;
-            Status = AE_OK;
-            break;
-        }
-
-        Flags = ACPI_NS_NO_UPSEARCH;
-        if (WalkState->PassNumber == ACPI_IMODE_EXECUTE)
-        {
-            /* Execution mode, node cannot already exist, node is temporary */
-
-            Flags |= ACPI_NS_ERROR_IF_FOUND;
-
-            if (!(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
-            {
-                Flags |= ACPI_NS_TEMPORARY;
-            }
-        }
-
-#ifdef ACPI_ASL_COMPILER
-
-        /*
-         * Do not open a scope for AML_EXTERNAL_OP
-         * AcpiNsLookup can open a new scope based on the object type
-         * of this op. AML_EXTERNAL_OP is a declaration rather than a
-         * definition. In the case that this external is a method object,
-         * AcpiNsLookup will open a new scope. However, an AML_EXTERNAL_OP
-         * associated with the ACPI_TYPE_METHOD is a declaration, rather than
-         * a definition. Flags is set to avoid opening a scope for any
-         * AML_EXTERNAL_OP.
-         */
-        if (WalkState->Opcode == AML_EXTERNAL_OP)
-        {
-            Flags |= ACPI_NS_DONT_OPEN_SCOPE;
-        }
-#endif
-
-        /*
-         * For name creation opcodes, the full namepath prefix must
-         * exist, except for the final (new) nameseg.
-         */
-        if (WalkState->OpInfo->Flags & AML_NAMED)
-        {
-            Flags |= ACPI_NS_PREFIX_MUST_EXIST;
-        }
-
-        /* Add new entry or lookup existing entry */
-
-        Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
-            ACPI_IMODE_LOAD_PASS2, Flags, WalkState, &Node);
-
-        if (ACPI_SUCCESS (Status) && (Flags & ACPI_NS_TEMPORARY))
-        {
-            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-                "***New Node [%4.4s] %p is temporary\n",
-                AcpiUtGetNodeName (Node), Node));
-        }
-        break;
-    }
-
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
-            BufferPtr, Status);
-        return_ACPI_STATUS (Status);
-    }
-
-    if (!Op)
-    {
-        /* Create a new op */
-
-        Op = AcpiPsAllocOp (WalkState->Opcode, WalkState->Aml);
-        if (!Op)
-        {
-            return_ACPI_STATUS (AE_NO_MEMORY);
-        }
-
-        /* Initialize the new op */
-
-        if (Node)
-        {
-            Op->Named.Name = Node->Name.Integer;
-        }
-        *OutOp = Op;
-    }
-
-    /*
-     * Put the Node in the "op" object that the parser uses, so we
-     * can get it again quickly when this scope is closed
-     */
-    Op->Common.Node = Node;
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsLoad2EndOp
- *
- * PARAMETERS:  WalkState       - Current state of the parse tree walk
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Ascending callback used during the loading of the namespace,
- *              both control methods and everything else.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsLoad2EndOp (
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_PARSE_OBJECT       *Op;
-    ACPI_STATUS             Status = AE_OK;
-    ACPI_OBJECT_TYPE        ObjectType;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_PARSE_OBJECT       *Arg;
-    ACPI_NAMESPACE_NODE     *NewNode;
-    UINT32                  i;
-    UINT8                   RegionSpace;
-
-
-    ACPI_FUNCTION_TRACE (DsLoad2EndOp);
-
-    Op = WalkState->Op;
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
-        WalkState->OpInfo->Name, Op, WalkState));
-
-    /* Check if opcode had an associated namespace object */
-
-    if (!(WalkState->OpInfo->Flags & AML_NSOBJECT))
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    if (Op->Common.AmlOpcode == AML_SCOPE_OP)
-    {
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-            "Ending scope Op=%p State=%p\n", Op, WalkState));
-    }
-
-    ObjectType = WalkState->OpInfo->ObjectType;
-
-    /*
-     * Get the Node/name from the earlier lookup
-     * (It was saved in the *op structure)
-     */
-    Node = Op->Common.Node;
-
-    /*
-     * Put the Node on the object stack (Contains the ACPI Name of
-     * this object)
-     */
-    WalkState->Operands[0] = (void *) Node;
-    WalkState->NumOperands = 1;
-
-    /* Pop the scope stack */
-
-    if (AcpiNsOpensScope (ObjectType) &&
-       (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP))
-    {
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
-            AcpiUtGetTypeName (ObjectType), Op));
-
-        Status = AcpiDsScopeStackPop (WalkState);
-        if (ACPI_FAILURE (Status))
-        {
-            goto Cleanup;
-        }
-    }
-
-    /*
-     * Named operations are as follows:
-     *
-     * AML_ALIAS
-     * AML_BANKFIELD
-     * AML_CREATEBITFIELD
-     * AML_CREATEBYTEFIELD
-     * AML_CREATEDWORDFIELD
-     * AML_CREATEFIELD
-     * AML_CREATEQWORDFIELD
-     * AML_CREATEWORDFIELD
-     * AML_DATA_REGION
-     * AML_DEVICE
-     * AML_EVENT
-     * AML_FIELD
-     * AML_INDEXFIELD
-     * AML_METHOD
-     * AML_METHODCALL
-     * AML_MUTEX
-     * AML_NAME
-     * AML_NAMEDFIELD
-     * AML_OPREGION
-     * AML_POWERRES
-     * AML_PROCESSOR
-     * AML_SCOPE
-     * AML_THERMALZONE
-     */
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-        "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
-        AcpiPsGetOpcodeName (Op->Common.AmlOpcode), WalkState, Op, Node));
-
-    /* Decode the opcode */
-
-    Arg = Op->Common.Value.Arg;
-
-    switch (WalkState->OpInfo->Type)
-    {
-
-    case AML_TYPE_CREATE_FIELD:
-        /*
-         * Create the field object, but the field buffer and index must
-         * be evaluated later during the execution phase
-         */
-        Status = AcpiDsCreateBufferField (Op, WalkState);
-        break;
-
-     case AML_TYPE_NAMED_FIELD:
-        /*
-         * If we are executing a method, initialize the field
-         */
-        if (WalkState->MethodNode)
-        {
-            Status = AcpiDsInitFieldObjects (Op, WalkState);
-        }
-
-        switch (Op->Common.AmlOpcode)
-        {
-        case AML_INDEX_FIELD_OP:
-
-            Status = AcpiDsCreateIndexField (
-                Op, (ACPI_HANDLE) Arg->Common.Node, WalkState);
-            break;
-
-        case AML_BANK_FIELD_OP:
-
-            Status = AcpiDsCreateBankField (Op, Arg->Common.Node, WalkState);
-            break;
-
-        case AML_FIELD_OP:
-
-            Status = AcpiDsCreateField (Op, Arg->Common.Node, WalkState);
-            break;
-
-        default:
-
-            /* All NAMED_FIELD opcodes must be handled above */
-            break;
-        }
-        break;
-
-     case AML_TYPE_NAMED_SIMPLE:
-
-        Status = AcpiDsCreateOperands (WalkState, Arg);
-        if (ACPI_FAILURE (Status))
-        {
-            goto Cleanup;
-        }
-
-        switch (Op->Common.AmlOpcode)
-        {
-        case AML_PROCESSOR_OP:
-
-            Status = AcpiExCreateProcessor (WalkState);
-            break;
-
-        case AML_POWER_RESOURCE_OP:
-
-            Status = AcpiExCreatePowerResource (WalkState);
-            break;
-
-        case AML_MUTEX_OP:
-
-            Status = AcpiExCreateMutex (WalkState);
-            break;
-
-        case AML_EVENT_OP:
-
-            Status = AcpiExCreateEvent (WalkState);
-            break;
-
-        case AML_ALIAS_OP:
-
-            Status = AcpiExCreateAlias (WalkState);
-            break;
-
-        default:
-
-            /* Unknown opcode */
-
-            Status = AE_OK;
-            goto Cleanup;
-        }
-
-        /* Delete operands */
-
-        for (i = 1; i < WalkState->NumOperands; i++)
-        {
-            AcpiUtRemoveReference (WalkState->Operands[i]);
-            WalkState->Operands[i] = NULL;
-        }
-
-        break;
-
-    case AML_TYPE_NAMED_COMPLEX:
-
-        switch (Op->Common.AmlOpcode)
-        {
-        case AML_REGION_OP:
-        case AML_DATA_REGION_OP:
-
-            if (Op->Common.AmlOpcode == AML_REGION_OP)
-            {
-                RegionSpace = (ACPI_ADR_SPACE_TYPE)
-                    ((Op->Common.Value.Arg)->Common.Value.Integer);
-            }
-            else
-            {
-                RegionSpace = ACPI_ADR_SPACE_DATA_TABLE;
-            }
-
-            /*
-             * The OpRegion is not fully parsed at this time. The only valid
-             * argument is the SpaceId. (We must save the address of the
-             * AML of the address and length operands)
-             *
-             * If we have a valid region, initialize it. The namespace is
-             * unlocked at this point.
-             *
-             * Need to unlock interpreter if it is locked (if we are running
-             * a control method), in order to allow _REG methods to be run
-             * during AcpiEvInitializeRegion.
-             */
-            if (WalkState->MethodNode)
-            {
-                /*
-                 * Executing a method: initialize the region and unlock
-                 * the interpreter
-                 */
-                Status = AcpiExCreateRegion (Op->Named.Data,
-                    Op->Named.Length, RegionSpace, WalkState);
-                if (ACPI_FAILURE (Status))
-                {
-                    return_ACPI_STATUS (Status);
-                }
-            }
-
-            Status = AcpiEvInitializeRegion (
-                AcpiNsGetAttachedObject (Node));
-            break;
-
-        case AML_NAME_OP:
-
-            Status = AcpiDsCreateNode (WalkState, Node, Op);
-            break;
-
-        case AML_METHOD_OP:
-            /*
-             * MethodOp PkgLength NameString MethodFlags TermList
-             *
-             * Note: We must create the method node/object pair as soon as we
-             * see the method declaration. This allows later pass1 parsing
-             * of invocations of the method (need to know the number of
-             * arguments.)
-             */
-            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-                "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
-                WalkState, Op, Op->Named.Node));
-
-            if (!AcpiNsGetAttachedObject (Op->Named.Node))
-            {
-                WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
-                WalkState->NumOperands = 1;
-
-                Status = AcpiDsCreateOperands (
-                    WalkState, Op->Common.Value.Arg);
-                if (ACPI_SUCCESS (Status))
-                {
-                    Status = AcpiExCreateMethod (
-                        Op->Named.Data, Op->Named.Length, WalkState);
-                }
-
-                WalkState->Operands[0] = NULL;
-                WalkState->NumOperands = 0;
-
-                if (ACPI_FAILURE (Status))
-                {
-                    return_ACPI_STATUS (Status);
-                }
-            }
-            break;
-
-
-        default:
-
-            /* All NAMED_COMPLEX opcodes must be handled above */
-            break;
-        }
-        break;
-
-    case AML_CLASS_INTERNAL:
-
-        /* case AML_INT_NAMEPATH_OP: */
-        break;
-
-    case AML_CLASS_METHOD_CALL:
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-            "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
-            WalkState, Op, Node));
-
-        /*
-         * Lookup the method name and save the Node
-         */
-        Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
-            ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS2,
-            ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
-            WalkState, &(NewNode));
-        if (ACPI_SUCCESS (Status))
-        {
-            /*
-             * Make sure that what we found is indeed a method
-             * We didn't search for a method on purpose, to see if the name
-             * would resolve
-             */
-            if (NewNode->Type != ACPI_TYPE_METHOD)
-            {
-                Status = AE_AML_OPERAND_TYPE;
-            }
-
-            /* We could put the returned object (Node) on the object stack for
-             * later, but for now, we will put it in the "op" object that the
-             * parser uses, so we can get it again at the end of this scope
-             */
-            Op->Common.Node = NewNode;
-        }
-        else
-        {
-            ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
-                Arg->Common.Value.String, Status);
-        }
-        break;
-
-
-    default:
-
-        break;
-    }
-
-Cleanup:
-
-    /* Remove the Node pushed at the very beginning */
-
-    WalkState->Operands[0] = NULL;
-    WalkState->NumOperands = 0;
-    return_ACPI_STATUS (Status);
-}

+ 0 - 233
h2o/localdep/acpica/dispatcher/dswscope.c

@@ -1,233 +0,0 @@
-/******************************************************************************
- *
- * Module Name: dswscope - Scope stack manipulation
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acdispat.h"
-
-
-#define _COMPONENT          ACPI_DISPATCHER
-        ACPI_MODULE_NAME    ("dswscope")
-
-
-/****************************************************************************
- *
- * FUNCTION:    AcpiDsScopeStackClear
- *
- * PARAMETERS:  WalkState       - Current state
- *
- * RETURN:      None
- *
- * DESCRIPTION: Pop (and free) everything on the scope stack except the
- *              root scope object (which remains at the stack top.)
- *
- ***************************************************************************/
-
-void
-AcpiDsScopeStackClear (
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_GENERIC_STATE      *ScopeInfo;
-
-    ACPI_FUNCTION_NAME (DsScopeStackClear);
-
-
-    while (WalkState->ScopeInfo)
-    {
-        /* Pop a scope off the stack */
-
-        ScopeInfo = WalkState->ScopeInfo;
-        WalkState->ScopeInfo = ScopeInfo->Scope.Next;
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-            "Popped object type (%s)\n",
-            AcpiUtGetTypeName (ScopeInfo->Common.Value)));
-
-        AcpiUtDeleteGenericState (ScopeInfo);
-    }
-}
-
-
-/****************************************************************************
- *
- * FUNCTION:    AcpiDsScopeStackPush
- *
- * PARAMETERS:  Node            - Name to be made current
- *              Type            - Type of frame being pushed
- *              WalkState       - Current state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Push the current scope on the scope stack, and make the
- *              passed Node current.
- *
- ***************************************************************************/
-
-ACPI_STATUS
-AcpiDsScopeStackPush (
-    ACPI_NAMESPACE_NODE     *Node,
-    ACPI_OBJECT_TYPE        Type,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_GENERIC_STATE      *ScopeInfo;
-    ACPI_GENERIC_STATE      *OldScopeInfo;
-
-
-    ACPI_FUNCTION_TRACE (DsScopeStackPush);
-
-
-    if (!Node)
-    {
-        /* Invalid scope   */
-
-        ACPI_ERROR ((AE_INFO, "Null scope parameter"));
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    /* Make sure object type is valid */
-
-    if (!AcpiUtValidObjectType (Type))
-    {
-        ACPI_WARNING ((AE_INFO,
-            "Invalid object type: 0x%X", Type));
-    }
-
-    /* Allocate a new scope object */
-
-    ScopeInfo = AcpiUtCreateGenericState ();
-    if (!ScopeInfo)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    /* Init new scope object */
-
-    ScopeInfo->Common.DescriptorType = ACPI_DESC_TYPE_STATE_WSCOPE;
-    ScopeInfo->Scope.Node = Node;
-    ScopeInfo->Common.Value = (UINT16) Type;
-
-    WalkState->ScopeDepth++;
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-        "[%.2d] Pushed scope ", (UINT32) WalkState->ScopeDepth));
-
-    OldScopeInfo = WalkState->ScopeInfo;
-    if (OldScopeInfo)
-    {
-        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
-            "[%4.4s] (%s)",
-            AcpiUtGetNodeName (OldScopeInfo->Scope.Node),
-            AcpiUtGetTypeName (OldScopeInfo->Common.Value)));
-    }
-    else
-    {
-        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, ACPI_NAMESPACE_ROOT));
-    }
-
-    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
-        ", New scope -> [%4.4s] (%s)\n",
-        AcpiUtGetNodeName (ScopeInfo->Scope.Node),
-        AcpiUtGetTypeName (ScopeInfo->Common.Value)));
-
-    /* Push new scope object onto stack */
-
-    AcpiUtPushGenericState (&WalkState->ScopeInfo, ScopeInfo);
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/****************************************************************************
- *
- * FUNCTION:    AcpiDsScopeStackPop
- *
- * PARAMETERS:  WalkState       - Current state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Pop the scope stack once.
- *
- ***************************************************************************/
-
-ACPI_STATUS
-AcpiDsScopeStackPop (
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_GENERIC_STATE      *ScopeInfo;
-    ACPI_GENERIC_STATE      *NewScopeInfo;
-
-
-    ACPI_FUNCTION_TRACE (DsScopeStackPop);
-
-
-    /*
-     * Pop scope info object off the stack.
-     */
-    ScopeInfo = AcpiUtPopGenericState (&WalkState->ScopeInfo);
-    if (!ScopeInfo)
-    {
-        return_ACPI_STATUS (AE_STACK_UNDERFLOW);
-    }
-
-    WalkState->ScopeDepth--;
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-        "[%.2d] Popped scope [%4.4s] (%s), New scope -> ",
-        (UINT32) WalkState->ScopeDepth,
-        AcpiUtGetNodeName (ScopeInfo->Scope.Node),
-        AcpiUtGetTypeName (ScopeInfo->Common.Value)));
-
-    NewScopeInfo = WalkState->ScopeInfo;
-    if (NewScopeInfo)
-    {
-        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "[%4.4s] (%s)\n",
-            AcpiUtGetNodeName (NewScopeInfo->Scope.Node),
-            AcpiUtGetTypeName (NewScopeInfo->Common.Value)));
-    }
-    else
-    {
-        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "%s\n", ACPI_NAMESPACE_ROOT));
-    }
-
-    AcpiUtDeleteGenericState (ScopeInfo);
-    return_ACPI_STATUS (AE_OK);
-}

+ 0 - 842
h2o/localdep/acpica/dispatcher/dswstate.c

@@ -1,842 +0,0 @@
-/******************************************************************************
- *
- * Module Name: dswstate - Dispatcher parse tree walk management routines
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acparser.h"
-#include "acdispat.h"
-#include "acnamesp.h"
-
-#define _COMPONENT          ACPI_DISPATCHER
-        ACPI_MODULE_NAME    ("dswstate")
-
-/* Local prototypes */
-
-static ACPI_STATUS
-AcpiDsResultStackPush (
-    ACPI_WALK_STATE         *WalkState);
-
-static ACPI_STATUS
-AcpiDsResultStackPop (
-    ACPI_WALK_STATE         *WalkState);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsResultPop
- *
- * PARAMETERS:  Object              - Where to return the popped object
- *              WalkState           - Current Walk state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Pop an object off the top of this walk's result stack
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsResultPop (
-    ACPI_OPERAND_OBJECT     **Object,
-    ACPI_WALK_STATE         *WalkState)
-{
-    UINT32                  Index;
-    ACPI_GENERIC_STATE      *State;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_NAME (DsResultPop);
-
-
-    State = WalkState->Results;
-
-    /* Incorrect state of result stack */
-
-    if (State && !WalkState->ResultCount)
-    {
-        ACPI_ERROR ((AE_INFO, "No results on result stack"));
-        return (AE_AML_INTERNAL);
-    }
-
-    if (!State && WalkState->ResultCount)
-    {
-        ACPI_ERROR ((AE_INFO, "No result state for result stack"));
-        return (AE_AML_INTERNAL);
-    }
-
-    /* Empty result stack */
-
-    if (!State)
-    {
-        ACPI_ERROR ((AE_INFO, "Result stack is empty! State=%p", WalkState));
-        return (AE_AML_NO_RETURN_VALUE);
-    }
-
-    /* Return object of the top element and clean that top element result stack */
-
-    WalkState->ResultCount--;
-    Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM;
-
-    *Object = State->Results.ObjDesc [Index];
-    if (!*Object)
-    {
-        ACPI_ERROR ((AE_INFO, "No result objects on result stack, State=%p",
-            WalkState));
-        return (AE_AML_NO_RETURN_VALUE);
-    }
-
-    State->Results.ObjDesc [Index] = NULL;
-    if (Index == 0)
-    {
-        Status = AcpiDsResultStackPop (WalkState);
-        if (ACPI_FAILURE (Status))
-        {
-            return (Status);
-        }
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-        "Obj=%p [%s] Index=%X State=%p Num=%X\n", *Object,
-        AcpiUtGetObjectTypeName (*Object),
-        Index, WalkState, WalkState->ResultCount));
-
-    return (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsResultPush
- *
- * PARAMETERS:  Object              - Where to return the popped object
- *              WalkState           - Current Walk state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Push an object onto the current result stack
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsResultPush (
-    ACPI_OPERAND_OBJECT     *Object,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_GENERIC_STATE      *State;
-    ACPI_STATUS             Status;
-    UINT32                  Index;
-
-
-    ACPI_FUNCTION_NAME (DsResultPush);
-
-
-    if (WalkState->ResultCount > WalkState->ResultSize)
-    {
-        ACPI_ERROR ((AE_INFO, "Result stack is full"));
-        return (AE_AML_INTERNAL);
-    }
-    else if (WalkState->ResultCount == WalkState->ResultSize)
-    {
-        /* Extend the result stack */
-
-        Status = AcpiDsResultStackPush (WalkState);
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_ERROR ((AE_INFO, "Failed to extend the result stack"));
-            return (Status);
-        }
-    }
-
-    if (!(WalkState->ResultCount < WalkState->ResultSize))
-    {
-        ACPI_ERROR ((AE_INFO, "No free elements in result stack"));
-        return (AE_AML_INTERNAL);
-    }
-
-    State = WalkState->Results;
-    if (!State)
-    {
-        ACPI_ERROR ((AE_INFO, "No result stack frame during push"));
-        return (AE_AML_INTERNAL);
-    }
-
-    if (!Object)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "Null Object! Obj=%p State=%p Num=%u",
-            Object, WalkState, WalkState->ResultCount));
-        return (AE_BAD_PARAMETER);
-    }
-
-    /* Assign the address of object to the top free element of result stack */
-
-    Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM;
-    State->Results.ObjDesc [Index] = Object;
-    WalkState->ResultCount++;
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
-        Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object),
-        WalkState, WalkState->ResultCount, WalkState->CurrentResult));
-
-    return (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsResultStackPush
- *
- * PARAMETERS:  WalkState           - Current Walk state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Push an object onto the WalkState result stack
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiDsResultStackPush (
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_GENERIC_STATE      *State;
-
-
-    ACPI_FUNCTION_NAME (DsResultStackPush);
-
-
-    /* Check for stack overflow */
-
-    if (((UINT32) WalkState->ResultSize + ACPI_RESULTS_FRAME_OBJ_NUM) >
-        ACPI_RESULTS_OBJ_NUM_MAX)
-    {
-        ACPI_ERROR ((AE_INFO, "Result stack overflow: State=%p Num=%u",
-            WalkState, WalkState->ResultSize));
-        return (AE_STACK_OVERFLOW);
-    }
-
-    State = AcpiUtCreateGenericState ();
-    if (!State)
-    {
-        return (AE_NO_MEMORY);
-    }
-
-    State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RESULT;
-    AcpiUtPushGenericState (&WalkState->Results, State);
-
-    /* Increase the length of the result stack by the length of frame */
-
-    WalkState->ResultSize += ACPI_RESULTS_FRAME_OBJ_NUM;
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Results=%p State=%p\n",
-        State, WalkState));
-
-    return (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsResultStackPop
- *
- * PARAMETERS:  WalkState           - Current Walk state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Pop an object off of the WalkState result stack
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiDsResultStackPop (
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_GENERIC_STATE      *State;
-
-
-    ACPI_FUNCTION_NAME (DsResultStackPop);
-
-
-    /* Check for stack underflow */
-
-    if (WalkState->Results == NULL)
-    {
-        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-            "Result stack underflow - State=%p\n", WalkState));
-        return (AE_AML_NO_OPERAND);
-    }
-
-    if (WalkState->ResultSize < ACPI_RESULTS_FRAME_OBJ_NUM)
-    {
-        ACPI_ERROR ((AE_INFO, "Insufficient result stack size"));
-        return (AE_AML_INTERNAL);
-    }
-
-    State = AcpiUtPopGenericState (&WalkState->Results);
-    AcpiUtDeleteGenericState (State);
-
-    /* Decrease the length of result stack by the length of frame */
-
-    WalkState->ResultSize -= ACPI_RESULTS_FRAME_OBJ_NUM;
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-        "Result=%p RemainingResults=%X State=%p\n",
-        State, WalkState->ResultCount, WalkState));
-
-    return (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsObjStackPush
- *
- * PARAMETERS:  Object              - Object to push
- *              WalkState           - Current Walk state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Push an object onto this walk's object/operand stack
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsObjStackPush (
-    void                    *Object,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_FUNCTION_NAME (DsObjStackPush);
-
-
-    /* Check for stack overflow */
-
-    if (WalkState->NumOperands >= ACPI_OBJ_NUM_OPERANDS)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "Object stack overflow! Obj=%p State=%p #Ops=%u",
-            Object, WalkState, WalkState->NumOperands));
-        return (AE_STACK_OVERFLOW);
-    }
-
-    /* Put the object onto the stack */
-
-    WalkState->Operands [WalkState->OperandIndex] = Object;
-    WalkState->NumOperands++;
-
-    /* For the usual order of filling the operand stack */
-
-    WalkState->OperandIndex++;
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
-        Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object),
-        WalkState, WalkState->NumOperands));
-
-    return (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsObjStackPop
- *
- * PARAMETERS:  PopCount            - Number of objects/entries to pop
- *              WalkState           - Current Walk state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
- *              deleted by this routine.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsObjStackPop (
-    UINT32                  PopCount,
-    ACPI_WALK_STATE         *WalkState)
-{
-    UINT32                  i;
-
-
-    ACPI_FUNCTION_NAME (DsObjStackPop);
-
-
-    for (i = 0; i < PopCount; i++)
-    {
-        /* Check for stack underflow */
-
-        if (WalkState->NumOperands == 0)
-        {
-            ACPI_ERROR ((AE_INFO,
-                "Object stack underflow! Count=%X State=%p #Ops=%u",
-                PopCount, WalkState, WalkState->NumOperands));
-            return (AE_STACK_UNDERFLOW);
-        }
-
-        /* Just set the stack entry to null */
-
-        WalkState->NumOperands--;
-        WalkState->Operands [WalkState->NumOperands] = NULL;
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%u\n",
-        PopCount, WalkState, WalkState->NumOperands));
-
-    return (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsObjStackPopAndDelete
- *
- * PARAMETERS:  PopCount            - Number of objects/entries to pop
- *              WalkState           - Current Walk state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Pop this walk's object stack and delete each object that is
- *              popped off.
- *
- ******************************************************************************/
-
-void
-AcpiDsObjStackPopAndDelete (
-    UINT32                  PopCount,
-    ACPI_WALK_STATE         *WalkState)
-{
-    INT32                   i;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-
-
-    ACPI_FUNCTION_NAME (DsObjStackPopAndDelete);
-
-
-    if (PopCount == 0)
-    {
-        return;
-    }
-
-    for (i = (INT32) PopCount - 1; i >= 0; i--)
-    {
-        if (WalkState->NumOperands == 0)
-        {
-            return;
-        }
-
-        /* Pop the stack and delete an object if present in this stack entry */
-
-        WalkState->NumOperands--;
-        ObjDesc = WalkState->Operands [i];
-        if (ObjDesc)
-        {
-            AcpiUtRemoveReference (WalkState->Operands [i]);
-            WalkState->Operands [i] = NULL;
-        }
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
-        PopCount, WalkState, WalkState->NumOperands));
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsGetCurrentWalkState
- *
- * PARAMETERS:  Thread          - Get current active state for this Thread
- *
- * RETURN:      Pointer to the current walk state
- *
- * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
- *              walk state.)
- *
- ******************************************************************************/
-
-ACPI_WALK_STATE *
-AcpiDsGetCurrentWalkState (
-    ACPI_THREAD_STATE       *Thread)
-{
-    ACPI_FUNCTION_NAME (DsGetCurrentWalkState);
-
-
-    if (!Thread)
-    {
-        return (NULL);
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Current WalkState %p\n",
-        Thread->WalkStateList));
-
-    return (Thread->WalkStateList);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsPushWalkState
- *
- * PARAMETERS:  WalkState       - State to push
- *              Thread          - Thread state object
- *
- * RETURN:      None
- *
- * DESCRIPTION: Place the Thread state at the head of the state list
- *
- ******************************************************************************/
-
-void
-AcpiDsPushWalkState (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_THREAD_STATE       *Thread)
-{
-    ACPI_FUNCTION_TRACE (DsPushWalkState);
-
-
-    WalkState->Next = Thread->WalkStateList;
-    Thread->WalkStateList = WalkState;
-
-    return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsPopWalkState
- *
- * PARAMETERS:  Thread      - Current thread state
- *
- * RETURN:      A WalkState object popped from the thread's stack
- *
- * DESCRIPTION: Remove and return the walkstate object that is at the head of
- *              the walk stack for the given walk list. NULL indicates that
- *              the list is empty.
- *
- ******************************************************************************/
-
-ACPI_WALK_STATE *
-AcpiDsPopWalkState (
-    ACPI_THREAD_STATE       *Thread)
-{
-    ACPI_WALK_STATE         *WalkState;
-
-
-    ACPI_FUNCTION_TRACE (DsPopWalkState);
-
-
-    WalkState = Thread->WalkStateList;
-
-    if (WalkState)
-    {
-        /* Next walk state becomes the current walk state */
-
-        Thread->WalkStateList = WalkState->Next;
-
-        /*
-         * Don't clear the NEXT field, this serves as an indicator
-         * that there is a parent WALK STATE
-         * Do Not: WalkState->Next = NULL;
-         */
-    }
-
-    return_PTR (WalkState);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsCreateWalkState
- *
- * PARAMETERS:  OwnerId         - ID for object creation
- *              Origin          - Starting point for this walk
- *              MethodDesc      - Method object
- *              Thread          - Current thread state
- *
- * RETURN:      Pointer to the new walk state.
- *
- * DESCRIPTION: Allocate and initialize a new walk state. The current walk
- *              state is set to this new state.
- *
- ******************************************************************************/
-
-ACPI_WALK_STATE *
-AcpiDsCreateWalkState (
-    ACPI_OWNER_ID           OwnerId,
-    ACPI_PARSE_OBJECT       *Origin,
-    ACPI_OPERAND_OBJECT     *MethodDesc,
-    ACPI_THREAD_STATE       *Thread)
-{
-    ACPI_WALK_STATE         *WalkState;
-
-
-    ACPI_FUNCTION_TRACE (DsCreateWalkState);
-
-
-    WalkState = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_WALK_STATE));
-    if (!WalkState)
-    {
-        return_PTR (NULL);
-    }
-
-    WalkState->DescriptorType = ACPI_DESC_TYPE_WALK;
-    WalkState->MethodDesc = MethodDesc;
-    WalkState->OwnerId = OwnerId;
-    WalkState->Origin = Origin;
-    WalkState->Thread = Thread;
-
-    WalkState->ParserState.StartOp = Origin;
-
-    /* Init the method args/local */
-
-#ifndef ACPI_CONSTANT_EVAL_ONLY
-    AcpiDsMethodDataInit (WalkState);
-#endif
-
-    /* Put the new state at the head of the walk list */
-
-    if (Thread)
-    {
-        AcpiDsPushWalkState (WalkState, Thread);
-    }
-
-    return_PTR (WalkState);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsInitAmlWalk
- *
- * PARAMETERS:  WalkState       - New state to be initialized
- *              Op              - Current parse op
- *              MethodNode      - Control method NS node, if any
- *              AmlStart        - Start of AML
- *              AmlLength       - Length of AML
- *              Info            - Method info block (params, etc.)
- *              PassNumber      - 1, 2, or 3
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDsInitAmlWalk (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_PARSE_OBJECT       *Op,
-    ACPI_NAMESPACE_NODE     *MethodNode,
-    UINT8                   *AmlStart,
-    UINT32                  AmlLength,
-    ACPI_EVALUATE_INFO      *Info,
-    UINT8                   PassNumber)
-{
-    ACPI_STATUS             Status;
-    ACPI_PARSE_STATE        *ParserState = &WalkState->ParserState;
-    ACPI_PARSE_OBJECT       *ExtraOp;
-
-
-    ACPI_FUNCTION_TRACE (DsInitAmlWalk);
-
-
-    WalkState->ParserState.Aml =
-    WalkState->ParserState.AmlStart = AmlStart;
-    WalkState->ParserState.AmlEnd =
-    WalkState->ParserState.PkgEnd = AmlStart + AmlLength;
-
-    /* The NextOp of the NextWalk will be the beginning of the method */
-
-    WalkState->NextOp = NULL;
-    WalkState->PassNumber = PassNumber;
-
-    if (Info)
-    {
-        WalkState->Params = Info->Parameters;
-        WalkState->CallerReturnDesc = &Info->ReturnObject;
-    }
-
-    Status = AcpiPsInitScope (&WalkState->ParserState, Op);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    if (MethodNode)
-    {
-        WalkState->ParserState.StartNode = MethodNode;
-        WalkState->WalkType = ACPI_WALK_METHOD;
-        WalkState->MethodNode = MethodNode;
-        WalkState->MethodDesc = AcpiNsGetAttachedObject (MethodNode);
-
-        /* Push start scope on scope stack and make it current  */
-
-        Status = AcpiDsScopeStackPush (
-            MethodNode, ACPI_TYPE_METHOD, WalkState);
-        if (ACPI_FAILURE (Status))
-        {
-            return_ACPI_STATUS (Status);
-        }
-
-        /* Init the method arguments */
-
-        Status = AcpiDsMethodDataInitArgs (WalkState->Params,
-                    ACPI_METHOD_NUM_ARGS, WalkState);
-        if (ACPI_FAILURE (Status))
-        {
-            return_ACPI_STATUS (Status);
-        }
-    }
-    else
-    {
-        /*
-         * Setup the current scope.
-         * Find a Named Op that has a namespace node associated with it.
-         * search upwards from this Op. Current scope is the first
-         * Op with a namespace node.
-         */
-        ExtraOp = ParserState->StartOp;
-        while (ExtraOp && !ExtraOp->Common.Node)
-        {
-            ExtraOp = ExtraOp->Common.Parent;
-        }
-
-        if (!ExtraOp)
-        {
-            ParserState->StartNode = NULL;
-        }
-        else
-        {
-            ParserState->StartNode = ExtraOp->Common.Node;
-        }
-
-        if (ParserState->StartNode)
-        {
-            /* Push start scope on scope stack and make it current  */
-
-            Status = AcpiDsScopeStackPush (ParserState->StartNode,
-                ParserState->StartNode->Type, WalkState);
-            if (ACPI_FAILURE (Status))
-            {
-                return_ACPI_STATUS (Status);
-            }
-        }
-    }
-
-    Status = AcpiDsInitCallbacks (WalkState, PassNumber);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDsDeleteWalkState
- *
- * PARAMETERS:  WalkState       - State to delete
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Delete a walk state including all internal data structures
- *
- ******************************************************************************/
-
-void
-AcpiDsDeleteWalkState (
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_GENERIC_STATE      *State;
-
-
-    ACPI_FUNCTION_TRACE_PTR (DsDeleteWalkState, WalkState);
-
-
-    if (!WalkState)
-    {
-        return_VOID;
-    }
-
-    if (WalkState->DescriptorType != ACPI_DESC_TYPE_WALK)
-    {
-        ACPI_ERROR ((AE_INFO, "%p is not a valid walk state",
-            WalkState));
-        return_VOID;
-    }
-
-    /* There should not be any open scopes */
-
-    if (WalkState->ParserState.Scope)
-    {
-        ACPI_ERROR ((AE_INFO, "%p walk still has a scope list",
-            WalkState));
-        AcpiPsCleanupScope (&WalkState->ParserState);
-    }
-
-    /* Always must free any linked control states */
-
-    while (WalkState->ControlState)
-    {
-        State = WalkState->ControlState;
-        WalkState->ControlState = State->Common.Next;
-
-        AcpiUtDeleteGenericState (State);
-    }
-
-    /* Always must free any linked parse states */
-
-    while (WalkState->ScopeInfo)
-    {
-        State = WalkState->ScopeInfo;
-        WalkState->ScopeInfo = State->Common.Next;
-
-        AcpiUtDeleteGenericState (State);
-    }
-
-    /* Always must free any stacked result states */
-
-    while (WalkState->Results)
-    {
-        State = WalkState->Results;
-        WalkState->Results = State->Common.Next;
-
-        AcpiUtDeleteGenericState (State);
-    }
-
-    ACPI_FREE (WalkState);
-    return_VOID;
-}

+ 0 - 341
h2o/localdep/acpica/events/evevent.c

@@ -1,341 +0,0 @@
-/******************************************************************************
- *
- * Module Name: evevent - Fixed Event handling and dispatch
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acevents.h"
-
-#define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evevent")
-
-#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
-
-/* Local prototypes */
-
-static ACPI_STATUS
-AcpiEvFixedEventInitialize (
-    void);
-
-static UINT32
-AcpiEvFixedEventDispatch (
-    UINT32                  Event);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvInitializeEvents
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Initialize global data structures for ACPI events (Fixed, GPE)
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvInitializeEvents (
-    void)
-{
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (EvInitializeEvents);
-
-
-    /* If Hardware Reduced flag is set, there are no fixed events */
-
-    if (AcpiGbl_ReducedHardware)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /*
-     * Initialize the Fixed and General Purpose Events. This is done prior to
-     * enabling SCIs to prevent interrupts from occurring before the handlers
-     * are installed.
-     */
-    Status = AcpiEvFixedEventInitialize ();
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_EXCEPTION ((AE_INFO, Status,
-            "Unable to initialize fixed events"));
-        return_ACPI_STATUS (Status);
-    }
-
-    Status = AcpiEvGpeInitialize ();
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_EXCEPTION ((AE_INFO, Status,
-            "Unable to initialize general purpose events"));
-        return_ACPI_STATUS (Status);
-    }
-
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvInstallXruptHandlers
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvInstallXruptHandlers (
-    void)
-{
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (EvInstallXruptHandlers);
-
-
-    /* If Hardware Reduced flag is set, there is no ACPI h/w */
-
-    if (AcpiGbl_ReducedHardware)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Install the SCI handler */
-
-    Status = AcpiEvInstallSciHandler ();
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_EXCEPTION ((AE_INFO, Status,
-            "Unable to install System Control Interrupt handler"));
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Install the handler for the Global Lock */
-
-    Status = AcpiEvInitGlobalLockHandler ();
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_EXCEPTION ((AE_INFO, Status,
-            "Unable to initialize Global Lock handler"));
-        return_ACPI_STATUS (Status);
-    }
-
-    AcpiGbl_EventsInitialized = TRUE;
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvFixedEventInitialize
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Install the fixed event handlers and disable all fixed events.
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiEvFixedEventInitialize (
-    void)
-{
-    UINT32                  i;
-    ACPI_STATUS             Status;
-
-
-    /*
-     * Initialize the structure that keeps track of fixed event handlers and
-     * enable the fixed events.
-     */
-    for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
-    {
-        AcpiGbl_FixedEventHandlers[i].Handler = NULL;
-        AcpiGbl_FixedEventHandlers[i].Context = NULL;
-
-        /* Disable the fixed event */
-
-        if (AcpiGbl_FixedEventInfo[i].EnableRegisterId != 0xFF)
-        {
-            Status = AcpiWriteBitRegister (
-                AcpiGbl_FixedEventInfo[i].EnableRegisterId,
-                ACPI_DISABLE_EVENT);
-            if (ACPI_FAILURE (Status))
-            {
-                return (Status);
-            }
-        }
-    }
-
-    return (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvFixedEventDetect
- *
- * PARAMETERS:  None
- *
- * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
- *
- * DESCRIPTION: Checks the PM status register for active fixed events
- *
- ******************************************************************************/
-
-UINT32
-AcpiEvFixedEventDetect (
-    void)
-{
-    UINT32                  IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
-    UINT32                  FixedStatus;
-    UINT32                  FixedEnable;
-    UINT32                  i;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_NAME (EvFixedEventDetect);
-
-
-    /*
-     * Read the fixed feature status and enable registers, as all the cases
-     * depend on their values. Ignore errors here.
-     */
-    Status = AcpiHwRegisterRead (ACPI_REGISTER_PM1_STATUS, &FixedStatus);
-    Status |= AcpiHwRegisterRead (ACPI_REGISTER_PM1_ENABLE, &FixedEnable);
-    if (ACPI_FAILURE (Status))
-    {
-        return (IntStatus);
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
-        "Fixed Event Block: Enable %08X Status %08X\n",
-        FixedEnable, FixedStatus));
-
-    /*
-     * Check for all possible Fixed Events and dispatch those that are active
-     */
-    for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
-    {
-        /* Both the status and enable bits must be on for this event */
-
-        if ((FixedStatus & AcpiGbl_FixedEventInfo[i].StatusBitMask) &&
-            (FixedEnable & AcpiGbl_FixedEventInfo[i].EnableBitMask))
-        {
-            /*
-             * Found an active (signalled) event. Invoke global event
-             * handler if present.
-             */
-            AcpiFixedEventCount[i]++;
-            if (AcpiGbl_GlobalEventHandler)
-            {
-                AcpiGbl_GlobalEventHandler (ACPI_EVENT_TYPE_FIXED, NULL,
-                     i, AcpiGbl_GlobalEventHandlerContext);
-            }
-
-            IntStatus |= AcpiEvFixedEventDispatch (i);
-        }
-    }
-
-    return (IntStatus);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvFixedEventDispatch
- *
- * PARAMETERS:  Event               - Event type
- *
- * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
- *
- * DESCRIPTION: Clears the status bit for the requested event, calls the
- *              handler that previously registered for the event.
- *              NOTE: If there is no handler for the event, the event is
- *              disabled to prevent further interrupts.
- *
- ******************************************************************************/
-
-static UINT32
-AcpiEvFixedEventDispatch (
-    UINT32                  Event)
-{
-
-    ACPI_FUNCTION_ENTRY ();
-
-
-    /* Clear the status bit */
-
-    (void) AcpiWriteBitRegister (
-        AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
-        ACPI_CLEAR_STATUS);
-
-    /*
-     * Make sure that a handler exists. If not, report an error
-     * and disable the event to prevent further interrupts.
-     */
-    if (!AcpiGbl_FixedEventHandlers[Event].Handler)
-    {
-        (void) AcpiWriteBitRegister (
-            AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
-            ACPI_DISABLE_EVENT);
-
-        ACPI_ERROR ((AE_INFO,
-            "No installed handler for fixed event - %s (%u), disabling",
-            AcpiUtGetEventName (Event), Event));
-
-        return (ACPI_INTERRUPT_NOT_HANDLED);
-    }
-
-    /* Invoke the Fixed Event handler */
-
-    return ((AcpiGbl_FixedEventHandlers[Event].Handler)(
-        AcpiGbl_FixedEventHandlers[Event].Context));
-}
-
-#endif /* !ACPI_REDUCED_HARDWARE */

+ 0 - 379
h2o/localdep/acpica/events/evglock.c

@@ -1,379 +0,0 @@
-/******************************************************************************
- *
- * Module Name: evglock - Global Lock support
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acevents.h"
-#include "acinterp.h"
-
-#define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evglock")
-
-#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
-
-/* Local prototypes */
-
-static UINT32
-AcpiEvGlobalLockHandler (
-    void                    *Context);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvInitGlobalLockHandler
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Install a handler for the global lock release event
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvInitGlobalLockHandler (
-    void)
-{
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (EvInitGlobalLockHandler);
-
-
-    /* If Hardware Reduced flag is set, there is no global lock */
-
-    if (AcpiGbl_ReducedHardware)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Attempt installation of the global lock handler */
-
-    Status = AcpiInstallFixedEventHandler (ACPI_EVENT_GLOBAL,
-        AcpiEvGlobalLockHandler, NULL);
-
-    /*
-     * If the global lock does not exist on this platform, the attempt to
-     * enable GBL_STATUS will fail (the GBL_ENABLE bit will not stick).
-     * Map to AE_OK, but mark global lock as not present. Any attempt to
-     * actually use the global lock will be flagged with an error.
-     */
-    AcpiGbl_GlobalLockPresent = FALSE;
-    if (Status == AE_NO_HARDWARE_RESPONSE)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "No response from Global Lock hardware, disabling lock"));
-
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    Status = AcpiOsCreateLock (&AcpiGbl_GlobalLockPendingLock);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    AcpiGbl_GlobalLockPending = FALSE;
-    AcpiGbl_GlobalLockPresent = TRUE;
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvRemoveGlobalLockHandler
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Remove the handler for the Global Lock
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvRemoveGlobalLockHandler (
-    void)
-{
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (EvRemoveGlobalLockHandler);
-
-
-    AcpiGbl_GlobalLockPresent = FALSE;
-    Status = AcpiRemoveFixedEventHandler (ACPI_EVENT_GLOBAL,
-        AcpiEvGlobalLockHandler);
-
-    AcpiOsDeleteLock (AcpiGbl_GlobalLockPendingLock);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvGlobalLockHandler
- *
- * PARAMETERS:  Context         - From thread interface, not used
- *
- * RETURN:      ACPI_INTERRUPT_HANDLED
- *
- * DESCRIPTION: Invoked directly from the SCI handler when a global lock
- *              release interrupt occurs. If there is actually a pending
- *              request for the lock, signal the waiting thread.
- *
- ******************************************************************************/
-
-static UINT32
-AcpiEvGlobalLockHandler (
-    void                    *Context)
-{
-    ACPI_STATUS             Status;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GlobalLockPendingLock);
-
-    /*
-     * If a request for the global lock is not actually pending,
-     * we are done. This handles "spurious" global lock interrupts
-     * which are possible (and have been seen) with bad BIOSs.
-     */
-    if (!AcpiGbl_GlobalLockPending)
-    {
-        goto CleanupAndExit;
-    }
-
-    /*
-     * Send a unit to the global lock semaphore. The actual acquisition
-     * of the global lock will be performed by the waiting thread.
-     */
-    Status = AcpiOsSignalSemaphore (AcpiGbl_GlobalLockSemaphore, 1);
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_ERROR ((AE_INFO, "Could not signal Global Lock semaphore"));
-    }
-
-    AcpiGbl_GlobalLockPending = FALSE;
-
-
-CleanupAndExit:
-
-    AcpiOsReleaseLock (AcpiGbl_GlobalLockPendingLock, Flags);
-    return (ACPI_INTERRUPT_HANDLED);
-}
-
-
-/******************************************************************************
- *
- * FUNCTION:    AcpiEvAcquireGlobalLock
- *
- * PARAMETERS:  Timeout         - Max time to wait for the lock, in millisec.
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Attempt to gain ownership of the Global Lock.
- *
- * MUTEX:       Interpreter must be locked
- *
- * Note: The original implementation allowed multiple threads to "acquire" the
- * Global Lock, and the OS would hold the lock until the last thread had
- * released it. However, this could potentially starve the BIOS out of the
- * lock, especially in the case where there is a tight handshake between the
- * Embedded Controller driver and the BIOS. Therefore, this implementation
- * allows only one thread to acquire the HW Global Lock at a time, and makes
- * the global lock appear as a standard mutex on the OS side.
- *
- *****************************************************************************/
-
-ACPI_STATUS
-AcpiEvAcquireGlobalLock (
-    UINT16                  Timeout)
-{
-    ACPI_CPU_FLAGS          Flags;
-    ACPI_STATUS             Status;
-    BOOLEAN                 Acquired = FALSE;
-
-
-    ACPI_FUNCTION_TRACE (EvAcquireGlobalLock);
-
-
-    /*
-     * Only one thread can acquire the GL at a time, the GlobalLockMutex
-     * enforces this. This interface releases the interpreter if we must wait.
-     */
-    Status = AcpiExSystemWaitMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex,
-                Timeout);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /*
-     * Update the global lock handle and check for wraparound. The handle is
-     * only used for the external global lock interfaces, but it is updated
-     * here to properly handle the case where a single thread may acquire the
-     * lock via both the AML and the AcpiAcquireGlobalLock interfaces. The
-     * handle is therefore updated on the first acquire from a given thread
-     * regardless of where the acquisition request originated.
-     */
-    AcpiGbl_GlobalLockHandle++;
-    if (AcpiGbl_GlobalLockHandle == 0)
-    {
-        AcpiGbl_GlobalLockHandle = 1;
-    }
-
-    /*
-     * Make sure that a global lock actually exists. If not, just
-     * treat the lock as a standard mutex.
-     */
-    if (!AcpiGbl_GlobalLockPresent)
-    {
-        AcpiGbl_GlobalLockAcquired = TRUE;
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GlobalLockPendingLock);
-
-    do
-    {
-        /* Attempt to acquire the actual hardware lock */
-
-        ACPI_ACQUIRE_GLOBAL_LOCK (AcpiGbl_FACS, Acquired);
-        if (Acquired)
-        {
-            AcpiGbl_GlobalLockAcquired = TRUE;
-            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-                "Acquired hardware Global Lock\n"));
-            break;
-        }
-
-        /*
-         * Did not get the lock. The pending bit was set above, and
-         * we must now wait until we receive the global lock
-         * released interrupt.
-         */
-        AcpiGbl_GlobalLockPending = TRUE;
-        AcpiOsReleaseLock (AcpiGbl_GlobalLockPendingLock, Flags);
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-            "Waiting for hardware Global Lock\n"));
-
-        /*
-         * Wait for handshake with the global lock interrupt handler.
-         * This interface releases the interpreter if we must wait.
-         */
-        Status = AcpiExSystemWaitSemaphore (
-            AcpiGbl_GlobalLockSemaphore, ACPI_WAIT_FOREVER);
-
-        Flags = AcpiOsAcquireLock (AcpiGbl_GlobalLockPendingLock);
-
-    } while (ACPI_SUCCESS (Status));
-
-    AcpiGbl_GlobalLockPending = FALSE;
-    AcpiOsReleaseLock (AcpiGbl_GlobalLockPendingLock, Flags);
-
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvReleaseGlobalLock
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Releases ownership of the Global Lock.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvReleaseGlobalLock (
-    void)
-{
-    BOOLEAN                 Pending = FALSE;
-    ACPI_STATUS             Status = AE_OK;
-
-
-    ACPI_FUNCTION_TRACE (EvReleaseGlobalLock);
-
-
-    /* Lock must be already acquired */
-
-    if (!AcpiGbl_GlobalLockAcquired)
-    {
-        ACPI_WARNING ((AE_INFO,
-            "Cannot release the ACPI Global Lock, it has not been acquired"));
-        return_ACPI_STATUS (AE_NOT_ACQUIRED);
-    }
-
-    if (AcpiGbl_GlobalLockPresent)
-    {
-        /* Allow any thread to release the lock */
-
-        ACPI_RELEASE_GLOBAL_LOCK (AcpiGbl_FACS, Pending);
-
-        /*
-         * If the pending bit was set, we must write GBL_RLS to the control
-         * register
-         */
-        if (Pending)
-        {
-            Status = AcpiWriteBitRegister (
-                ACPI_BITREG_GLOBAL_LOCK_RELEASE, ACPI_ENABLE_EVENT);
-        }
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Released hardware Global Lock\n"));
-    }
-
-    AcpiGbl_GlobalLockAcquired = FALSE;
-
-    /* Release the local GL mutex */
-
-    AcpiOsReleaseMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex);
-    return_ACPI_STATUS (Status);
-}
-
-#endif /* !ACPI_REDUCED_HARDWARE */

+ 0 - 946
h2o/localdep/acpica/events/evgpe.c

@@ -1,946 +0,0 @@
-/******************************************************************************
- *
- * Module Name: evgpe - General Purpose Event handling and dispatch
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acevents.h"
-#include "acnamesp.h"
-
-#define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evgpe")
-
-#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
-
-/* Local prototypes */
-
-static void ACPI_SYSTEM_XFACE
-AcpiEvAsynchExecuteGpeMethod (
-    void                    *Context);
-
-static void ACPI_SYSTEM_XFACE
-AcpiEvAsynchEnableGpe (
-    void                    *Context);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvUpdateGpeEnableMask
- *
- * PARAMETERS:  GpeEventInfo            - GPE to update
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Updates GPE register enable mask based upon whether there are
- *              runtime references to this GPE
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvUpdateGpeEnableMask (
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo)
-{
-    ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
-    UINT32                  RegisterBit;
-
-
-    ACPI_FUNCTION_TRACE (EvUpdateGpeEnableMask);
-
-
-    GpeRegisterInfo = GpeEventInfo->RegisterInfo;
-    if (!GpeRegisterInfo)
-    {
-        return_ACPI_STATUS (AE_NOT_EXIST);
-    }
-
-    RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
-
-    /* Clear the run bit up front */
-
-    ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForRun, RegisterBit);
-
-    /* Set the mask bit only if there are references to this GPE */
-
-    if (GpeEventInfo->RuntimeCount)
-    {
-        ACPI_SET_BIT (GpeRegisterInfo->EnableForRun, (UINT8) RegisterBit);
-    }
-
-    GpeRegisterInfo->EnableMask = GpeRegisterInfo->EnableForRun;
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvEnableGpe
- *
- * PARAMETERS:  GpeEventInfo            - GPE to enable
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Enable a GPE.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvEnableGpe (
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo)
-{
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (EvEnableGpe);
-
-
-    /* Enable the requested GPE */
-
-    Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_ENABLE);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvMaskGpe
- *
- * PARAMETERS:  GpeEventInfo            - GPE to be blocked/unblocked
- *              IsMasked                - Whether the GPE is masked or not
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Unconditionally mask/unmask a GPE during runtime.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvMaskGpe (
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo,
-    BOOLEAN                 IsMasked)
-{
-    ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
-    UINT32                  RegisterBit;
-
-
-    ACPI_FUNCTION_TRACE (EvMaskGpe);
-
-
-    GpeRegisterInfo = GpeEventInfo->RegisterInfo;
-    if (!GpeRegisterInfo)
-    {
-        return_ACPI_STATUS (AE_NOT_EXIST);
-    }
-
-    RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
-
-    /* Perform the action */
-
-    if (IsMasked)
-    {
-        if (RegisterBit & GpeRegisterInfo->MaskForRun)
-        {
-            return_ACPI_STATUS (AE_BAD_PARAMETER);
-        }
-
-        (void) AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
-        ACPI_SET_BIT (GpeRegisterInfo->MaskForRun, (UINT8) RegisterBit);
-    }
-    else
-    {
-        if (!(RegisterBit & GpeRegisterInfo->MaskForRun))
-        {
-            return_ACPI_STATUS (AE_BAD_PARAMETER);
-        }
-
-        ACPI_CLEAR_BIT (GpeRegisterInfo->MaskForRun, (UINT8) RegisterBit);
-        if (GpeEventInfo->RuntimeCount &&
-            !GpeEventInfo->DisableForDispatch)
-        {
-            (void) AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_ENABLE);
-        }
-    }
-
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvAddGpeReference
- *
- * PARAMETERS:  GpeEventInfo            - Add a reference to this GPE
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
- *              hardware-enabled.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvAddGpeReference (
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo)
-{
-    ACPI_STATUS             Status = AE_OK;
-
-
-    ACPI_FUNCTION_TRACE (EvAddGpeReference);
-
-
-    if (GpeEventInfo->RuntimeCount == ACPI_UINT8_MAX)
-    {
-        return_ACPI_STATUS (AE_LIMIT);
-    }
-
-    GpeEventInfo->RuntimeCount++;
-    if (GpeEventInfo->RuntimeCount == 1)
-    {
-        /* Enable on first reference */
-
-        Status = AcpiEvUpdateGpeEnableMask (GpeEventInfo);
-        if (ACPI_SUCCESS (Status))
-        {
-            Status = AcpiEvEnableGpe (GpeEventInfo);
-        }
-
-        if (ACPI_FAILURE (Status))
-        {
-            GpeEventInfo->RuntimeCount--;
-        }
-    }
-
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvRemoveGpeReference
- *
- * PARAMETERS:  GpeEventInfo            - Remove a reference to this GPE
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Remove a reference to a GPE. When the last reference is
- *              removed, the GPE is hardware-disabled.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvRemoveGpeReference (
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo)
-{
-    ACPI_STATUS             Status = AE_OK;
-
-
-    ACPI_FUNCTION_TRACE (EvRemoveGpeReference);
-
-
-    if (!GpeEventInfo->RuntimeCount)
-    {
-        return_ACPI_STATUS (AE_LIMIT);
-    }
-
-    GpeEventInfo->RuntimeCount--;
-    if (!GpeEventInfo->RuntimeCount)
-    {
-        /* Disable on last reference */
-
-        Status = AcpiEvUpdateGpeEnableMask (GpeEventInfo);
-        if (ACPI_SUCCESS (Status))
-        {
-            Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
-        }
-
-        if (ACPI_FAILURE (Status))
-        {
-            GpeEventInfo->RuntimeCount++;
-        }
-    }
-
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvLowGetGpeInfo
- *
- * PARAMETERS:  GpeNumber           - Raw GPE number
- *              GpeBlock            - A GPE info block
- *
- * RETURN:      A GPE EventInfo struct. NULL if not a valid GPE (The GpeNumber
- *              is not within the specified GPE block)
- *
- * DESCRIPTION: Returns the EventInfo struct associated with this GPE. This is
- *              the low-level implementation of EvGetGpeEventInfo.
- *
- ******************************************************************************/
-
-ACPI_GPE_EVENT_INFO *
-AcpiEvLowGetGpeInfo (
-    UINT32                  GpeNumber,
-    ACPI_GPE_BLOCK_INFO     *GpeBlock)
-{
-    UINT32                  GpeIndex;
-
-
-    /*
-     * Validate that the GpeNumber is within the specified GpeBlock.
-     * (Two steps)
-     */
-    if (!GpeBlock ||
-        (GpeNumber < GpeBlock->BlockBaseNumber))
-    {
-        return (NULL);
-    }
-
-    GpeIndex = GpeNumber - GpeBlock->BlockBaseNumber;
-    if (GpeIndex >= GpeBlock->GpeCount)
-    {
-        return (NULL);
-    }
-
-    return (&GpeBlock->EventInfo[GpeIndex]);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvGetGpeEventInfo
- *
- * PARAMETERS:  GpeDevice           - Device node. NULL for GPE0/GPE1
- *              GpeNumber           - Raw GPE number
- *
- * RETURN:      A GPE EventInfo struct. NULL if not a valid GPE
- *
- * DESCRIPTION: Returns the EventInfo struct associated with this GPE.
- *              Validates the GpeBlock and the GpeNumber
- *
- *              Should be called only when the GPE lists are semaphore locked
- *              and not subject to change.
- *
- ******************************************************************************/
-
-ACPI_GPE_EVENT_INFO *
-AcpiEvGetGpeEventInfo (
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber)
-{
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_GPE_EVENT_INFO     *GpeInfo;
-    UINT32                  i;
-
-
-    ACPI_FUNCTION_ENTRY ();
-
-
-    /* A NULL GpeDevice means use the FADT-defined GPE block(s) */
-
-    if (!GpeDevice)
-    {
-        /* Examine GPE Block 0 and 1 (These blocks are permanent) */
-
-        for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++)
-        {
-            GpeInfo = AcpiEvLowGetGpeInfo (GpeNumber,
-                AcpiGbl_GpeFadtBlocks[i]);
-            if (GpeInfo)
-            {
-                return (GpeInfo);
-            }
-        }
-
-        /* The GpeNumber was not in the range of either FADT GPE block */
-
-        return (NULL);
-    }
-
-    /* A Non-NULL GpeDevice means this is a GPE Block Device */
-
-    ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) GpeDevice);
-    if (!ObjDesc ||
-        !ObjDesc->Device.GpeBlock)
-    {
-        return (NULL);
-    }
-
-    return (AcpiEvLowGetGpeInfo (GpeNumber, ObjDesc->Device.GpeBlock));
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvGpeDetect
- *
- * PARAMETERS:  GpeXruptList        - Interrupt block for this interrupt.
- *                                    Can have multiple GPE blocks attached.
- *
- * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
- *
- * DESCRIPTION: Detect if any GP events have occurred. This function is
- *              executed at interrupt level.
- *
- ******************************************************************************/
-
-UINT32
-AcpiEvGpeDetect (
-    ACPI_GPE_XRUPT_INFO     *GpeXruptList)
-{
-    ACPI_GPE_BLOCK_INFO     *GpeBlock;
-    ACPI_NAMESPACE_NODE     *GpeDevice;
-    ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    UINT32                  GpeNumber;
-    UINT32                  IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
-    ACPI_CPU_FLAGS          Flags;
-    UINT32                  i;
-    UINT32                  j;
-
-
-    ACPI_FUNCTION_NAME (EvGpeDetect);
-
-    /* Check for the case where there are no GPEs */
-
-    if (!GpeXruptList)
-    {
-        return (IntStatus);
-    }
-
-    /*
-     * We need to obtain the GPE lock for both the data structs and registers
-     * Note: Not necessary to obtain the hardware lock, since the GPE
-     * registers are owned by the GpeLock.
-     */
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /* Examine all GPE blocks attached to this interrupt level */
-
-    GpeBlock = GpeXruptList->GpeBlockListHead;
-    while (GpeBlock)
-    {
-        GpeDevice = GpeBlock->Node;
-
-        /*
-         * Read all of the 8-bit GPE status and enable registers in this GPE
-         * block, saving all of them. Find all currently active GP events.
-         */
-        for (i = 0; i < GpeBlock->RegisterCount; i++)
-        {
-            /* Get the next status/enable pair */
-
-            GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
-
-            /*
-             * Optimization: If there are no GPEs enabled within this
-             * register, we can safely ignore the entire register.
-             */
-            if (!(GpeRegisterInfo->EnableForRun |
-                  GpeRegisterInfo->EnableForWake))
-            {
-                ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
-                    "Ignore disabled registers for GPE %02X-%02X: "
-                    "RunEnable=%02X, WakeEnable=%02X\n",
-                    GpeRegisterInfo->BaseGpeNumber,
-                    GpeRegisterInfo->BaseGpeNumber + (ACPI_GPE_REGISTER_WIDTH - 1),
-                    GpeRegisterInfo->EnableForRun,
-                    GpeRegisterInfo->EnableForWake));
-                continue;
-            }
-
-            /* Now look at the individual GPEs in this byte register */
-
-            for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
-            {
-                /* Detect and dispatch one GPE bit */
-
-                GpeEventInfo = &GpeBlock->EventInfo[((ACPI_SIZE) i *
-                    ACPI_GPE_REGISTER_WIDTH) + j];
-                GpeNumber = j + GpeRegisterInfo->BaseGpeNumber;
-                AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-                IntStatus |= AcpiEvDetectGpe (
-                    GpeDevice, GpeEventInfo, GpeNumber);
-                Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-            }
-        }
-
-        GpeBlock = GpeBlock->Next;
-    }
-
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    return (IntStatus);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvAsynchExecuteGpeMethod
- *
- * PARAMETERS:  Context (GpeEventInfo) - Info for this GPE
- *
- * RETURN:      None
- *
- * DESCRIPTION: Perform the actual execution of a GPE control method. This
- *              function is called from an invocation of AcpiOsExecute and
- *              therefore does NOT execute at interrupt level - so that
- *              the control method itself is not executed in the context of
- *              an interrupt handler.
- *
- ******************************************************************************/
-
-static void ACPI_SYSTEM_XFACE
-AcpiEvAsynchExecuteGpeMethod (
-    void                    *Context)
-{
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo = Context;
-    ACPI_STATUS             Status = AE_OK;
-    ACPI_EVALUATE_INFO      *Info;
-    ACPI_GPE_NOTIFY_INFO    *Notify;
-
-
-    ACPI_FUNCTION_TRACE (EvAsynchExecuteGpeMethod);
-
-
-    /* Do the correct dispatch - normal method or implicit notify */
-
-    switch (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags))
-    {
-    case ACPI_GPE_DISPATCH_NOTIFY:
-        /*
-         * Implicit notify.
-         * Dispatch a DEVICE_WAKE notify to the appropriate handler.
-         * NOTE: the request is queued for execution after this method
-         * completes. The notify handlers are NOT invoked synchronously
-         * from this thread -- because handlers may in turn run other
-         * control methods.
-         *
-         * June 2012: Expand implicit notify mechanism to support
-         * notifies on multiple device objects.
-         */
-        Notify = GpeEventInfo->Dispatch.NotifyList;
-        while (ACPI_SUCCESS (Status) && Notify)
-        {
-            Status = AcpiEvQueueNotifyRequest (
-                Notify->DeviceNode, ACPI_NOTIFY_DEVICE_WAKE);
-
-            Notify = Notify->Next;
-        }
-        break;
-
-    case ACPI_GPE_DISPATCH_METHOD:
-
-        /* Allocate the evaluation information block */
-
-        Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
-        if (!Info)
-        {
-            Status = AE_NO_MEMORY;
-        }
-        else
-        {
-            /*
-             * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the
-             * _Lxx/_Exx control method that corresponds to this GPE
-             */
-            Info->PrefixNode = GpeEventInfo->Dispatch.MethodNode;
-            Info->Flags = ACPI_IGNORE_RETURN_VALUE;
-
-            Status = AcpiNsEvaluate (Info);
-            ACPI_FREE (Info);
-        }
-
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_EXCEPTION ((AE_INFO, Status,
-                "while evaluating GPE method [%4.4s]",
-                AcpiUtGetNodeName (GpeEventInfo->Dispatch.MethodNode)));
-        }
-        break;
-
-    default:
-
-        goto ErrorExit; /* Should never happen */
-    }
-
-    /* Defer enabling of GPE until all notify handlers are done */
-
-    Status = AcpiOsExecute (OSL_NOTIFY_HANDLER,
-        AcpiEvAsynchEnableGpe, GpeEventInfo);
-    if (ACPI_SUCCESS (Status))
-    {
-        return_VOID;
-    }
-
-ErrorExit:
-    AcpiEvAsynchEnableGpe (GpeEventInfo);
-    return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvAsynchEnableGpe
- *
- * PARAMETERS:  Context (GpeEventInfo) - Info for this GPE
- *              Callback from AcpiOsExecute
- *
- * RETURN:      None
- *
- * DESCRIPTION: Asynchronous clear/enable for GPE. This allows the GPE to
- *              complete (i.e., finish execution of Notify)
- *
- ******************************************************************************/
-
-static void ACPI_SYSTEM_XFACE
-AcpiEvAsynchEnableGpe (
-    void                    *Context)
-{
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo = Context;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-    (void) AcpiEvFinishGpe (GpeEventInfo);
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-
-    return;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvFinishGpe
- *
- * PARAMETERS:  GpeEventInfo        - Info for this GPE
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Clear/Enable a GPE. Common code that is used after execution
- *              of a GPE method or a synchronous or asynchronous GPE handler.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvFinishGpe (
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo)
-{
-    ACPI_STATUS             Status;
-
-
-    if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
-            ACPI_GPE_LEVEL_TRIGGERED)
-    {
-        /*
-         * GPE is level-triggered, we clear the GPE status bit after
-         * handling the event.
-         */
-        Status = AcpiHwClearGpe (GpeEventInfo);
-        if (ACPI_FAILURE (Status))
-        {
-            return (Status);
-        }
-    }
-
-    /*
-     * Enable this GPE, conditionally. This means that the GPE will
-     * only be physically enabled if the EnableMask bit is set
-     * in the EventInfo.
-     */
-    (void) AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_CONDITIONAL_ENABLE);
-    GpeEventInfo->DisableForDispatch = FALSE;
-    return (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvDetectGpe
- *
- * PARAMETERS:  GpeDevice           - Device node. NULL for GPE0/GPE1
- *              GpeEventInfo        - Info for this GPE
- *              GpeNumber           - Number relative to the parent GPE block
- *
- * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
- *
- * DESCRIPTION: Detect and dispatch a General Purpose Event to either a function
- *              (e.g. EC) or method (e.g. _Lxx/_Exx) handler.
- * NOTE:        GPE is W1C, so it is possible to handle a single GPE from both
- *              task and irq context in parallel as long as the process to
- *              detect and mask the GPE is atomic.
- *              However the atomicity of ACPI_GPE_DISPATCH_RAW_HANDLER is
- *              dependent on the raw handler itself.
- *
- ******************************************************************************/
-
-UINT32
-AcpiEvDetectGpe (
-    ACPI_NAMESPACE_NODE     *GpeDevice,
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo,
-    UINT32                  GpeNumber)
-{
-    UINT32                  IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
-    UINT8                   EnabledStatusByte;
-    UINT64                  StatusReg;
-    UINT64                  EnableReg;
-    UINT32                  RegisterBit;
-    ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
-    ACPI_GPE_HANDLER_INFO   *GpeHandlerInfo;
-    ACPI_CPU_FLAGS          Flags;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (EvGpeDetect);
-
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /* Get the info block for the entire GPE register */
-
-    GpeRegisterInfo = GpeEventInfo->RegisterInfo;
-
-    /* Get the register bitmask for this GPE */
-
-    RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
-
-    /* GPE currently enabled (enable bit == 1)? */
-
-    Status = AcpiHwRead (&EnableReg, &GpeRegisterInfo->EnableAddress);
-    if (ACPI_FAILURE (Status))
-    {
-        goto ErrorExit;
-    }
-
-    /* GPE currently active (status bit == 1)? */
-
-    Status = AcpiHwRead (&StatusReg, &GpeRegisterInfo->StatusAddress);
-    if (ACPI_FAILURE (Status))
-    {
-        goto ErrorExit;
-    }
-
-    /* Check if there is anything active at all in this GPE */
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
-        "Read registers for GPE %02X: Status=%02X, Enable=%02X, "
-        "RunEnable=%02X, WakeEnable=%02X\n",
-        GpeNumber,
-        (UINT32) (StatusReg & RegisterBit),
-        (UINT32) (EnableReg & RegisterBit),
-        GpeRegisterInfo->EnableForRun,
-        GpeRegisterInfo->EnableForWake));
-
-    EnabledStatusByte = (UINT8) (StatusReg & EnableReg);
-    if (!(EnabledStatusByte & RegisterBit))
-    {
-        goto ErrorExit;
-    }
-
-    /* Invoke global event handler if present */
-
-    AcpiGpeCount++;
-    if (AcpiGbl_GlobalEventHandler)
-    {
-        AcpiGbl_GlobalEventHandler (ACPI_EVENT_TYPE_GPE,
-            GpeDevice, GpeNumber,
-            AcpiGbl_GlobalEventHandlerContext);
-    }
-
-    /* Found an active GPE */
-
-    if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
-        ACPI_GPE_DISPATCH_RAW_HANDLER)
-    {
-        /* Dispatch the event to a raw handler */
-
-        GpeHandlerInfo = GpeEventInfo->Dispatch.Handler;
-
-        /*
-         * There is no protection around the namespace node
-         * and the GPE handler to ensure a safe destruction
-         * because:
-         * 1. The namespace node is expected to always
-         *    exist after loading a table.
-         * 2. The GPE handler is expected to be flushed by
-         *    AcpiOsWaitEventsComplete() before the
-         *    destruction.
-         */
-        AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-        IntStatus |= GpeHandlerInfo->Address (
-            GpeDevice, GpeNumber, GpeHandlerInfo->Context);
-        Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-    }
-    else
-    {
-        /* Dispatch the event to a standard handler or method. */
-
-        IntStatus |= AcpiEvGpeDispatch (GpeDevice,
-            GpeEventInfo, GpeNumber);
-    }
-
-ErrorExit:
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    return (IntStatus);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvGpeDispatch
- *
- * PARAMETERS:  GpeDevice           - Device node. NULL for GPE0/GPE1
- *              GpeEventInfo        - Info for this GPE
- *              GpeNumber           - Number relative to the parent GPE block
- *
- * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
- *
- * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
- *              or method (e.g. _Lxx/_Exx) handler.
- *
- ******************************************************************************/
-
-UINT32
-AcpiEvGpeDispatch (
-    ACPI_NAMESPACE_NODE     *GpeDevice,
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo,
-    UINT32                  GpeNumber)
-{
-    ACPI_STATUS             Status;
-    UINT32                  ReturnValue;
-
-
-    ACPI_FUNCTION_TRACE (EvGpeDispatch);
-
-
-    /*
-     * Always disable the GPE so that it does not keep firing before
-     * any asynchronous activity completes (either from the execution
-     * of a GPE method or an asynchronous GPE handler.)
-     *
-     * If there is no handler or method to run, just disable the
-     * GPE and leave it disabled permanently to prevent further such
-     * pointless events from firing.
-     */
-    Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_EXCEPTION ((AE_INFO, Status,
-            "Unable to disable GPE %02X", GpeNumber));
-        return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED);
-    }
-
-    /*
-     * If edge-triggered, clear the GPE status bit now. Note that
-     * level-triggered events are cleared after the GPE is serviced.
-     */
-    if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
-            ACPI_GPE_EDGE_TRIGGERED)
-    {
-        Status = AcpiHwClearGpe (GpeEventInfo);
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_EXCEPTION ((AE_INFO, Status,
-                "Unable to clear GPE %02X", GpeNumber));
-            (void) AcpiHwLowSetGpe (
-                GpeEventInfo, ACPI_GPE_CONDITIONAL_ENABLE);
-            return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED);
-        }
-    }
-
-    GpeEventInfo->DisableForDispatch = TRUE;
-
-    /*
-     * Dispatch the GPE to either an installed handler or the control
-     * method associated with this GPE (_Lxx or _Exx). If a handler
-     * exists, we invoke it and do not attempt to run the method.
-     * If there is neither a handler nor a method, leave the GPE
-     * disabled.
-     */
-    switch (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags))
-    {
-    case ACPI_GPE_DISPATCH_HANDLER:
-
-        /* Invoke the installed handler (at interrupt level) */
-
-        ReturnValue = GpeEventInfo->Dispatch.Handler->Address (
-            GpeDevice, GpeNumber,
-            GpeEventInfo->Dispatch.Handler->Context);
-
-        /* If requested, clear (if level-triggered) and re-enable the GPE */
-
-        if (ReturnValue & ACPI_REENABLE_GPE)
-        {
-            (void) AcpiEvFinishGpe (GpeEventInfo);
-        }
-        break;
-
-    case ACPI_GPE_DISPATCH_METHOD:
-    case ACPI_GPE_DISPATCH_NOTIFY:
-        /*
-         * Execute the method associated with the GPE
-         * NOTE: Level-triggered GPEs are cleared after the method completes.
-         */
-        Status = AcpiOsExecute (OSL_GPE_HANDLER,
-            AcpiEvAsynchExecuteGpeMethod, GpeEventInfo);
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_EXCEPTION ((AE_INFO, Status,
-                "Unable to queue handler for GPE %02X - event disabled",
-                GpeNumber));
-        }
-        break;
-
-    default:
-        /*
-         * No handler or method to run!
-         * 03/2010: This case should no longer be possible. We will not allow
-         * a GPE to be enabled if it has no handler or method.
-         */
-        ACPI_ERROR ((AE_INFO,
-            "No handler or method for GPE %02X, disabling event",
-            GpeNumber));
-        break;
-    }
-
-    return_UINT32 (ACPI_INTERRUPT_HANDLED);
-}
-
-#endif /* !ACPI_REDUCED_HARDWARE */

+ 0 - 565
h2o/localdep/acpica/events/evgpeblk.c

@@ -1,565 +0,0 @@
-/******************************************************************************
- *
- * Module Name: evgpeblk - GPE block creation and initialization.
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acevents.h"
-#include "acnamesp.h"
-
-#define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evgpeblk")
-
-#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
-
-/* Local prototypes */
-
-static ACPI_STATUS
-AcpiEvInstallGpeBlock (
-    ACPI_GPE_BLOCK_INFO     *GpeBlock,
-    UINT32                  InterruptNumber);
-
-static ACPI_STATUS
-AcpiEvCreateGpeInfoBlocks (
-    ACPI_GPE_BLOCK_INFO     *GpeBlock);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvInstallGpeBlock
- *
- * PARAMETERS:  GpeBlock                - New GPE block
- *              InterruptNumber         - Xrupt to be associated with this
- *                                        GPE block
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Install new GPE block with mutex support
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiEvInstallGpeBlock (
-    ACPI_GPE_BLOCK_INFO     *GpeBlock,
-    UINT32                  InterruptNumber)
-{
-    ACPI_GPE_BLOCK_INFO     *NextGpeBlock;
-    ACPI_GPE_XRUPT_INFO     *GpeXruptBlock;
-    ACPI_STATUS             Status;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
-
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    Status = AcpiEvGetGpeXruptBlock (InterruptNumber, &GpeXruptBlock);
-    if (ACPI_FAILURE (Status))
-    {
-        goto UnlockAndExit;
-    }
-
-    /* Install the new block at the end of the list with lock */
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-    if (GpeXruptBlock->GpeBlockListHead)
-    {
-        NextGpeBlock = GpeXruptBlock->GpeBlockListHead;
-        while (NextGpeBlock->Next)
-        {
-            NextGpeBlock = NextGpeBlock->Next;
-        }
-
-        NextGpeBlock->Next = GpeBlock;
-        GpeBlock->Previous = NextGpeBlock;
-    }
-    else
-    {
-        GpeXruptBlock->GpeBlockListHead = GpeBlock;
-    }
-
-    GpeBlock->XruptBlock = GpeXruptBlock;
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-
-
-UnlockAndExit:
-    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvDeleteGpeBlock
- *
- * PARAMETERS:  GpeBlock            - Existing GPE block
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Remove a GPE block
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvDeleteGpeBlock (
-    ACPI_GPE_BLOCK_INFO     *GpeBlock)
-{
-    ACPI_STATUS             Status;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
-
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Disable all GPEs in this block */
-
-    Status = AcpiHwDisableGpeBlock (GpeBlock->XruptBlock, GpeBlock, NULL);
-
-    if (!GpeBlock->Previous && !GpeBlock->Next)
-    {
-        /* This is the last GpeBlock on this interrupt */
-
-        Status = AcpiEvDeleteGpeXrupt (GpeBlock->XruptBlock);
-        if (ACPI_FAILURE (Status))
-        {
-            goto UnlockAndExit;
-        }
-    }
-    else
-    {
-        /* Remove the block on this interrupt with lock */
-
-        Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-        if (GpeBlock->Previous)
-        {
-            GpeBlock->Previous->Next = GpeBlock->Next;
-        }
-        else
-        {
-            GpeBlock->XruptBlock->GpeBlockListHead = GpeBlock->Next;
-        }
-
-        if (GpeBlock->Next)
-        {
-            GpeBlock->Next->Previous = GpeBlock->Previous;
-        }
-
-        AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    }
-
-    AcpiCurrentGpeCount -= GpeBlock->GpeCount;
-
-    /* Free the GpeBlock */
-
-    ACPI_FREE (GpeBlock->RegisterInfo);
-    ACPI_FREE (GpeBlock->EventInfo);
-    ACPI_FREE (GpeBlock);
-
-UnlockAndExit:
-    Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvCreateGpeInfoBlocks
- *
- * PARAMETERS:  GpeBlock    - New GPE block
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Create the RegisterInfo and EventInfo blocks for this GPE block
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiEvCreateGpeInfoBlocks (
-    ACPI_GPE_BLOCK_INFO     *GpeBlock)
-{
-    ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo = NULL;
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo = NULL;
-    ACPI_GPE_EVENT_INFO     *ThisEvent;
-    ACPI_GPE_REGISTER_INFO  *ThisRegister;
-    UINT32                  i;
-    UINT32                  j;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (EvCreateGpeInfoBlocks);
-
-
-    /* Allocate the GPE register information block */
-
-    GpeRegisterInfo = ACPI_ALLOCATE_ZEROED (
-        (ACPI_SIZE) GpeBlock->RegisterCount *
-        sizeof (ACPI_GPE_REGISTER_INFO));
-    if (!GpeRegisterInfo)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "Could not allocate the GpeRegisterInfo table"));
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    /*
-     * Allocate the GPE EventInfo block. There are eight distinct GPEs
-     * per register. Initialization to zeros is sufficient.
-     */
-    GpeEventInfo = ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) GpeBlock->GpeCount *
-        sizeof (ACPI_GPE_EVENT_INFO));
-    if (!GpeEventInfo)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "Could not allocate the GpeEventInfo table"));
-        Status = AE_NO_MEMORY;
-        goto ErrorExit;
-    }
-
-    /* Save the new Info arrays in the GPE block */
-
-    GpeBlock->RegisterInfo = GpeRegisterInfo;
-    GpeBlock->EventInfo = GpeEventInfo;
-
-    /*
-     * Initialize the GPE Register and Event structures. A goal of these
-     * tables is to hide the fact that there are two separate GPE register
-     * sets in a given GPE hardware block, the status registers occupy the
-     * first half, and the enable registers occupy the second half.
-     */
-    ThisRegister = GpeRegisterInfo;
-    ThisEvent = GpeEventInfo;
-
-    for (i = 0; i < GpeBlock->RegisterCount; i++)
-    {
-        /* Init the RegisterInfo for this GPE register (8 GPEs) */
-
-        ThisRegister->BaseGpeNumber = (UINT16)
-            (GpeBlock->BlockBaseNumber + (i * ACPI_GPE_REGISTER_WIDTH));
-
-        ThisRegister->StatusAddress.Address =
-            GpeBlock->Address + i;
-
-        ThisRegister->EnableAddress.Address =
-            GpeBlock->Address + i + GpeBlock->RegisterCount;
-
-        ThisRegister->StatusAddress.SpaceId   = GpeBlock->SpaceId;
-        ThisRegister->EnableAddress.SpaceId   = GpeBlock->SpaceId;
-        ThisRegister->StatusAddress.BitWidth  = ACPI_GPE_REGISTER_WIDTH;
-        ThisRegister->EnableAddress.BitWidth  = ACPI_GPE_REGISTER_WIDTH;
-        ThisRegister->StatusAddress.BitOffset = 0;
-        ThisRegister->EnableAddress.BitOffset = 0;
-
-        /* Init the EventInfo for each GPE within this register */
-
-        for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
-        {
-            ThisEvent->GpeNumber = (UINT8) (ThisRegister->BaseGpeNumber + j);
-            ThisEvent->RegisterInfo = ThisRegister;
-            ThisEvent++;
-        }
-
-        /* Disable all GPEs within this register */
-
-        Status = AcpiHwWrite (0x00, &ThisRegister->EnableAddress);
-        if (ACPI_FAILURE (Status))
-        {
-            goto ErrorExit;
-        }
-
-        /* Clear any pending GPE events within this register */
-
-        Status = AcpiHwWrite (0xFF, &ThisRegister->StatusAddress);
-        if (ACPI_FAILURE (Status))
-        {
-            goto ErrorExit;
-        }
-
-        ThisRegister++;
-    }
-
-    return_ACPI_STATUS (AE_OK);
-
-
-ErrorExit:
-    if (GpeRegisterInfo)
-    {
-        ACPI_FREE (GpeRegisterInfo);
-    }
-    if (GpeEventInfo)
-    {
-        ACPI_FREE (GpeEventInfo);
-    }
-
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvCreateGpeBlock
- *
- * PARAMETERS:  GpeDevice           - Handle to the parent GPE block
- *              GpeBlockAddress     - Address and SpaceID
- *              RegisterCount       - Number of GPE register pairs in the block
- *              GpeBlockBaseNumber  - Starting GPE number for the block
- *              InterruptNumber     - H/W interrupt for the block
- *              ReturnGpeBlock      - Where the new block descriptor is returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
- *              the block are disabled at exit.
- *              Note: Assumes namespace is locked.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvCreateGpeBlock (
-    ACPI_NAMESPACE_NODE     *GpeDevice,
-    UINT64                  Address,
-    UINT8                   SpaceId,
-    UINT32                  RegisterCount,
-    UINT16                  GpeBlockBaseNumber,
-    UINT32                  InterruptNumber,
-    ACPI_GPE_BLOCK_INFO     **ReturnGpeBlock)
-{
-    ACPI_STATUS             Status;
-    ACPI_GPE_BLOCK_INFO     *GpeBlock;
-    ACPI_GPE_WALK_INFO      WalkInfo;
-
-
-    ACPI_FUNCTION_TRACE (EvCreateGpeBlock);
-
-
-    if (!RegisterCount)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Allocate a new GPE block */
-
-    GpeBlock = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_BLOCK_INFO));
-    if (!GpeBlock)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    /* Initialize the new GPE block */
-
-    GpeBlock->Address = Address;
-    GpeBlock->SpaceId = SpaceId;
-    GpeBlock->Node = GpeDevice;
-    GpeBlock->GpeCount = (UINT16) (RegisterCount * ACPI_GPE_REGISTER_WIDTH);
-    GpeBlock->Initialized = FALSE;
-    GpeBlock->RegisterCount = RegisterCount;
-    GpeBlock->BlockBaseNumber = GpeBlockBaseNumber;
-
-    /*
-     * Create the RegisterInfo and EventInfo sub-structures
-     * Note: disables and clears all GPEs in the block
-     */
-    Status = AcpiEvCreateGpeInfoBlocks (GpeBlock);
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_FREE (GpeBlock);
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Install the new block in the global lists */
-
-    Status = AcpiEvInstallGpeBlock (GpeBlock, InterruptNumber);
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_FREE (GpeBlock->RegisterInfo);
-        ACPI_FREE (GpeBlock->EventInfo);
-        ACPI_FREE (GpeBlock);
-        return_ACPI_STATUS (Status);
-    }
-
-    AcpiGbl_AllGpesInitialized = FALSE;
-
-    /* Find all GPE methods (_Lxx or_Exx) for this block */
-
-    WalkInfo.GpeBlock = GpeBlock;
-    WalkInfo.GpeDevice = GpeDevice;
-    WalkInfo.ExecuteByOwnerId = FALSE;
-
-    Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD, GpeDevice,
-        ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
-        AcpiEvMatchGpeMethod, NULL, &WalkInfo, NULL);
-
-    /* Return the new block */
-
-    if (ReturnGpeBlock)
-    {
-        (*ReturnGpeBlock) = GpeBlock;
-    }
-
-    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
-        "    Initialized GPE %02X to %02X [%4.4s] %u regs on interrupt 0x%X%s\n",
-        (UINT32) GpeBlock->BlockBaseNumber,
-        (UINT32) (GpeBlock->BlockBaseNumber + (GpeBlock->GpeCount - 1)),
-        GpeDevice->Name.Ascii, GpeBlock->RegisterCount, InterruptNumber,
-        InterruptNumber == AcpiGbl_FADT.SciInterrupt ? " (SCI)" : ""));
-
-    /* Update global count of currently available GPEs */
-
-    AcpiCurrentGpeCount += GpeBlock->GpeCount;
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvInitializeGpeBlock
- *
- * PARAMETERS:  ACPI_GPE_CALLBACK
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Initialize and enable a GPE block. Enable GPEs that have
- *              associated methods.
- *              Note: Assumes namespace is locked.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvInitializeGpeBlock (
-    ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
-    ACPI_GPE_BLOCK_INFO     *GpeBlock,
-    void                    *Context)
-{
-    ACPI_STATUS             Status;
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    UINT32                  GpeEnabledCount;
-    UINT32                  GpeIndex;
-    UINT32                  i;
-    UINT32                  j;
-    BOOLEAN                 *IsPollingNeeded = Context;
-    ACPI_ERROR_ONLY (UINT32 GpeNumber);
-
-
-    ACPI_FUNCTION_TRACE (EvInitializeGpeBlock);
-
-
-    /*
-     * Ignore a null GPE block (e.g., if no GPE block 1 exists), and
-     * any GPE blocks that have been initialized already.
-     */
-    if (!GpeBlock || GpeBlock->Initialized)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /*
-     * Enable all GPEs that have a corresponding method and have the
-     * ACPI_GPE_CAN_WAKE flag unset. Any other GPEs within this block
-     * must be enabled via the acpi_enable_gpe() interface.
-     */
-    GpeEnabledCount = 0;
-
-    for (i = 0; i < GpeBlock->RegisterCount; i++)
-    {
-        for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
-        {
-            /* Get the info block for this particular GPE */
-
-            GpeIndex = (i * ACPI_GPE_REGISTER_WIDTH) + j;
-            GpeEventInfo = &GpeBlock->EventInfo[GpeIndex];
-            ACPI_ERROR_ONLY(GpeNumber = GpeBlock->BlockBaseNumber + GpeIndex);
-            GpeEventInfo->Flags |= ACPI_GPE_INITIALIZED;
-
-            /*
-             * Ignore GPEs that have no corresponding _Lxx/_Exx method
-             * and GPEs that are used to wake the system
-             */
-            if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) != ACPI_GPE_DISPATCH_METHOD) ||
-                (GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
-            {
-                continue;
-            }
-
-            Status = AcpiEvAddGpeReference (GpeEventInfo);
-            if (ACPI_FAILURE (Status))
-            {
-                ACPI_EXCEPTION ((AE_INFO, Status,
-                    "Could not enable GPE 0x%02X",
-                    GpeNumber));
-                continue;
-            }
-
-            GpeEventInfo->Flags |= ACPI_GPE_AUTO_ENABLED;
-
-            if (IsPollingNeeded &&
-                ACPI_GPE_IS_POLLING_NEEDED (GpeEventInfo))
-            {
-                *IsPollingNeeded = TRUE;
-            }
-
-            GpeEnabledCount++;
-        }
-    }
-
-    if (GpeEnabledCount)
-    {
-        ACPI_INFO ((
-            "Enabled %u GPEs in block %02X to %02X", GpeEnabledCount,
-            (UINT32) GpeBlock->BlockBaseNumber,
-            (UINT32) (GpeBlock->BlockBaseNumber + (GpeBlock->GpeCount - 1))));
-    }
-
-    GpeBlock->Initialized = TRUE;
-    return_ACPI_STATUS (AE_OK);
-}
-
-#endif /* !ACPI_REDUCED_HARDWARE */

+ 0 - 469
h2o/localdep/acpica/events/evgpeinit.c

@@ -1,469 +0,0 @@
-/******************************************************************************
- *
- * Module Name: evgpeinit - System GPE initialization and update
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acevents.h"
-#include "acnamesp.h"
-
-#define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evgpeinit")
-
-#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
-
-/*
- * Note: History of _PRW support in ACPICA
- *
- * Originally (2000 - 2010), the GPE initialization code performed a walk of
- * the entire namespace to execute the _PRW methods and detect all GPEs
- * capable of waking the system.
- *
- * As of 10/2010, the _PRW method execution has been removed since it is
- * actually unnecessary. The host OS must in fact execute all _PRW methods
- * in order to identify the device/power-resource dependencies. We now put
- * the onus on the host OS to identify the wake GPEs as part of this process
- * and to inform ACPICA of these GPEs via the AcpiSetupGpeForWake interface. This
- * not only reduces the complexity of the ACPICA initialization code, but in
- * some cases (on systems with very large namespaces) it should reduce the
- * kernel boot time as well.
- */
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvGpeInitialize
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Initialize the GPE data structures and the FADT GPE 0/1 blocks
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvGpeInitialize (
-    void)
-{
-    UINT32                  RegisterCount0 = 0;
-    UINT32                  RegisterCount1 = 0;
-    UINT32                  GpeNumberMax = 0;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (EvGpeInitialize);
-
-
-    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
-        "Initializing General Purpose Events (GPEs):\n"));
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /*
-     * Initialize the GPE Block(s) defined in the FADT
-     *
-     * Why the GPE register block lengths are divided by 2:  From the ACPI
-     * Spec, section "General-Purpose Event Registers", we have:
-     *
-     * "Each register block contains two registers of equal length
-     *  GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
-     *  GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
-     *  The length of the GPE1_STS and GPE1_EN registers is equal to
-     *  half the GPE1_LEN. If a generic register block is not supported
-     *  then its respective block pointer and block length values in the
-     *  FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
-     *  to be the same size."
-     */
-
-    /*
-     * Determine the maximum GPE number for this machine.
-     *
-     * Note: both GPE0 and GPE1 are optional, and either can exist without
-     * the other.
-     *
-     * If EITHER the register length OR the block address are zero, then that
-     * particular block is not supported.
-     */
-    if (AcpiGbl_FADT.Gpe0BlockLength &&
-        AcpiGbl_FADT.XGpe0Block.Address)
-    {
-        /* GPE block 0 exists (has both length and address > 0) */
-
-        RegisterCount0 = (UINT16) (AcpiGbl_FADT.Gpe0BlockLength / 2);
-        GpeNumberMax = (RegisterCount0 * ACPI_GPE_REGISTER_WIDTH) - 1;
-
-        /* Install GPE Block 0 */
-
-        Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
-            AcpiGbl_FADT.XGpe0Block.Address,
-            AcpiGbl_FADT.XGpe0Block.SpaceId,
-            RegisterCount0, 0,
-            AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[0]);
-
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_EXCEPTION ((AE_INFO, Status,
-                "Could not create GPE Block 0"));
-        }
-    }
-
-    if (AcpiGbl_FADT.Gpe1BlockLength &&
-        AcpiGbl_FADT.XGpe1Block.Address)
-    {
-        /* GPE block 1 exists (has both length and address > 0) */
-
-        RegisterCount1 = (UINT16) (AcpiGbl_FADT.Gpe1BlockLength / 2);
-
-        /* Check for GPE0/GPE1 overlap (if both banks exist) */
-
-        if ((RegisterCount0) &&
-            (GpeNumberMax >= AcpiGbl_FADT.Gpe1Base))
-        {
-            ACPI_ERROR ((AE_INFO,
-                "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
-                "(GPE %u to %u) - Ignoring GPE1",
-                GpeNumberMax, AcpiGbl_FADT.Gpe1Base,
-                AcpiGbl_FADT.Gpe1Base +
-                ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
-
-            /* Ignore GPE1 block by setting the register count to zero */
-
-            RegisterCount1 = 0;
-        }
-        else
-        {
-            /* Install GPE Block 1 */
-
-            Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
-                AcpiGbl_FADT.XGpe1Block.Address,
-                AcpiGbl_FADT.XGpe1Block.SpaceId,
-                RegisterCount1,
-                AcpiGbl_FADT.Gpe1Base,
-                AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[1]);
-
-            if (ACPI_FAILURE (Status))
-            {
-                ACPI_EXCEPTION ((AE_INFO, Status,
-                    "Could not create GPE Block 1"));
-            }
-
-            /*
-             * GPE0 and GPE1 do not have to be contiguous in the GPE number
-             * space. However, GPE0 always starts at GPE number zero.
-             */
-            GpeNumberMax = AcpiGbl_FADT.Gpe1Base +
-                ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1);
-        }
-    }
-
-    /* Exit if there are no GPE registers */
-
-    if ((RegisterCount0 + RegisterCount1) == 0)
-    {
-        /* GPEs are not required by ACPI, this is OK */
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
-            "There are no GPE blocks defined in the FADT\n"));
-        Status = AE_OK;
-        goto Cleanup;
-    }
-
-
-Cleanup:
-    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvUpdateGpes
- *
- * PARAMETERS:  TableOwnerId        - ID of the newly-loaded ACPI table
- *
- * RETURN:      None
- *
- * DESCRIPTION: Check for new GPE methods (_Lxx/_Exx) made available as a
- *              result of a Load() or LoadTable() operation. If new GPE
- *              methods have been installed, register the new methods.
- *
- ******************************************************************************/
-
-void
-AcpiEvUpdateGpes (
-    ACPI_OWNER_ID           TableOwnerId)
-{
-    ACPI_GPE_XRUPT_INFO     *GpeXruptInfo;
-    ACPI_GPE_BLOCK_INFO     *GpeBlock;
-    ACPI_GPE_WALK_INFO      WalkInfo;
-    ACPI_STATUS             Status = AE_OK;
-
-
-    /*
-     * Find any _Lxx/_Exx GPE methods that have just been loaded.
-     *
-     * Any GPEs that correspond to new _Lxx/_Exx methods are immediately
-     * enabled.
-     *
-     * Examine the namespace underneath each GpeDevice within the
-     * GpeBlock lists.
-     */
-    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
-    if (ACPI_FAILURE (Status))
-    {
-        return;
-    }
-
-    WalkInfo.Count = 0;
-    WalkInfo.OwnerId = TableOwnerId;
-    WalkInfo.ExecuteByOwnerId = TRUE;
-
-    /* Walk the interrupt level descriptor list */
-
-    GpeXruptInfo = AcpiGbl_GpeXruptListHead;
-    while (GpeXruptInfo)
-    {
-        /* Walk all Gpe Blocks attached to this interrupt level */
-
-        GpeBlock = GpeXruptInfo->GpeBlockListHead;
-        while (GpeBlock)
-        {
-            WalkInfo.GpeBlock = GpeBlock;
-            WalkInfo.GpeDevice = GpeBlock->Node;
-
-            Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD,
-                WalkInfo.GpeDevice, ACPI_UINT32_MAX,
-                ACPI_NS_WALK_NO_UNLOCK, AcpiEvMatchGpeMethod,
-                NULL, &WalkInfo, NULL);
-            if (ACPI_FAILURE (Status))
-            {
-                ACPI_EXCEPTION ((AE_INFO, Status,
-                    "While decoding _Lxx/_Exx methods"));
-            }
-
-            GpeBlock = GpeBlock->Next;
-        }
-
-        GpeXruptInfo = GpeXruptInfo->Next;
-    }
-
-    if (WalkInfo.Count)
-    {
-        ACPI_INFO (("Enabled %u new GPEs", WalkInfo.Count));
-    }
-
-    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-    return;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvMatchGpeMethod
- *
- * PARAMETERS:  Callback from WalkNamespace
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
- *              control method under the _GPE portion of the namespace.
- *              Extract the name and GPE type from the object, saving this
- *              information for quick lookup during GPE dispatch. Allows a
- *              per-OwnerId evaluation if ExecuteByOwnerId is TRUE in the
- *              WalkInfo parameter block.
- *
- *              The name of each GPE control method is of the form:
- *              "_Lxx" or "_Exx", where:
- *                  L      - means that the GPE is level triggered
- *                  E      - means that the GPE is edge triggered
- *                  xx     - is the GPE number [in HEX]
- *
- * If WalkInfo->ExecuteByOwnerId is TRUE, we only execute examine GPE methods
- * with that owner.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvMatchGpeMethod (
-    ACPI_HANDLE             ObjHandle,
-    UINT32                  Level,
-    void                    *Context,
-    void                    **ReturnValue)
-{
-    ACPI_NAMESPACE_NODE     *MethodNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
-    ACPI_GPE_WALK_INFO      *WalkInfo = ACPI_CAST_PTR (ACPI_GPE_WALK_INFO, Context);
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    ACPI_STATUS             Status;
-    UINT32                  GpeNumber;
-    UINT8                   TempGpeNumber;
-    char                    Name[ACPI_NAMESEG_SIZE + 1];
-    UINT8                   Type;
-
-
-    ACPI_FUNCTION_TRACE (EvMatchGpeMethod);
-
-
-    /* Check if requested OwnerId matches this OwnerId */
-
-    if ((WalkInfo->ExecuteByOwnerId) &&
-        (MethodNode->OwnerId != WalkInfo->OwnerId))
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /*
-     * Match and decode the _Lxx and _Exx GPE method names
-     *
-     * 1) Extract the method name and null terminate it
-     */
-    ACPI_MOVE_32_TO_32 (Name, &MethodNode->Name.Integer);
-    Name[ACPI_NAMESEG_SIZE] = 0;
-
-    /* 2) Name must begin with an underscore */
-
-    if (Name[0] != '_')
-    {
-        return_ACPI_STATUS (AE_OK); /* Ignore this method */
-    }
-
-    /*
-     * 3) Edge/Level determination is based on the 2nd character
-     *    of the method name
-     */
-    switch (Name[1])
-    {
-    case 'L':
-
-        Type = ACPI_GPE_LEVEL_TRIGGERED;
-        break;
-
-    case 'E':
-
-        Type = ACPI_GPE_EDGE_TRIGGERED;
-        break;
-
-    default:
-
-        /* Unknown method type, just ignore it */
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
-            "Ignoring unknown GPE method type: %s "
-            "(name not of form _Lxx or _Exx)", Name));
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* 4) The last two characters of the name are the hex GPE Number */
-
-    Status = AcpiUtAsciiToHexByte (&Name[2], &TempGpeNumber);
-    if (ACPI_FAILURE (Status))
-    {
-        /* Conversion failed; invalid method, just ignore it */
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
-            "Could not extract GPE number from name: %s "
-            "(name is not of form _Lxx or _Exx)", Name));
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Ensure that we have a valid GPE number for this GPE block */
-
-    GpeNumber = (UINT32) TempGpeNumber;
-    GpeEventInfo = AcpiEvLowGetGpeInfo (GpeNumber, WalkInfo->GpeBlock);
-    if (!GpeEventInfo)
-    {
-        /*
-         * This GpeNumber is not valid for this GPE block, just ignore it.
-         * However, it may be valid for a different GPE block, since GPE0
-         * and GPE1 methods both appear under \_GPE.
-         */
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
-            ACPI_GPE_DISPATCH_HANDLER) ||
-        (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
-            ACPI_GPE_DISPATCH_RAW_HANDLER))
-    {
-        /* If there is already a handler, ignore this GPE method */
-
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
-        ACPI_GPE_DISPATCH_METHOD)
-    {
-        /*
-         * If there is already a method, ignore this method. But check
-         * for a type mismatch (if both the _Lxx AND _Exx exist)
-         */
-        if (Type != (GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK))
-        {
-            ACPI_ERROR ((AE_INFO,
-                "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods",
-                GpeNumber, GpeNumber, GpeNumber));
-        }
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Disable the GPE in case it's been enabled already. */
-
-    (void) AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
-
-    /*
-     * Add the GPE information from above to the GpeEventInfo block for
-     * use during dispatch of this GPE.
-     */
-    GpeEventInfo->Flags &= ~(ACPI_GPE_DISPATCH_MASK);
-    GpeEventInfo->Flags |= (UINT8) (Type | ACPI_GPE_DISPATCH_METHOD);
-    GpeEventInfo->Dispatch.MethodNode = MethodNode;
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
-        "Registered GPE method %s as GPE number 0x%.2X\n",
-        Name, GpeNumber));
-    return_ACPI_STATUS (AE_OK);
-}
-
-#endif /* !ACPI_REDUCED_HARDWARE */

+ 0 - 398
h2o/localdep/acpica/events/evgpeutil.c

@@ -1,398 +0,0 @@
-/******************************************************************************
- *
- * Module Name: evgpeutil - GPE utilities
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acevents.h"
-
-#define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evgpeutil")
-
-
-#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvWalkGpeList
- *
- * PARAMETERS:  GpeWalkCallback     - Routine called for each GPE block
- *              Context             - Value passed to callback
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Walk the GPE lists.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvWalkGpeList (
-    ACPI_GPE_CALLBACK       GpeWalkCallback,
-    void                    *Context)
-{
-    ACPI_GPE_BLOCK_INFO     *GpeBlock;
-    ACPI_GPE_XRUPT_INFO     *GpeXruptInfo;
-    ACPI_STATUS             Status = AE_OK;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (EvWalkGpeList);
-
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /* Walk the interrupt level descriptor list */
-
-    GpeXruptInfo = AcpiGbl_GpeXruptListHead;
-    while (GpeXruptInfo)
-    {
-        /* Walk all Gpe Blocks attached to this interrupt level */
-
-        GpeBlock = GpeXruptInfo->GpeBlockListHead;
-        while (GpeBlock)
-        {
-            /* One callback per GPE block */
-
-            Status = GpeWalkCallback (GpeXruptInfo, GpeBlock, Context);
-            if (ACPI_FAILURE (Status))
-            {
-                if (Status == AE_CTRL_END) /* Callback abort */
-                {
-                    Status = AE_OK;
-                }
-                goto UnlockAndExit;
-            }
-
-            GpeBlock = GpeBlock->Next;
-        }
-
-        GpeXruptInfo = GpeXruptInfo->Next;
-    }
-
-UnlockAndExit:
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvGetGpeDevice
- *
- * PARAMETERS:  GPE_WALK_CALLBACK
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Matches the input GPE index (0-CurrentGpeCount) with a GPE
- *              block device. NULL if the GPE is one of the FADT-defined GPEs.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvGetGpeDevice (
-    ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
-    ACPI_GPE_BLOCK_INFO     *GpeBlock,
-    void                    *Context)
-{
-    ACPI_GPE_DEVICE_INFO    *Info = Context;
-
-
-    /* Increment Index by the number of GPEs in this block */
-
-    Info->NextBlockBaseIndex += GpeBlock->GpeCount;
-
-    if (Info->Index < Info->NextBlockBaseIndex)
-    {
-        /*
-         * The GPE index is within this block, get the node. Leave the node
-         * NULL for the FADT-defined GPEs
-         */
-        if ((GpeBlock->Node)->Type == ACPI_TYPE_DEVICE)
-        {
-            Info->GpeDevice = GpeBlock->Node;
-        }
-
-        Info->Status = AE_OK;
-        return (AE_CTRL_END);
-    }
-
-    return (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvGetGpeXruptBlock
- *
- * PARAMETERS:  InterruptNumber             - Interrupt for a GPE block
- *              GpeXruptBlock               - Where the block is returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
- *              block per unique interrupt level used for GPEs. Should be
- *              called only when the GPE lists are semaphore locked and not
- *              subject to change.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvGetGpeXruptBlock (
-    UINT32                  InterruptNumber,
-    ACPI_GPE_XRUPT_INFO     **GpeXruptBlock)
-{
-    ACPI_GPE_XRUPT_INFO     *NextGpeXrupt;
-    ACPI_GPE_XRUPT_INFO     *GpeXrupt;
-    ACPI_STATUS             Status;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (EvGetGpeXruptBlock);
-
-
-    /* No need for lock since we are not changing any list elements here */
-
-    NextGpeXrupt = AcpiGbl_GpeXruptListHead;
-    while (NextGpeXrupt)
-    {
-        if (NextGpeXrupt->InterruptNumber == InterruptNumber)
-        {
-            *GpeXruptBlock = NextGpeXrupt;
-            return_ACPI_STATUS (AE_OK);
-        }
-
-        NextGpeXrupt = NextGpeXrupt->Next;
-    }
-
-    /* Not found, must allocate a new xrupt descriptor */
-
-    GpeXrupt = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_XRUPT_INFO));
-    if (!GpeXrupt)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    GpeXrupt->InterruptNumber = InterruptNumber;
-
-    /* Install new interrupt descriptor with spin lock */
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-    if (AcpiGbl_GpeXruptListHead)
-    {
-        NextGpeXrupt = AcpiGbl_GpeXruptListHead;
-        while (NextGpeXrupt->Next)
-        {
-            NextGpeXrupt = NextGpeXrupt->Next;
-        }
-
-        NextGpeXrupt->Next = GpeXrupt;
-        GpeXrupt->Previous = NextGpeXrupt;
-    }
-    else
-    {
-        AcpiGbl_GpeXruptListHead = GpeXrupt;
-    }
-
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-
-    /* Install new interrupt handler if not SCI_INT */
-
-    if (InterruptNumber != AcpiGbl_FADT.SciInterrupt)
-    {
-        Status = AcpiOsInstallInterruptHandler (InterruptNumber,
-            AcpiEvGpeXruptHandler, GpeXrupt);
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_EXCEPTION ((AE_INFO, Status,
-                "Could not install GPE interrupt handler at level 0x%X",
-                InterruptNumber));
-            return_ACPI_STATUS (Status);
-        }
-    }
-
-    *GpeXruptBlock = GpeXrupt;
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvDeleteGpeXrupt
- *
- * PARAMETERS:  GpeXrupt        - A GPE interrupt info block
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Remove and free a GpeXrupt block. Remove an associated
- *              interrupt handler if not the SCI interrupt.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvDeleteGpeXrupt (
-    ACPI_GPE_XRUPT_INFO     *GpeXrupt)
-{
-    ACPI_STATUS             Status;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (EvDeleteGpeXrupt);
-
-
-    /* We never want to remove the SCI interrupt handler */
-
-    if (GpeXrupt->InterruptNumber == AcpiGbl_FADT.SciInterrupt)
-    {
-        GpeXrupt->GpeBlockListHead = NULL;
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Disable this interrupt */
-
-    Status = AcpiOsRemoveInterruptHandler (
-        GpeXrupt->InterruptNumber, AcpiEvGpeXruptHandler);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Unlink the interrupt block with lock */
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-    if (GpeXrupt->Previous)
-    {
-        GpeXrupt->Previous->Next = GpeXrupt->Next;
-    }
-    else
-    {
-        /* No previous, update list head */
-
-        AcpiGbl_GpeXruptListHead = GpeXrupt->Next;
-    }
-
-    if (GpeXrupt->Next)
-    {
-        GpeXrupt->Next->Previous = GpeXrupt->Previous;
-    }
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-
-    /* Free the block */
-
-    ACPI_FREE (GpeXrupt);
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvDeleteGpeHandlers
- *
- * PARAMETERS:  GpeXruptInfo        - GPE Interrupt info
- *              GpeBlock            - Gpe Block info
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
- *              Used only prior to termination.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvDeleteGpeHandlers (
-    ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
-    ACPI_GPE_BLOCK_INFO     *GpeBlock,
-    void                    *Context)
-{
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    ACPI_GPE_NOTIFY_INFO    *Notify;
-    ACPI_GPE_NOTIFY_INFO    *Next;
-    UINT32                  i;
-    UINT32                  j;
-
-
-    ACPI_FUNCTION_TRACE (EvDeleteGpeHandlers);
-
-
-    /* Examine each GPE Register within the block */
-
-    for (i = 0; i < GpeBlock->RegisterCount; i++)
-    {
-        /* Now look at the individual GPEs in this byte register */
-
-        for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
-        {
-            GpeEventInfo = &GpeBlock->EventInfo[((ACPI_SIZE) i *
-                ACPI_GPE_REGISTER_WIDTH) + j];
-
-            if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
-                    ACPI_GPE_DISPATCH_HANDLER) ||
-                (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
-                    ACPI_GPE_DISPATCH_RAW_HANDLER))
-            {
-                /* Delete an installed handler block */
-
-                ACPI_FREE (GpeEventInfo->Dispatch.Handler);
-                GpeEventInfo->Dispatch.Handler = NULL;
-                GpeEventInfo->Flags &= ~ACPI_GPE_DISPATCH_MASK;
-            }
-            else if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
-                ACPI_GPE_DISPATCH_NOTIFY)
-            {
-                /* Delete the implicit notification device list */
-
-                Notify = GpeEventInfo->Dispatch.NotifyList;
-                while (Notify)
-                {
-                    Next = Notify->Next;
-                    ACPI_FREE (Notify);
-                    Notify = Next;
-                }
-
-                GpeEventInfo->Dispatch.NotifyList = NULL;
-                GpeEventInfo->Flags &= ~ACPI_GPE_DISPATCH_MASK;
-            }
-        }
-    }
-
-    return_ACPI_STATUS (AE_OK);
-}
-
-#endif /* !ACPI_REDUCED_HARDWARE */

+ 0 - 606
h2o/localdep/acpica/events/evhandler.c

@@ -1,606 +0,0 @@
-/******************************************************************************
- *
- * Module Name: evhandler - Support for Address Space handlers
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acevents.h"
-#include "acnamesp.h"
-#include "acinterp.h"
-
-#define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evhandler")
-
-
-/* Local prototypes */
-
-static ACPI_STATUS
-AcpiEvInstallHandler (
-    ACPI_HANDLE             ObjHandle,
-    UINT32                  Level,
-    void                    *Context,
-    void                    **ReturnValue);
-
-
-/* These are the address spaces that will get default handlers */
-
-UINT8        AcpiGbl_DefaultAddressSpaces[ACPI_NUM_DEFAULT_SPACES] =
-{
-    ACPI_ADR_SPACE_SYSTEM_MEMORY,
-    ACPI_ADR_SPACE_SYSTEM_IO,
-    ACPI_ADR_SPACE_PCI_CONFIG,
-    ACPI_ADR_SPACE_DATA_TABLE
-};
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvInstallRegionHandlers
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Installs the core subsystem default address space handlers.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvInstallRegionHandlers (
-    void)
-{
-    ACPI_STATUS             Status;
-    UINT32                  i;
-
-
-    ACPI_FUNCTION_TRACE (EvInstallRegionHandlers);
-
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /*
-     * All address spaces (PCI Config, EC, SMBus) are scope dependent and
-     * registration must occur for a specific device.
-     *
-     * In the case of the system memory and IO address spaces there is
-     * currently no device associated with the address space. For these we
-     * use the root.
-     *
-     * We install the default PCI config space handler at the root so that
-     * this space is immediately available even though the we have not
-     * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
-     * specification which states that the PCI config space must be always
-     * available -- even though we are nowhere near ready to find the PCI root
-     * buses at this point.
-     *
-     * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
-     * has already been installed (via AcpiInstallAddressSpaceHandler).
-     * Similar for AE_SAME_HANDLER.
-     */
-    for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
-    {
-        Status = AcpiEvInstallSpaceHandler (AcpiGbl_RootNode,
-            AcpiGbl_DefaultAddressSpaces[i],
-            ACPI_DEFAULT_HANDLER, NULL, NULL);
-        switch (Status)
-        {
-        case AE_OK:
-        case AE_SAME_HANDLER:
-        case AE_ALREADY_EXISTS:
-
-            /* These exceptions are all OK */
-
-            Status = AE_OK;
-            break;
-
-        default:
-
-            goto UnlockAndExit;
-        }
-    }
-
-UnlockAndExit:
-    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvHasDefaultHandler
- *
- * PARAMETERS:  Node                - Namespace node for the device
- *              SpaceId             - The address space ID
- *
- * RETURN:      TRUE if default handler is installed, FALSE otherwise
- *
- * DESCRIPTION: Check if the default handler is installed for the requested
- *              space ID.
- *
- ******************************************************************************/
-
-BOOLEAN
-AcpiEvHasDefaultHandler (
-    ACPI_NAMESPACE_NODE     *Node,
-    ACPI_ADR_SPACE_TYPE     SpaceId)
-{
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_OPERAND_OBJECT     *HandlerObj;
-
-
-    /* Must have an existing internal object */
-
-    ObjDesc = AcpiNsGetAttachedObject (Node);
-    if (ObjDesc)
-    {
-        HandlerObj = ObjDesc->CommonNotify.Handler;
-
-        /* Walk the linked list of handlers for this object */
-
-        while (HandlerObj)
-        {
-            if (HandlerObj->AddressSpace.SpaceId == SpaceId)
-            {
-                if (HandlerObj->AddressSpace.HandlerFlags &
-                    ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)
-                {
-                    return (TRUE);
-                }
-            }
-
-            HandlerObj = HandlerObj->AddressSpace.Next;
-        }
-    }
-
-    return (FALSE);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvInstallHandler
- *
- * PARAMETERS:  WalkNamespace callback
- *
- * DESCRIPTION: This routine installs an address handler into objects that are
- *              of type Region or Device.
- *
- *              If the Object is a Device, and the device has a handler of
- *              the same type then the search is terminated in that branch.
- *
- *              This is because the existing handler is closer in proximity
- *              to any more regions than the one we are trying to install.
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiEvInstallHandler (
-    ACPI_HANDLE             ObjHandle,
-    UINT32                  Level,
-    void                    *Context,
-    void                    **ReturnValue)
-{
-    ACPI_OPERAND_OBJECT     *HandlerObj;
-    ACPI_OPERAND_OBJECT     *NextHandlerObj;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_NAME (EvInstallHandler);
-
-
-    HandlerObj = (ACPI_OPERAND_OBJECT  *) Context;
-
-    /* Parameter validation */
-
-    if (!HandlerObj)
-    {
-        return (AE_OK);
-    }
-
-    /* Convert and validate the device handle */
-
-    Node = AcpiNsValidateHandle (ObjHandle);
-    if (!Node)
-    {
-        return (AE_BAD_PARAMETER);
-    }
-
-    /*
-     * We only care about regions and objects that are allowed to have
-     * address space handlers
-     */
-    if ((Node->Type != ACPI_TYPE_DEVICE) &&
-        (Node->Type != ACPI_TYPE_REGION) &&
-        (Node != AcpiGbl_RootNode))
-    {
-        return (AE_OK);
-    }
-
-    /* Check for an existing internal object */
-
-    ObjDesc = AcpiNsGetAttachedObject (Node);
-    if (!ObjDesc)
-    {
-        /* No object, just exit */
-
-        return (AE_OK);
-    }
-
-    /* Devices are handled different than regions */
-
-    if (ObjDesc->Common.Type == ACPI_TYPE_DEVICE)
-    {
-        /* Check if this Device already has a handler for this address space */
-
-        NextHandlerObj = AcpiEvFindRegionHandler (
-            HandlerObj->AddressSpace.SpaceId, ObjDesc->CommonNotify.Handler);
-        if (NextHandlerObj)
-        {
-            /* Found a handler, is it for the same address space? */
-
-            ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-                "Found handler for region [%s] in device %p(%p) handler %p\n",
-                AcpiUtGetRegionName (HandlerObj->AddressSpace.SpaceId),
-                ObjDesc, NextHandlerObj, HandlerObj));
-
-            /*
-             * Since the object we found it on was a device, then it means
-             * that someone has already installed a handler for the branch
-             * of the namespace from this device on. Just bail out telling
-             * the walk routine to not traverse this branch. This preserves
-             * the scoping rule for handlers.
-             */
-            return (AE_CTRL_DEPTH);
-        }
-
-        /*
-         * As long as the device didn't have a handler for this space we
-         * don't care about it. We just ignore it and proceed.
-         */
-        return (AE_OK);
-    }
-
-    /* Object is a Region */
-
-    if (ObjDesc->Region.SpaceId != HandlerObj->AddressSpace.SpaceId)
-    {
-        /* This region is for a different address space, just ignore it */
-
-        return (AE_OK);
-    }
-
-    /*
-     * Now we have a region and it is for the handler's address space type.
-     *
-     * First disconnect region for any previous handler (if any)
-     */
-    AcpiEvDetachRegion (ObjDesc, FALSE);
-
-    /* Connect the region to the new handler */
-
-    Status = AcpiEvAttachRegion (HandlerObj, ObjDesc, FALSE);
-    return (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvFindRegionHandler
- *
- * PARAMETERS:  SpaceId         - The address space ID
- *              HandlerObj      - Head of the handler object list
- *
- * RETURN:      Matching handler object. NULL if space ID not matched
- *
- * DESCRIPTION: Search a handler object list for a match on the address
- *              space ID.
- *
- ******************************************************************************/
-
-ACPI_OPERAND_OBJECT *
-AcpiEvFindRegionHandler (
-    ACPI_ADR_SPACE_TYPE     SpaceId,
-    ACPI_OPERAND_OBJECT     *HandlerObj)
-{
-
-    /* Walk the handler list for this device */
-
-    while (HandlerObj)
-    {
-        /* Same SpaceId indicates a handler is installed */
-
-        if (HandlerObj->AddressSpace.SpaceId == SpaceId)
-        {
-            return (HandlerObj);
-        }
-
-        /* Next handler object */
-
-        HandlerObj = HandlerObj->AddressSpace.Next;
-    }
-
-    return (NULL);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvInstallSpaceHandler
- *
- * PARAMETERS:  Node            - Namespace node for the device
- *              SpaceId         - The address space ID
- *              Handler         - Address of the handler
- *              Setup           - Address of the setup function
- *              Context         - Value passed to the handler on each access
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
- *              Assumes namespace is locked
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvInstallSpaceHandler (
-    ACPI_NAMESPACE_NODE     *Node,
-    ACPI_ADR_SPACE_TYPE     SpaceId,
-    ACPI_ADR_SPACE_HANDLER  Handler,
-    ACPI_ADR_SPACE_SETUP    Setup,
-    void                    *Context)
-{
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_OPERAND_OBJECT     *HandlerObj;
-    ACPI_STATUS             Status = AE_OK;
-    ACPI_OBJECT_TYPE        Type;
-    UINT8                   Flags = 0;
-
-
-    ACPI_FUNCTION_TRACE (EvInstallSpaceHandler);
-
-
-    /*
-     * This registration is valid for only the types below and the root.
-     * The root node is where the default handlers get installed.
-     */
-    if ((Node->Type != ACPI_TYPE_DEVICE)     &&
-        (Node->Type != ACPI_TYPE_PROCESSOR)  &&
-        (Node->Type != ACPI_TYPE_THERMAL)    &&
-        (Node != AcpiGbl_RootNode))
-    {
-        Status = AE_BAD_PARAMETER;
-        goto UnlockAndExit;
-    }
-
-    if (Handler == ACPI_DEFAULT_HANDLER)
-    {
-        Flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
-
-        switch (SpaceId)
-        {
-        case ACPI_ADR_SPACE_SYSTEM_MEMORY:
-
-            Handler = AcpiExSystemMemorySpaceHandler;
-            Setup   = AcpiEvSystemMemoryRegionSetup;
-            break;
-
-        case ACPI_ADR_SPACE_SYSTEM_IO:
-
-            Handler = AcpiExSystemIoSpaceHandler;
-            Setup   = AcpiEvIoSpaceRegionSetup;
-            break;
-
-        case ACPI_ADR_SPACE_PCI_CONFIG:
-
-            Handler = AcpiExPciConfigSpaceHandler;
-            Setup   = AcpiEvPciConfigRegionSetup;
-            break;
-
-        case ACPI_ADR_SPACE_CMOS:
-
-            Handler = AcpiExCmosSpaceHandler;
-            Setup   = AcpiEvCmosRegionSetup;
-            break;
-
-        case ACPI_ADR_SPACE_PCI_BAR_TARGET:
-
-            Handler = AcpiExPciBarSpaceHandler;
-            Setup   = AcpiEvPciBarRegionSetup;
-            break;
-
-        case ACPI_ADR_SPACE_DATA_TABLE:
-
-            Handler = AcpiExDataTableSpaceHandler;
-            Setup   = NULL;
-            break;
-
-        default:
-
-            Status = AE_BAD_PARAMETER;
-            goto UnlockAndExit;
-        }
-    }
-
-    /* If the caller hasn't specified a setup routine, use the default */
-
-    if (!Setup)
-    {
-        Setup = AcpiEvDefaultRegionSetup;
-    }
-
-    /* Check for an existing internal object */
-
-    ObjDesc = AcpiNsGetAttachedObject (Node);
-    if (ObjDesc)
-    {
-        /*
-         * The attached device object already exists. Now make sure
-         * the handler is not already installed.
-         */
-        HandlerObj = AcpiEvFindRegionHandler (SpaceId,
-            ObjDesc->CommonNotify.Handler);
-
-        if (HandlerObj)
-        {
-            if (HandlerObj->AddressSpace.Handler == Handler)
-            {
-                /*
-                 * It is (relatively) OK to attempt to install the SAME
-                 * handler twice. This can easily happen with the
-                 * PCI_Config space.
-                 */
-                Status = AE_SAME_HANDLER;
-                goto UnlockAndExit;
-            }
-            else
-            {
-                /* A handler is already installed */
-
-                Status = AE_ALREADY_EXISTS;
-            }
-
-            goto UnlockAndExit;
-        }
-    }
-    else
-    {
-        ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-            "Creating object on Device %p while installing handler\n",
-            Node));
-
-        /* ObjDesc does not exist, create one */
-
-        if (Node->Type == ACPI_TYPE_ANY)
-        {
-            Type = ACPI_TYPE_DEVICE;
-        }
-        else
-        {
-            Type = Node->Type;
-        }
-
-        ObjDesc = AcpiUtCreateInternalObject (Type);
-        if (!ObjDesc)
-        {
-            Status = AE_NO_MEMORY;
-            goto UnlockAndExit;
-        }
-
-        /* Init new descriptor */
-
-        ObjDesc->Common.Type = (UINT8) Type;
-
-        /* Attach the new object to the Node */
-
-        Status = AcpiNsAttachObject (Node, ObjDesc, Type);
-
-        /* Remove local reference to the object */
-
-        AcpiUtRemoveReference (ObjDesc);
-
-        if (ACPI_FAILURE (Status))
-        {
-            goto UnlockAndExit;
-        }
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-        "Installing address handler for region %s(%X) "
-        "on Device %4.4s %p(%p)\n",
-        AcpiUtGetRegionName (SpaceId), SpaceId,
-        AcpiUtGetNodeName (Node), Node, ObjDesc));
-
-    /*
-     * Install the handler
-     *
-     * At this point there is no existing handler. Just allocate the object
-     * for the handler and link it into the list.
-     */
-    HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
-    if (!HandlerObj)
-    {
-        Status = AE_NO_MEMORY;
-        goto UnlockAndExit;
-    }
-
-    /* Init handler obj */
-
-    HandlerObj->AddressSpace.SpaceId = (UINT8) SpaceId;
-    HandlerObj->AddressSpace.HandlerFlags = Flags;
-    HandlerObj->AddressSpace.RegionList = NULL;
-    HandlerObj->AddressSpace.Node = Node;
-    HandlerObj->AddressSpace.Handler = Handler;
-    HandlerObj->AddressSpace.Context = Context;
-    HandlerObj->AddressSpace.Setup = Setup;
-
-    /* Install at head of Device.AddressSpace list */
-
-    HandlerObj->AddressSpace.Next = ObjDesc->CommonNotify.Handler;
-
-    /*
-     * The Device object is the first reference on the HandlerObj.
-     * Each region that uses the handler adds a reference.
-     */
-    ObjDesc->CommonNotify.Handler = HandlerObj;
-
-    /*
-     * Walk the namespace finding all of the regions this handler will
-     * manage.
-     *
-     * Start at the device and search the branch toward the leaf nodes
-     * until either the leaf is encountered or a device is detected that
-     * has an address handler of the same type.
-     *
-     * In either case, back up and search down the remainder of the branch
-     */
-    Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node,
-        ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
-        AcpiEvInstallHandler, NULL, HandlerObj, NULL);
-
-UnlockAndExit:
-    return_ACPI_STATUS (Status);
-}

+ 0 - 332
h2o/localdep/acpica/events/evmisc.c

@@ -1,332 +0,0 @@
-/******************************************************************************
- *
- * Module Name: evmisc - Miscellaneous event manager support functions
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acevents.h"
-#include "acnamesp.h"
-
-#define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evmisc")
-
-
-/* Local prototypes */
-
-static void ACPI_SYSTEM_XFACE
-AcpiEvNotifyDispatch (
-    void                    *Context);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvIsNotifyObject
- *
- * PARAMETERS:  Node            - Node to check
- *
- * RETURN:      TRUE if notifies allowed on this object
- *
- * DESCRIPTION: Check type of node for a object that supports notifies.
- *
- *              TBD: This could be replaced by a flag bit in the node.
- *
- ******************************************************************************/
-
-BOOLEAN
-AcpiEvIsNotifyObject (
-    ACPI_NAMESPACE_NODE     *Node)
-{
-
-    switch (Node->Type)
-    {
-    case ACPI_TYPE_DEVICE:
-    case ACPI_TYPE_PROCESSOR:
-    case ACPI_TYPE_THERMAL:
-        /*
-         * These are the ONLY objects that can receive ACPI notifications
-         */
-        return (TRUE);
-
-    default:
-
-        return (FALSE);
-    }
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvQueueNotifyRequest
- *
- * PARAMETERS:  Node            - NS node for the notified object
- *              NotifyValue     - Value from the Notify() request
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Dispatch a device notification event to a previously
- *              installed handler.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvQueueNotifyRequest (
-    ACPI_NAMESPACE_NODE     *Node,
-    UINT32                  NotifyValue)
-{
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_OPERAND_OBJECT     *HandlerListHead = NULL;
-    ACPI_GENERIC_STATE      *Info;
-    UINT8                   HandlerListId = 0;
-    ACPI_STATUS             Status = AE_OK;
-
-
-    ACPI_FUNCTION_NAME (EvQueueNotifyRequest);
-
-
-    /* Are Notifies allowed on this object? */
-
-    if (!AcpiEvIsNotifyObject (Node))
-    {
-        return (AE_TYPE);
-    }
-
-    /* Get the correct notify list type (System or Device) */
-
-    if (NotifyValue <= ACPI_MAX_SYS_NOTIFY)
-    {
-        HandlerListId = ACPI_SYSTEM_HANDLER_LIST;
-    }
-    else
-    {
-        HandlerListId = ACPI_DEVICE_HANDLER_LIST;
-    }
-
-    /* Get the notify object attached to the namespace Node */
-
-    ObjDesc = AcpiNsGetAttachedObject (Node);
-    if (ObjDesc)
-    {
-        /* We have an attached object, Get the correct handler list */
-
-        HandlerListHead = ObjDesc->CommonNotify.NotifyList[HandlerListId];
-    }
-
-    /*
-     * If there is no notify handler (Global or Local)
-     * for this object, just ignore the notify
-     */
-    if (!AcpiGbl_GlobalNotify[HandlerListId].Handler && !HandlerListHead)
-    {
-        ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
-            "No notify handler for Notify, ignoring (%4.4s, %X) node %p\n",
-            AcpiUtGetNodeName (Node), NotifyValue, Node));
-
-        return (AE_OK);
-    }
-
-    /* Setup notify info and schedule the notify dispatcher */
-
-    Info = AcpiUtCreateGenericState ();
-    if (!Info)
-    {
-        return (AE_NO_MEMORY);
-    }
-
-    Info->Common.DescriptorType = ACPI_DESC_TYPE_STATE_NOTIFY;
-
-    Info->Notify.Node = Node;
-    Info->Notify.Value = (UINT16) NotifyValue;
-    Info->Notify.HandlerListId = HandlerListId;
-    Info->Notify.HandlerListHead = HandlerListHead;
-    Info->Notify.Global = &AcpiGbl_GlobalNotify[HandlerListId];
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
-        "Dispatching Notify on [%4.4s] (%s) Value 0x%2.2X (%s) Node %p\n",
-        AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type),
-        NotifyValue, AcpiUtGetNotifyName (NotifyValue, ACPI_TYPE_ANY), Node));
-
-    Status = AcpiOsExecute (OSL_NOTIFY_HANDLER,
-        AcpiEvNotifyDispatch, Info);
-    if (ACPI_FAILURE (Status))
-    {
-        AcpiUtDeleteGenericState (Info);
-    }
-
-    return (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvNotifyDispatch
- *
- * PARAMETERS:  Context         - To be passed to the notify handler
- *
- * RETURN:      None.
- *
- * DESCRIPTION: Dispatch a device notification event to a previously
- *              installed handler.
- *
- ******************************************************************************/
-
-static void ACPI_SYSTEM_XFACE
-AcpiEvNotifyDispatch (
-    void                    *Context)
-{
-    ACPI_GENERIC_STATE      *Info = (ACPI_GENERIC_STATE *) Context;
-    ACPI_OPERAND_OBJECT     *HandlerObj;
-
-
-    ACPI_FUNCTION_ENTRY ();
-
-
-    /* Invoke a global notify handler if installed */
-
-    if (Info->Notify.Global->Handler)
-    {
-        Info->Notify.Global->Handler (Info->Notify.Node,
-            Info->Notify.Value,
-            Info->Notify.Global->Context);
-    }
-
-    /* Now invoke the local notify handler(s) if any are installed */
-
-    HandlerObj = Info->Notify.HandlerListHead;
-    while (HandlerObj)
-    {
-        HandlerObj->Notify.Handler (Info->Notify.Node,
-            Info->Notify.Value,
-            HandlerObj->Notify.Context);
-
-        HandlerObj = HandlerObj->Notify.Next[Info->Notify.HandlerListId];
-    }
-
-    /* All done with the info object */
-
-    AcpiUtDeleteGenericState (Info);
-}
-
-
-#if (!ACPI_REDUCED_HARDWARE)
-/******************************************************************************
- *
- * FUNCTION:    AcpiEvTerminate
- *
- * PARAMETERS:  none
- *
- * RETURN:      none
- *
- * DESCRIPTION: Disable events and free memory allocated for table storage.
- *
- ******************************************************************************/
-
-void
-AcpiEvTerminate (
-    void)
-{
-    UINT32                  i;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (EvTerminate);
-
-
-    if (AcpiGbl_EventsInitialized)
-    {
-        /*
-         * Disable all event-related functionality. In all cases, on error,
-         * print a message but obviously we don't abort.
-         */
-
-        /* Disable all fixed events */
-
-        for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
-        {
-            Status = AcpiDisableEvent (i, 0);
-            if (ACPI_FAILURE (Status))
-            {
-                ACPI_ERROR ((AE_INFO,
-                    "Could not disable fixed event %u", (UINT32) i));
-            }
-        }
-
-        /* Disable all GPEs in all GPE blocks */
-
-        Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
-
-        Status = AcpiEvRemoveGlobalLockHandler ();
-        if (ACPI_FAILURE(Status))
-        {
-            ACPI_ERROR ((AE_INFO,
-                "Could not remove Global Lock handler"));
-        }
-
-        AcpiGbl_EventsInitialized = FALSE;
-    }
-
-    /* Remove SCI handlers */
-
-    Status = AcpiEvRemoveAllSciHandlers ();
-    if (ACPI_FAILURE(Status))
-    {
-        ACPI_ERROR ((AE_INFO,
-            "Could not remove SCI handler"));
-    }
-
-    /* Deallocate all handler objects installed within GPE info structs */
-
-    Status = AcpiEvWalkGpeList (AcpiEvDeleteGpeHandlers, NULL);
-
-    /* Return to original mode if necessary */
-
-    if (AcpiGbl_OriginalMode == ACPI_SYS_MODE_LEGACY)
-    {
-        Status = AcpiDisable ();
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_WARNING ((AE_INFO, "AcpiDisable failed"));
-        }
-    }
-    return_VOID;
-}
-
-#endif /* !ACPI_REDUCED_HARDWARE */

+ 0 - 939
h2o/localdep/acpica/events/evregion.c

@@ -1,939 +0,0 @@
-/******************************************************************************
- *
- * Module Name: evregion - Operation Region support
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acevents.h"
-#include "acnamesp.h"
-#include "acinterp.h"
-
-#define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evregion")
-
-
-extern UINT8        AcpiGbl_DefaultAddressSpaces[];
-
-/* Local prototypes */
-
-static void
-AcpiEvOrphanEcRegMethod (
-    ACPI_NAMESPACE_NODE     *EcDeviceNode);
-
-static ACPI_STATUS
-AcpiEvRegRun (
-    ACPI_HANDLE             ObjHandle,
-    UINT32                  Level,
-    void                    *Context,
-    void                    **ReturnValue);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvInitializeOpRegions
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Execute _REG methods for all Operation Regions that have
- *              an installed default region handler.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvInitializeOpRegions (
-    void)
-{
-    ACPI_STATUS             Status;
-    UINT32                  i;
-
-
-    ACPI_FUNCTION_TRACE (EvInitializeOpRegions);
-
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Run the _REG methods for OpRegions in each default address space */
-
-    for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
-    {
-        /*
-         * Make sure the installed handler is the DEFAULT handler. If not the
-         * default, the _REG methods will have already been run (when the
-         * handler was installed)
-         */
-        if (AcpiEvHasDefaultHandler (AcpiGbl_RootNode,
-               AcpiGbl_DefaultAddressSpaces[i]))
-        {
-            AcpiEvExecuteRegMethods (AcpiGbl_RootNode,
-                AcpiGbl_DefaultAddressSpaces[i], ACPI_REG_CONNECT);
-        }
-    }
-
-    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvAddressSpaceDispatch
- *
- * PARAMETERS:  RegionObj           - Internal region object
- *              FieldObj            - Corresponding field. Can be NULL.
- *              Function            - Read or Write operation
- *              RegionOffset        - Where in the region to read or write
- *              BitWidth            - Field width in bits (8, 16, 32, or 64)
- *              Value               - Pointer to in or out value, must be
- *                                    a full 64-bit integer
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Dispatch an address space or operation region access to
- *              a previously installed handler.
- *
- * NOTE: During early initialization, we always install the default region
- * handlers for Memory, I/O and PCI_Config. This ensures that these operation
- * region address spaces are always available as per the ACPI specification.
- * This is especially needed in order to support the execution of
- * module-level AML code during loading of the ACPI tables.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvAddressSpaceDispatch (
-    ACPI_OPERAND_OBJECT     *RegionObj,
-    ACPI_OPERAND_OBJECT     *FieldObj,
-    UINT32                  Function,
-    UINT32                  RegionOffset,
-    UINT32                  BitWidth,
-    UINT64                  *Value)
-{
-    ACPI_STATUS             Status;
-    ACPI_ADR_SPACE_HANDLER  Handler;
-    ACPI_ADR_SPACE_SETUP    RegionSetup;
-    ACPI_OPERAND_OBJECT     *HandlerDesc;
-    ACPI_OPERAND_OBJECT     *RegionObj2;
-    void                    *RegionContext = NULL;
-    ACPI_CONNECTION_INFO    *Context;
-    ACPI_PHYSICAL_ADDRESS   Address;
-
-
-    ACPI_FUNCTION_TRACE (EvAddressSpaceDispatch);
-
-
-    RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
-    if (!RegionObj2)
-    {
-        return_ACPI_STATUS (AE_NOT_EXIST);
-    }
-
-    /* Ensure that there is a handler associated with this region */
-
-    HandlerDesc = RegionObj->Region.Handler;
-    if (!HandlerDesc)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "No handler for Region [%4.4s] (%p) [%s]",
-            AcpiUtGetNodeName (RegionObj->Region.Node),
-            RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
-
-        return_ACPI_STATUS (AE_NOT_EXIST);
-    }
-
-    Context = HandlerDesc->AddressSpace.Context;
-
-    /*
-     * It may be the case that the region has never been initialized.
-     * Some types of regions require special init code
-     */
-    if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
-    {
-        /* This region has not been initialized yet, do it */
-
-        RegionSetup = HandlerDesc->AddressSpace.Setup;
-        if (!RegionSetup)
-        {
-            /* No initialization routine, exit with error */
-
-            ACPI_ERROR ((AE_INFO,
-                "No init routine for region(%p) [%s]",
-                RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
-            return_ACPI_STATUS (AE_NOT_EXIST);
-        }
-
-        /*
-         * We must exit the interpreter because the region setup will
-         * potentially execute control methods (for example, the _REG method
-         * for this region)
-         */
-        AcpiExExitInterpreter ();
-
-        Status = RegionSetup (RegionObj, ACPI_REGION_ACTIVATE,
-            Context, &RegionContext);
-
-        /* Re-enter the interpreter */
-
-        AcpiExEnterInterpreter ();
-
-        /* Check for failure of the Region Setup */
-
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_EXCEPTION ((AE_INFO, Status,
-                "During region initialization: [%s]",
-                AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
-            return_ACPI_STATUS (Status);
-        }
-
-        /* Region initialization may have been completed by RegionSetup */
-
-        if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
-        {
-            RegionObj->Region.Flags |= AOPOBJ_SETUP_COMPLETE;
-
-            /*
-             * Save the returned context for use in all accesses to
-             * the handler for this particular region
-             */
-            if (!(RegionObj2->Extra.RegionContext))
-            {
-                RegionObj2->Extra.RegionContext = RegionContext;
-            }
-        }
-    }
-
-    /* We have everything we need, we can invoke the address space handler */
-
-    Handler = HandlerDesc->AddressSpace.Handler;
-    Address = (RegionObj->Region.Address + RegionOffset);
-
-    /*
-     * Special handling for GenericSerialBus and GeneralPurposeIo:
-     * There are three extra parameters that must be passed to the
-     * handler via the context:
-     *   1) Connection buffer, a resource template from Connection() op
-     *   2) Length of the above buffer
-     *   3) Actual access length from the AccessAs() op
-     *
-     * In addition, for GeneralPurposeIo, the Address and BitWidth fields
-     * are defined as follows:
-     *   1) Address is the pin number index of the field (bit offset from
-     *      the previous Connection)
-     *   2) BitWidth is the actual bit length of the field (number of pins)
-     */
-    if ((RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS) &&
-        Context &&
-        FieldObj)
-    {
-        /* Get the Connection (ResourceTemplate) buffer */
-
-        Context->Connection = FieldObj->Field.ResourceBuffer;
-        Context->Length = FieldObj->Field.ResourceLength;
-        Context->AccessLength = FieldObj->Field.AccessLength;
-    }
-    if ((RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GPIO) &&
-        Context &&
-        FieldObj)
-    {
-        /* Get the Connection (ResourceTemplate) buffer */
-
-        Context->Connection = FieldObj->Field.ResourceBuffer;
-        Context->Length = FieldObj->Field.ResourceLength;
-        Context->AccessLength = FieldObj->Field.AccessLength;
-        Address = FieldObj->Field.PinNumberIndex;
-        BitWidth = FieldObj->Field.BitLength;
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-        "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
-        &RegionObj->Region.Handler->AddressSpace, Handler,
-        ACPI_FORMAT_UINT64 (Address),
-        AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
-
-    if (!(HandlerDesc->AddressSpace.HandlerFlags &
-        ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
-    {
-        /*
-         * For handlers other than the default (supplied) handlers, we must
-         * exit the interpreter because the handler *might* block -- we don't
-         * know what it will do, so we can't hold the lock on the interpreter.
-         */
-        AcpiExExitInterpreter();
-    }
-
-    /* Call the handler */
-
-    Status = Handler (Function, Address, BitWidth, Value, Context,
-        RegionObj2->Extra.RegionContext);
-
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_EXCEPTION ((AE_INFO, Status, "Returned by Handler for [%s]",
-            AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
-
-        /*
-         * Special case for an EC timeout. These are seen so frequently
-         * that an additional error message is helpful
-         */
-        if ((RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) &&
-            (Status == AE_TIME))
-        {
-            ACPI_ERROR ((AE_INFO,
-                "Timeout from EC hardware or EC device driver"));
-        }
-    }
-
-    if (!(HandlerDesc->AddressSpace.HandlerFlags &
-        ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
-    {
-        /*
-         * We just returned from a non-default handler, we must re-enter the
-         * interpreter
-         */
-        AcpiExEnterInterpreter ();
-    }
-
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvDetachRegion
- *
- * PARAMETERS:  RegionObj           - Region Object
- *              AcpiNsIsLocked      - Namespace Region Already Locked?
- *
- * RETURN:      None
- *
- * DESCRIPTION: Break the association between the handler and the region
- *              this is a two way association.
- *
- ******************************************************************************/
-
-void
-AcpiEvDetachRegion (
-    ACPI_OPERAND_OBJECT     *RegionObj,
-    BOOLEAN                 AcpiNsIsLocked)
-{
-    ACPI_OPERAND_OBJECT     *HandlerObj;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_OPERAND_OBJECT     *StartDesc;
-    ACPI_OPERAND_OBJECT     **LastObjPtr;
-    ACPI_ADR_SPACE_SETUP    RegionSetup;
-    void                    **RegionContext;
-    ACPI_OPERAND_OBJECT     *RegionObj2;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (EvDetachRegion);
-
-
-    RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
-    if (!RegionObj2)
-    {
-        return_VOID;
-    }
-    RegionContext = &RegionObj2->Extra.RegionContext;
-
-    /* Get the address handler from the region object */
-
-    HandlerObj = RegionObj->Region.Handler;
-    if (!HandlerObj)
-    {
-        /* This region has no handler, all done */
-
-        return_VOID;
-    }
-
-    /* Find this region in the handler's list */
-
-    ObjDesc = HandlerObj->AddressSpace.RegionList;
-    StartDesc = ObjDesc;
-    LastObjPtr = &HandlerObj->AddressSpace.RegionList;
-
-    while (ObjDesc)
-    {
-        /* Is this the correct Region? */
-
-        if (ObjDesc == RegionObj)
-        {
-            ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-                "Removing Region %p from address handler %p\n",
-                RegionObj, HandlerObj));
-
-            /* This is it, remove it from the handler's list */
-
-            *LastObjPtr = ObjDesc->Region.Next;
-            ObjDesc->Region.Next = NULL;        /* Must clear field */
-
-            if (AcpiNsIsLocked)
-            {
-                Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
-                if (ACPI_FAILURE (Status))
-                {
-                    return_VOID;
-                }
-            }
-
-            /* Now stop region accesses by executing the _REG method */
-
-            Status = AcpiEvExecuteRegMethod (RegionObj, ACPI_REG_DISCONNECT);
-            if (ACPI_FAILURE (Status))
-            {
-                ACPI_EXCEPTION ((AE_INFO, Status, "from region _REG, [%s]",
-                    AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
-            }
-
-            if (AcpiNsIsLocked)
-            {
-                Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
-                if (ACPI_FAILURE (Status))
-                {
-                    return_VOID;
-                }
-            }
-
-            /*
-             * If the region has been activated, call the setup handler with
-             * the deactivate notification
-             */
-            if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
-            {
-                RegionSetup = HandlerObj->AddressSpace.Setup;
-                Status = RegionSetup (RegionObj, ACPI_REGION_DEACTIVATE,
-                    HandlerObj->AddressSpace.Context, RegionContext);
-
-                /*
-                 * RegionContext should have been released by the deactivate
-                 * operation. We don't need access to it anymore here.
-                 */
-                if (RegionContext)
-                {
-                    *RegionContext = NULL;
-                }
-
-                /* Init routine may fail, Just ignore errors */
-
-                if (ACPI_FAILURE (Status))
-                {
-                    ACPI_EXCEPTION ((AE_INFO, Status,
-                        "from region handler - deactivate, [%s]",
-                        AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
-                }
-
-                RegionObj->Region.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
-            }
-
-            /*
-             * Remove handler reference in the region
-             *
-             * NOTE: this doesn't mean that the region goes away, the region
-             * is just inaccessible as indicated to the _REG method
-             *
-             * If the region is on the handler's list, this must be the
-             * region's handler
-             */
-            RegionObj->Region.Handler = NULL;
-            AcpiUtRemoveReference (HandlerObj);
-
-            return_VOID;
-        }
-
-        /* Walk the linked list of handlers */
-
-        LastObjPtr = &ObjDesc->Region.Next;
-        ObjDesc = ObjDesc->Region.Next;
-
-        /* Prevent infinite loop if list is corrupted */
-
-        if (ObjDesc == StartDesc)
-        {
-            ACPI_ERROR ((AE_INFO,
-                "Circular handler list in region object %p",
-                RegionObj));
-            return_VOID;
-        }
-    }
-
-    /* If we get here, the region was not in the handler's region list */
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-        "Cannot remove region %p from address handler %p\n",
-        RegionObj, HandlerObj));
-
-    return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvAttachRegion
- *
- * PARAMETERS:  HandlerObj          - Handler Object
- *              RegionObj           - Region Object
- *              AcpiNsIsLocked      - Namespace Region Already Locked?
- *
- * RETURN:      None
- *
- * DESCRIPTION: Create the association between the handler and the region
- *              this is a two way association.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvAttachRegion (
-    ACPI_OPERAND_OBJECT     *HandlerObj,
-    ACPI_OPERAND_OBJECT     *RegionObj,
-    BOOLEAN                 AcpiNsIsLocked)
-{
-
-    ACPI_FUNCTION_TRACE (EvAttachRegion);
-
-
-    /* Install the region's handler */
-
-    if (RegionObj->Region.Handler)
-    {
-        return_ACPI_STATUS (AE_ALREADY_EXISTS);
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-        "Adding Region [%4.4s] %p to address handler %p [%s]\n",
-        AcpiUtGetNodeName (RegionObj->Region.Node),
-        RegionObj, HandlerObj,
-        AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
-
-    /* Link this region to the front of the handler's list */
-
-    RegionObj->Region.Next = HandlerObj->AddressSpace.RegionList;
-    HandlerObj->AddressSpace.RegionList = RegionObj;
-    RegionObj->Region.Handler = HandlerObj;
-    AcpiUtAddReference (HandlerObj);
-
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvExecuteRegMethod
- *
- * PARAMETERS:  RegionObj           - Region object
- *              Function            - Passed to _REG: On (1) or Off (0)
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Execute _REG method for a region
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvExecuteRegMethod (
-    ACPI_OPERAND_OBJECT     *RegionObj,
-    UINT32                  Function)
-{
-    ACPI_EVALUATE_INFO      *Info;
-    ACPI_OPERAND_OBJECT     *Args[3];
-    ACPI_OPERAND_OBJECT     *RegionObj2;
-    const ACPI_NAME         *RegNamePtr = ACPI_CAST_PTR (ACPI_NAME, METHOD_NAME__REG);
-    ACPI_NAMESPACE_NODE     *MethodNode;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (EvExecuteRegMethod);
-
-
-    if (!AcpiGbl_NamespaceInitialized ||
-        RegionObj->Region.Handler == NULL)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
-    if (!RegionObj2)
-    {
-        return_ACPI_STATUS (AE_NOT_EXIST);
-    }
-
-    /*
-     * Find any "_REG" method associated with this region definition.
-     * The method should always be updated as this function may be
-     * invoked after a namespace change.
-     */
-    Node = RegionObj->Region.Node->Parent;
-    Status = AcpiNsSearchOneScope (
-        *RegNamePtr, Node, ACPI_TYPE_METHOD, &MethodNode);
-    if (ACPI_SUCCESS (Status))
-    {
-        /*
-         * The _REG method is optional and there can be only one per
-         * region definition. This will be executed when the handler is
-         * attached or removed.
-         */
-        RegionObj2->Extra.Method_REG = MethodNode;
-    }
-    if (RegionObj2->Extra.Method_REG == NULL)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* _REG(DISCONNECT) should be paired with _REG(CONNECT) */
-
-    if ((Function == ACPI_REG_CONNECT &&
-        RegionObj->Common.Flags & AOPOBJ_REG_CONNECTED) ||
-        (Function == ACPI_REG_DISCONNECT &&
-         !(RegionObj->Common.Flags & AOPOBJ_REG_CONNECTED)))
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Allocate and initialize the evaluation information block */
-
-    Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
-    if (!Info)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    Info->PrefixNode = RegionObj2->Extra.Method_REG;
-    Info->RelativePathname = NULL;
-    Info->Parameters = Args;
-    Info->Flags = ACPI_IGNORE_RETURN_VALUE;
-
-    /*
-     * The _REG method has two arguments:
-     *
-     * Arg0 - Integer:
-     *  Operation region space ID Same value as RegionObj->Region.SpaceId
-     *
-     * Arg1 - Integer:
-     *  connection status 1 for connecting the handler, 0 for disconnecting
-     *  the handler (Passed as a parameter)
-     */
-    Args[0] = AcpiUtCreateIntegerObject ((UINT64) RegionObj->Region.SpaceId);
-    if (!Args[0])
-    {
-        Status = AE_NO_MEMORY;
-        goto Cleanup1;
-    }
-
-    Args[1] = AcpiUtCreateIntegerObject ((UINT64) Function);
-    if (!Args[1])
-    {
-        Status = AE_NO_MEMORY;
-        goto Cleanup2;
-    }
-
-    Args[2] = NULL; /* Terminate list */
-
-    /* Execute the method, no return value */
-
-    ACPI_DEBUG_EXEC (
-        AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, Info->PrefixNode, NULL));
-
-    Status = AcpiNsEvaluate (Info);
-    AcpiUtRemoveReference (Args[1]);
-
-    if (ACPI_FAILURE (Status))
-    {
-        goto Cleanup2;
-    }
-
-    if (Function == ACPI_REG_CONNECT)
-    {
-        RegionObj->Common.Flags |= AOPOBJ_REG_CONNECTED;
-    }
-    else
-    {
-        RegionObj->Common.Flags &= ~AOPOBJ_REG_CONNECTED;
-    }
-
-Cleanup2:
-    AcpiUtRemoveReference (Args[0]);
-
-Cleanup1:
-    ACPI_FREE (Info);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvExecuteRegMethods
- *
- * PARAMETERS:  Node            - Namespace node for the device
- *              SpaceId         - The address space ID
- *              Function        - Passed to _REG: On (1) or Off (0)
- *
- * RETURN:      None
- *
- * DESCRIPTION: Run all _REG methods for the input Space ID;
- *              Note: assumes namespace is locked, or system init time.
- *
- ******************************************************************************/
-
-void
-AcpiEvExecuteRegMethods (
-    ACPI_NAMESPACE_NODE     *Node,
-    ACPI_ADR_SPACE_TYPE     SpaceId,
-    UINT32                  Function)
-{
-    ACPI_REG_WALK_INFO      Info;
-
-
-    ACPI_FUNCTION_TRACE (EvExecuteRegMethods);
-
-    /*
-     * These address spaces do not need a call to _REG, since the ACPI
-     * specification defines them as: "must always be accessible". Since
-     * they never change state (never become unavailable), no need to ever
-     * call _REG on them. Also, a DataTable is not a "real" address space,
-     * so do not call _REG. September 2018.
-     */
-    if ((SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY) ||
-        (SpaceId == ACPI_ADR_SPACE_SYSTEM_IO) ||
-        (SpaceId == ACPI_ADR_SPACE_DATA_TABLE))
-    {
-        return_VOID;
-    }
-
-    Info.SpaceId = SpaceId;
-    Info.Function = Function;
-    Info.RegRunCount = 0;
-
-    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_NAMES,
-        "    Running _REG methods for SpaceId %s\n",
-        AcpiUtGetRegionName (Info.SpaceId)));
-
-    /*
-     * Run all _REG methods for all Operation Regions for this space ID. This
-     * is a separate walk in order to handle any interdependencies between
-     * regions and _REG methods. (i.e. handlers must be installed for all
-     * regions of this Space ID before we can run any _REG methods)
-     */
-    (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
-        ACPI_NS_WALK_UNLOCK, AcpiEvRegRun, NULL, &Info, NULL);
-
-    /* Special case for EC: handle "orphan" _REG methods with no region */
-
-    if (SpaceId == ACPI_ADR_SPACE_EC)
-    {
-        AcpiEvOrphanEcRegMethod (Node);
-    }
-
-    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_NAMES,
-        "    Executed %u _REG methods for SpaceId %s\n",
-        Info.RegRunCount, AcpiUtGetRegionName (Info.SpaceId)));
-
-    return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvRegRun
- *
- * PARAMETERS:  WalkNamespace callback
- *
- * DESCRIPTION: Run _REG method for region objects of the requested spaceID
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiEvRegRun (
-    ACPI_HANDLE             ObjHandle,
-    UINT32                  Level,
-    void                    *Context,
-    void                    **ReturnValue)
-{
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_STATUS             Status;
-    ACPI_REG_WALK_INFO      *Info;
-
-
-    Info = ACPI_CAST_PTR (ACPI_REG_WALK_INFO, Context);
-
-    /* Convert and validate the device handle */
-
-    Node = AcpiNsValidateHandle (ObjHandle);
-    if (!Node)
-    {
-        return (AE_BAD_PARAMETER);
-    }
-
-    /*
-     * We only care about regions and objects that are allowed to have
-     * address space handlers
-     */
-    if ((Node->Type != ACPI_TYPE_REGION) &&
-        (Node != AcpiGbl_RootNode))
-    {
-        return (AE_OK);
-    }
-
-    /* Check for an existing internal object */
-
-    ObjDesc = AcpiNsGetAttachedObject (Node);
-    if (!ObjDesc)
-    {
-        /* No object, just exit */
-
-        return (AE_OK);
-    }
-
-    /* Object is a Region */
-
-    if (ObjDesc->Region.SpaceId != Info->SpaceId)
-    {
-        /* This region is for a different address space, just ignore it */
-
-        return (AE_OK);
-    }
-
-    Info->RegRunCount++;
-    Status = AcpiEvExecuteRegMethod (ObjDesc, Info->Function);
-    return (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvOrphanEcRegMethod
- *
- * PARAMETERS:  EcDeviceNode        - Namespace node for an EC device
- *
- * RETURN:      None
- *
- * DESCRIPTION: Execute an "orphan" _REG method that appears under the EC
- *              device. This is a _REG method that has no corresponding region
- *              within the EC device scope. The orphan _REG method appears to
- *              have been enabled by the description of the ECDT in the ACPI
- *              specification: "The availability of the region space can be
- *              detected by providing a _REG method object underneath the
- *              Embedded Controller device."
- *
- *              To quickly access the EC device, we use the EcDeviceNode used
- *              during EC handler installation. Otherwise, we would need to
- *              perform a time consuming namespace walk, executing _HID
- *              methods to find the EC device.
- *
- *  MUTEX:      Assumes the namespace is locked
- *
- ******************************************************************************/
-
-static void
-AcpiEvOrphanEcRegMethod (
-    ACPI_NAMESPACE_NODE     *EcDeviceNode)
-{
-    ACPI_HANDLE             RegMethod;
-    ACPI_NAMESPACE_NODE     *NextNode;
-    ACPI_STATUS             Status;
-    ACPI_OBJECT_LIST        Args;
-    ACPI_OBJECT             Objects[2];
-
-
-    ACPI_FUNCTION_TRACE (EvOrphanEcRegMethod);
-
-
-    if (!EcDeviceNode)
-    {
-        return_VOID;
-    }
-
-    /* Namespace is currently locked, must release */
-
-    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
-
-    /* Get a handle to a _REG method immediately under the EC device */
-
-    Status = AcpiGetHandle (EcDeviceNode, METHOD_NAME__REG, &RegMethod);
-    if (ACPI_FAILURE (Status))
-    {
-        goto Exit; /* There is no _REG method present */
-    }
-
-    /*
-     * Execute the _REG method only if there is no Operation Region in
-     * this scope with the Embedded Controller space ID. Otherwise, it
-     * will already have been executed. Note, this allows for Regions
-     * with other space IDs to be present; but the code below will then
-     * execute the _REG method with the EmbeddedControl SpaceID argument.
-     */
-    NextNode = AcpiNsGetNextNode (EcDeviceNode, NULL);
-    while (NextNode)
-    {
-        if ((NextNode->Type == ACPI_TYPE_REGION) &&
-            (NextNode->Object) &&
-            (NextNode->Object->Region.SpaceId == ACPI_ADR_SPACE_EC))
-        {
-            goto Exit; /* Do not execute the _REG */
-        }
-
-        NextNode = AcpiNsGetNextNode (EcDeviceNode, NextNode);
-    }
-
-    /* Evaluate the _REG(EmbeddedControl,Connect) method */
-
-    Args.Count = 2;
-    Args.Pointer = Objects;
-    Objects[0].Type = ACPI_TYPE_INTEGER;
-    Objects[0].Integer.Value = ACPI_ADR_SPACE_EC;
-    Objects[1].Type = ACPI_TYPE_INTEGER;
-    Objects[1].Integer.Value = ACPI_REG_CONNECT;
-
-    Status = AcpiEvaluateObject (RegMethod, NULL, &Args, NULL);
-
-Exit:
-    /* We ignore all errors from above, don't care */
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
-    return_VOID;
-}

+ 0 - 663
h2o/localdep/acpica/events/evrgnini.c

@@ -1,663 +0,0 @@
-/******************************************************************************
- *
- * Module Name: evrgnini- ACPI AddressSpace (OpRegion) init
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acevents.h"
-#include "acnamesp.h"
-#include "acinterp.h"
-
-#define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evrgnini")
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvSystemMemoryRegionSetup
- *
- * PARAMETERS:  Handle              - Region we are interested in
- *              Function            - Start or stop
- *              HandlerContext      - Address space handler context
- *              RegionContext       - Region specific context
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Setup a SystemMemory operation region
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvSystemMemoryRegionSetup (
-    ACPI_HANDLE             Handle,
-    UINT32                  Function,
-    void                    *HandlerContext,
-    void                    **RegionContext)
-{
-    ACPI_OPERAND_OBJECT     *RegionDesc = (ACPI_OPERAND_OBJECT *) Handle;
-    ACPI_MEM_SPACE_CONTEXT  *LocalRegionContext;
-
-
-    ACPI_FUNCTION_TRACE (EvSystemMemoryRegionSetup);
-
-
-    if (Function == ACPI_REGION_DEACTIVATE)
-    {
-        if (*RegionContext)
-        {
-            LocalRegionContext = (ACPI_MEM_SPACE_CONTEXT *) *RegionContext;
-
-            /* Delete a cached mapping if present */
-
-            if (LocalRegionContext->MappedLength)
-            {
-                AcpiOsUnmapMemory (LocalRegionContext->MappedLogicalAddress,
-                    LocalRegionContext->MappedLength);
-            }
-            ACPI_FREE (LocalRegionContext);
-            *RegionContext = NULL;
-        }
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Create a new context */
-
-    LocalRegionContext = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_MEM_SPACE_CONTEXT));
-    if (!(LocalRegionContext))
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    /* Save the region length and address for use in the handler */
-
-    LocalRegionContext->Length  = RegionDesc->Region.Length;
-    LocalRegionContext->Address = RegionDesc->Region.Address;
-
-    *RegionContext = LocalRegionContext;
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvIoSpaceRegionSetup
- *
- * PARAMETERS:  Handle              - Region we are interested in
- *              Function            - Start or stop
- *              HandlerContext      - Address space handler context
- *              RegionContext       - Region specific context
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Setup a IO operation region
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvIoSpaceRegionSetup (
-    ACPI_HANDLE             Handle,
-    UINT32                  Function,
-    void                    *HandlerContext,
-    void                    **RegionContext)
-{
-    ACPI_FUNCTION_TRACE (EvIoSpaceRegionSetup);
-
-
-    if (Function == ACPI_REGION_DEACTIVATE)
-    {
-        *RegionContext = NULL;
-    }
-    else
-    {
-        *RegionContext = HandlerContext;
-    }
-
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvPciConfigRegionSetup
- *
- * PARAMETERS:  Handle              - Region we are interested in
- *              Function            - Start or stop
- *              HandlerContext      - Address space handler context
- *              RegionContext       - Region specific context
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Setup a PCI_Config operation region
- *
- * MUTEX:       Assumes namespace is not locked
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvPciConfigRegionSetup (
-    ACPI_HANDLE             Handle,
-    UINT32                  Function,
-    void                    *HandlerContext,
-    void                    **RegionContext)
-{
-    ACPI_STATUS             Status = AE_OK;
-    UINT64                  PciValue;
-    ACPI_PCI_ID             *PciId = *RegionContext;
-    ACPI_OPERAND_OBJECT     *HandlerObj;
-    ACPI_NAMESPACE_NODE     *ParentNode;
-    ACPI_NAMESPACE_NODE     *PciRootNode;
-    ACPI_NAMESPACE_NODE     *PciDeviceNode;
-    ACPI_OPERAND_OBJECT     *RegionObj = (ACPI_OPERAND_OBJECT  *) Handle;
-
-
-    ACPI_FUNCTION_TRACE (EvPciConfigRegionSetup);
-
-
-    HandlerObj = RegionObj->Region.Handler;
-    if (!HandlerObj)
-    {
-        /*
-         * No installed handler. This shouldn't happen because the dispatch
-         * routine checks before we get here, but we check again just in case.
-         */
-        ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-            "Attempting to init a region %p, with no handler\n", RegionObj));
-        return_ACPI_STATUS (AE_NOT_EXIST);
-    }
-
-    *RegionContext = NULL;
-    if (Function == ACPI_REGION_DEACTIVATE)
-    {
-        if (PciId)
-        {
-            ACPI_FREE (PciId);
-        }
-        return_ACPI_STATUS (Status);
-    }
-
-    ParentNode = RegionObj->Region.Node->Parent;
-
-    /*
-     * Get the _SEG and _BBN values from the device upon which the handler
-     * is installed.
-     *
-     * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
-     * This is the device the handler has been registered to handle.
-     */
-
-    /*
-     * If the AddressSpace.Node is still pointing to the root, we need
-     * to scan upward for a PCI Root bridge and re-associate the OpRegion
-     * handlers with that device.
-     */
-    if (HandlerObj->AddressSpace.Node == AcpiGbl_RootNode)
-    {
-        /* Start search from the parent object */
-
-        PciRootNode = ParentNode;
-        while (PciRootNode != AcpiGbl_RootNode)
-        {
-            /* Get the _HID/_CID in order to detect a RootBridge */
-
-            if (AcpiEvIsPciRootBridge (PciRootNode))
-            {
-                /* Install a handler for this PCI root bridge */
-
-                Status = AcpiInstallAddressSpaceHandler (
-                    (ACPI_HANDLE) PciRootNode,
-                    ACPI_ADR_SPACE_PCI_CONFIG,
-                    ACPI_DEFAULT_HANDLER, NULL, NULL);
-                if (ACPI_FAILURE (Status))
-                {
-                    if (Status == AE_SAME_HANDLER)
-                    {
-                        /*
-                         * It is OK if the handler is already installed on the
-                         * root bridge. Still need to return a context object
-                         * for the new PCI_Config operation region, however.
-                         */
-                        Status = AE_OK;
-                    }
-                    else
-                    {
-                        ACPI_EXCEPTION ((AE_INFO, Status,
-                            "Could not install PciConfig handler "
-                            "for Root Bridge %4.4s",
-                            AcpiUtGetNodeName (PciRootNode)));
-                    }
-                }
-                break;
-            }
-
-            PciRootNode = PciRootNode->Parent;
-        }
-
-        /* PCI root bridge not found, use namespace root node */
-    }
-    else
-    {
-        PciRootNode = HandlerObj->AddressSpace.Node;
-    }
-
-    /*
-     * If this region is now initialized, we are done.
-     * (InstallAddressSpaceHandler could have initialized it)
-     */
-    if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Region is still not initialized. Create a new context */
-
-    PciId = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PCI_ID));
-    if (!PciId)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    /*
-     * For PCI_Config space access, we need the segment, bus, device and
-     * function numbers. Acquire them here.
-     *
-     * Find the parent device object. (This allows the operation region to be
-     * within a subscope under the device, such as a control method.)
-     */
-    PciDeviceNode = RegionObj->Region.Node;
-    while (PciDeviceNode && (PciDeviceNode->Type != ACPI_TYPE_DEVICE))
-    {
-        PciDeviceNode = PciDeviceNode->Parent;
-    }
-
-    if (!PciDeviceNode)
-    {
-        ACPI_FREE (PciId);
-        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
-    }
-
-    /*
-     * Get the PCI device and function numbers from the _ADR object
-     * contained in the parent's scope.
-     */
-    Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR,
-        PciDeviceNode, &PciValue);
-
-    /*
-     * The default is zero, and since the allocation above zeroed the data,
-     * just do nothing on failure.
-     */
-    if (ACPI_SUCCESS (Status))
-    {
-        PciId->Device   = ACPI_HIWORD (ACPI_LODWORD (PciValue));
-        PciId->Function = ACPI_LOWORD (ACPI_LODWORD (PciValue));
-    }
-
-    /* The PCI segment number comes from the _SEG method */
-
-    Status = AcpiUtEvaluateNumericObject (METHOD_NAME__SEG,
-        PciRootNode, &PciValue);
-    if (ACPI_SUCCESS (Status))
-    {
-        PciId->Segment = ACPI_LOWORD (PciValue);
-    }
-
-    /* The PCI bus number comes from the _BBN method */
-
-    Status = AcpiUtEvaluateNumericObject (METHOD_NAME__BBN,
-        PciRootNode, &PciValue);
-    if (ACPI_SUCCESS (Status))
-    {
-        PciId->Bus = ACPI_LOWORD (PciValue);
-    }
-
-    /* Complete/update the PCI ID for this device */
-
-    Status = AcpiHwDerivePciId (PciId, PciRootNode, RegionObj->Region.Node);
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_FREE (PciId);
-        return_ACPI_STATUS (Status);
-    }
-
-    *RegionContext = PciId;
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvIsPciRootBridge
- *
- * PARAMETERS:  Node            - Device node being examined
- *
- * RETURN:      TRUE if device is a PCI/PCI-Express Root Bridge
- *
- * DESCRIPTION: Determine if the input device represents a PCI Root Bridge by
- *              examining the _HID and _CID for the device.
- *
- ******************************************************************************/
-
-BOOLEAN
-AcpiEvIsPciRootBridge (
-    ACPI_NAMESPACE_NODE     *Node)
-{
-    ACPI_STATUS             Status;
-    ACPI_PNP_DEVICE_ID      *Hid;
-    ACPI_PNP_DEVICE_ID_LIST *Cid;
-    UINT32                  i;
-    BOOLEAN                 Match;
-
-
-    /* Get the _HID and check for a PCI Root Bridge */
-
-    Status = AcpiUtExecute_HID (Node, &Hid);
-    if (ACPI_FAILURE (Status))
-    {
-        return (FALSE);
-    }
-
-    Match = AcpiUtIsPciRootBridge (Hid->String);
-    ACPI_FREE (Hid);
-
-    if (Match)
-    {
-        return (TRUE);
-    }
-
-    /* The _HID did not match. Get the _CID and check for a PCI Root Bridge */
-
-    Status = AcpiUtExecute_CID (Node, &Cid);
-    if (ACPI_FAILURE (Status))
-    {
-        return (FALSE);
-    }
-
-    /* Check all _CIDs in the returned list */
-
-    for (i = 0; i < Cid->Count; i++)
-    {
-        if (AcpiUtIsPciRootBridge (Cid->Ids[i].String))
-        {
-            ACPI_FREE (Cid);
-            return (TRUE);
-        }
-    }
-
-    ACPI_FREE (Cid);
-    return (FALSE);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvPciBarRegionSetup
- *
- * PARAMETERS:  Handle              - Region we are interested in
- *              Function            - Start or stop
- *              HandlerContext      - Address space handler context
- *              RegionContext       - Region specific context
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Setup a PciBAR operation region
- *
- * MUTEX:       Assumes namespace is not locked
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvPciBarRegionSetup (
-    ACPI_HANDLE             Handle,
-    UINT32                  Function,
-    void                    *HandlerContext,
-    void                    **RegionContext)
-{
-    ACPI_FUNCTION_TRACE (EvPciBarRegionSetup);
-
-
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvCmosRegionSetup
- *
- * PARAMETERS:  Handle              - Region we are interested in
- *              Function            - Start or stop
- *              HandlerContext      - Address space handler context
- *              RegionContext       - Region specific context
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Setup a CMOS operation region
- *
- * MUTEX:       Assumes namespace is not locked
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvCmosRegionSetup (
-    ACPI_HANDLE             Handle,
-    UINT32                  Function,
-    void                    *HandlerContext,
-    void                    **RegionContext)
-{
-    ACPI_FUNCTION_TRACE (EvCmosRegionSetup);
-
-
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvDefaultRegionSetup
- *
- * PARAMETERS:  Handle              - Region we are interested in
- *              Function            - Start or stop
- *              HandlerContext      - Address space handler context
- *              RegionContext       - Region specific context
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Default region initialization
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvDefaultRegionSetup (
-    ACPI_HANDLE             Handle,
-    UINT32                  Function,
-    void                    *HandlerContext,
-    void                    **RegionContext)
-{
-    ACPI_FUNCTION_TRACE (EvDefaultRegionSetup);
-
-
-    if (Function == ACPI_REGION_DEACTIVATE)
-    {
-        *RegionContext = NULL;
-    }
-    else
-    {
-        *RegionContext = HandlerContext;
-    }
-
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvInitializeRegion
- *
- * PARAMETERS:  RegionObj       - Region we are initializing
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Initializes the region, finds any _REG methods and saves them
- *              for execution at a later time
- *
- *              Get the appropriate address space handler for a newly
- *              created region.
- *
- *              This also performs address space specific initialization. For
- *              example, PCI regions must have an _ADR object that contains
- *              a PCI address in the scope of the definition. This address is
- *              required to perform an access to PCI config space.
- *
- * MUTEX:       Interpreter should be unlocked, because we may run the _REG
- *              method for this region.
- *
- * NOTE:        Possible incompliance:
- *              There is a behavior conflict in automatic _REG execution:
- *              1. When the interpreter is evaluating a method, we can only
- *                 automatically run _REG for the following case:
- *                   Method(_REG, 2) {}
- *                   OperationRegion (OPR1, 0x80, 0x1000010, 0x4)
- *              2. When the interpreter is loading a table, we can also
- *                 automatically run _REG for the following case:
- *                   OperationRegion (OPR1, 0x80, 0x1000010, 0x4)
- *                   Method(_REG, 2) {}
- *              Though this may not be compliant to the de-facto standard, the
- *              logic is kept in order not to trigger regressions. And keeping
- *              this logic should be taken care by the caller of this function.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvInitializeRegion (
-    ACPI_OPERAND_OBJECT     *RegionObj)
-{
-    ACPI_OPERAND_OBJECT     *HandlerObj;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_ADR_SPACE_TYPE     SpaceId;
-    ACPI_NAMESPACE_NODE     *Node;
-
-
-    ACPI_FUNCTION_TRACE (EvInitializeRegion);
-
-
-    if (!RegionObj)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    if (RegionObj->Common.Flags & AOPOBJ_OBJECT_INITIALIZED)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    RegionObj->Common.Flags |= AOPOBJ_OBJECT_INITIALIZED;
-
-    Node = RegionObj->Region.Node->Parent;
-    SpaceId = RegionObj->Region.SpaceId;
-
-    /*
-     * The following loop depends upon the root Node having no parent
-     * ie: AcpiGbl_RootNode->Parent being set to NULL
-     */
-    while (Node)
-    {
-        /* Check to see if a handler exists */
-
-        HandlerObj = NULL;
-        ObjDesc = AcpiNsGetAttachedObject (Node);
-        if (ObjDesc)
-        {
-            /* Can only be a handler if the object exists */
-
-            switch (Node->Type)
-            {
-            case ACPI_TYPE_DEVICE:
-            case ACPI_TYPE_PROCESSOR:
-            case ACPI_TYPE_THERMAL:
-
-                HandlerObj = ObjDesc->CommonNotify.Handler;
-                break;
-
-            default:
-
-                /* Ignore other objects */
-
-                break;
-            }
-
-            HandlerObj = AcpiEvFindRegionHandler (SpaceId, HandlerObj);
-            if (HandlerObj)
-            {
-                /* Found correct handler */
-
-                ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-                    "Found handler %p for region %p in obj %p\n",
-                    HandlerObj, RegionObj, ObjDesc));
-
-                (void) AcpiEvAttachRegion (HandlerObj, RegionObj, FALSE);
-
-                /*
-                 * Tell all users that this region is usable by
-                 * running the _REG method
-                 */
-                AcpiExExitInterpreter ();
-                (void) AcpiEvExecuteRegMethod (RegionObj, ACPI_REG_CONNECT);
-                AcpiExEnterInterpreter ();
-                return_ACPI_STATUS (AE_OK);
-            }
-        }
-
-        /* This node does not have the handler we need; Pop up one level */
-
-        Node = Node->Parent;
-    }
-
-    /*
-     * If we get here, there is no handler for this region. This is not
-     * fatal because many regions get created before a handler is installed
-     * for said region.
-     */
-    ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-        "No handler for RegionType %s(%X) (RegionObj %p)\n",
-        AcpiUtGetRegionName (SpaceId), SpaceId, RegionObj));
-
-    return_ACPI_STATUS (AE_OK);
-}

+ 0 - 282
h2o/localdep/acpica/events/evsci.c

@@ -1,282 +0,0 @@
-/*******************************************************************************
- *
- * Module Name: evsci - System Control Interrupt configuration and
- *                      legacy to ACPI mode state transition functions
- *
- ******************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acevents.h"
-
-
-#define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evsci")
-
-#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
-
-/* Local prototypes */
-
-static UINT32 ACPI_SYSTEM_XFACE
-AcpiEvSciXruptHandler (
-    void                    *Context);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvSciDispatch
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status code indicates whether interrupt was handled.
- *
- * DESCRIPTION: Dispatch the SCI to all host-installed SCI handlers.
- *
- ******************************************************************************/
-
-UINT32
-AcpiEvSciDispatch (
-    void)
-{
-    ACPI_SCI_HANDLER_INFO   *SciHandler;
-    ACPI_CPU_FLAGS          Flags;
-    UINT32                  IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
-
-
-    ACPI_FUNCTION_NAME (EvSciDispatch);
-
-
-    /* Are there any host-installed SCI handlers? */
-
-    if (!AcpiGbl_SciHandlerList)
-    {
-        return (IntStatus);
-    }
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /* Invoke all host-installed SCI handlers */
-
-    SciHandler = AcpiGbl_SciHandlerList;
-    while (SciHandler)
-    {
-        /* Invoke the installed handler (at interrupt level) */
-
-        IntStatus |= SciHandler->Address (
-            SciHandler->Context);
-
-        SciHandler = SciHandler->Next;
-    }
-
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    return (IntStatus);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvSciXruptHandler
- *
- * PARAMETERS:  Context   - Calling Context
- *
- * RETURN:      Status code indicates whether interrupt was handled.
- *
- * DESCRIPTION: Interrupt handler that will figure out what function or
- *              control method to call to deal with a SCI.
- *
- ******************************************************************************/
-
-static UINT32 ACPI_SYSTEM_XFACE
-AcpiEvSciXruptHandler (
-    void                    *Context)
-{
-    ACPI_GPE_XRUPT_INFO     *GpeXruptList = Context;
-    UINT32                  InterruptHandled = ACPI_INTERRUPT_NOT_HANDLED;
-
-
-    ACPI_FUNCTION_TRACE (EvSciXruptHandler);
-
-
-    /*
-     * We are guaranteed by the ACPICA initialization/shutdown code that
-     * if this interrupt handler is installed, ACPI is enabled.
-     */
-
-    /*
-     * Fixed Events:
-     * Check for and dispatch any Fixed Events that have occurred
-     */
-    InterruptHandled |= AcpiEvFixedEventDetect ();
-
-    /*
-     * General Purpose Events:
-     * Check for and dispatch any GPEs that have occurred
-     */
-    InterruptHandled |= AcpiEvGpeDetect (GpeXruptList);
-
-    /* Invoke all host-installed SCI handlers */
-
-    InterruptHandled |= AcpiEvSciDispatch ();
-
-    AcpiSciCount++;
-    return_UINT32 (InterruptHandled);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvGpeXruptHandler
- *
- * PARAMETERS:  Context   - Calling Context
- *
- * RETURN:      Status code indicates whether interrupt was handled.
- *
- * DESCRIPTION: Handler for GPE Block Device interrupts
- *
- ******************************************************************************/
-
-UINT32 ACPI_SYSTEM_XFACE
-AcpiEvGpeXruptHandler (
-    void                    *Context)
-{
-    ACPI_GPE_XRUPT_INFO     *GpeXruptList = Context;
-    UINT32                  InterruptHandled = ACPI_INTERRUPT_NOT_HANDLED;
-
-
-    ACPI_FUNCTION_TRACE (EvGpeXruptHandler);
-
-
-    /*
-     * We are guaranteed by the ACPICA initialization/shutdown code that
-     * if this interrupt handler is installed, ACPI is enabled.
-     */
-
-    /* GPEs: Check for and dispatch any GPEs that have occurred */
-
-    InterruptHandled |= AcpiEvGpeDetect (GpeXruptList);
-    return_UINT32 (InterruptHandled);
-}
-
-
-/******************************************************************************
- *
- * FUNCTION:    AcpiEvInstallSciHandler
- *
- * PARAMETERS:  none
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Installs SCI handler.
- *
- ******************************************************************************/
-
-UINT32
-AcpiEvInstallSciHandler (
-    void)
-{
-    UINT32                  Status = AE_OK;
-
-
-    ACPI_FUNCTION_TRACE (EvInstallSciHandler);
-
-
-    Status = AcpiOsInstallInterruptHandler ((UINT32) AcpiGbl_FADT.SciInterrupt,
-        AcpiEvSciXruptHandler, AcpiGbl_GpeXruptListHead);
-    return_ACPI_STATUS (Status);
-}
-
-
-/******************************************************************************
- *
- * FUNCTION:    AcpiEvRemoveAllSciHandlers
- *
- * PARAMETERS:  none
- *
- * RETURN:      AE_OK if handler uninstalled, AE_ERROR if handler was not
- *              installed to begin with
- *
- * DESCRIPTION: Remove the SCI interrupt handler. No further SCIs will be
- *              taken. Remove all host-installed SCI handlers.
- *
- * Note:  It doesn't seem important to disable all events or set the event
- *        enable registers to their original values. The OS should disable
- *        the SCI interrupt level when the handler is removed, so no more
- *        events will come in.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEvRemoveAllSciHandlers (
-    void)
-{
-    ACPI_SCI_HANDLER_INFO   *SciHandler;
-    ACPI_CPU_FLAGS          Flags;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (EvRemoveAllSciHandlers);
-
-
-    /* Just let the OS remove the handler and disable the level */
-
-    Status = AcpiOsRemoveInterruptHandler ((UINT32) AcpiGbl_FADT.SciInterrupt,
-        AcpiEvSciXruptHandler);
-
-    if (!AcpiGbl_SciHandlerList)
-    {
-        return (Status);
-    }
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /* Free all host-installed SCI handlers */
-
-    while (AcpiGbl_SciHandlerList)
-    {
-        SciHandler = AcpiGbl_SciHandlerList;
-        AcpiGbl_SciHandlerList = SciHandler->Next;
-        ACPI_FREE (SciHandler);
-    }
-
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    return_ACPI_STATUS (Status);
-}
-
-#endif /* !ACPI_REDUCED_HARDWARE */

+ 0 - 1268
h2o/localdep/acpica/events/evxface.c

@@ -1,1268 +0,0 @@
-/******************************************************************************
- *
- * Module Name: evxface - External interfaces for ACPI events
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#define EXPORT_ACPI_INTERFACES
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acnamesp.h"
-#include "acevents.h"
-#include "acinterp.h"
-
-#define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evxface")
-
-#if (!ACPI_REDUCED_HARDWARE)
-
-/* Local prototypes */
-
-static ACPI_STATUS
-AcpiEvInstallGpeHandler (
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber,
-    UINT32                  Type,
-    BOOLEAN                 IsRawHandler,
-    ACPI_GPE_HANDLER        Address,
-    void                    *Context);
-
-#endif
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiInstallNotifyHandler
- *
- * PARAMETERS:  Device          - The device for which notifies will be handled
- *              HandlerType     - The type of handler:
- *                                  ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
- *                                  ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
- *                                  ACPI_ALL_NOTIFY:    Both System and Device
- *              Handler         - Address of the handler
- *              Context         - Value passed to the handler on each GPE
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Install a handler for notifications on an ACPI Device,
- *              ThermalZone, or Processor object.
- *
- * NOTES:       The Root namespace object may have only one handler for each
- *              type of notify (System/Device). Device/Thermal/Processor objects
- *              may have one device notify handler, and multiple system notify
- *              handlers.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiInstallNotifyHandler (
-    ACPI_HANDLE             Device,
-    UINT32                  HandlerType,
-    ACPI_NOTIFY_HANDLER     Handler,
-    void                    *Context)
-{
-    ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Device);
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_OPERAND_OBJECT     *HandlerObj;
-    ACPI_STATUS             Status;
-    UINT32                  i;
-
-
-    ACPI_FUNCTION_TRACE (AcpiInstallNotifyHandler);
-
-
-    /* Parameter validation */
-
-    if ((!Device) || (!Handler) || (!HandlerType) ||
-        (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /*
-     * Root Object:
-     * Registering a notify handler on the root object indicates that the
-     * caller wishes to receive notifications for all objects. Note that
-     * only one global handler can be registered per notify type.
-     * Ensure that a handler is not already installed.
-     */
-    if (Device == ACPI_ROOT_OBJECT)
-    {
-        for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
-        {
-            if (HandlerType & (i+1))
-            {
-                if (AcpiGbl_GlobalNotify[i].Handler)
-                {
-                    Status = AE_ALREADY_EXISTS;
-                    goto UnlockAndExit;
-                }
-
-                AcpiGbl_GlobalNotify[i].Handler = Handler;
-                AcpiGbl_GlobalNotify[i].Context = Context;
-            }
-        }
-
-        goto UnlockAndExit; /* Global notify handler installed, all done */
-    }
-
-    /*
-     * All Other Objects:
-     * Caller will only receive notifications specific to the target
-     * object. Note that only certain object types are allowed to
-     * receive notifications.
-     */
-
-    /* Are Notifies allowed on this object? */
-
-    if (!AcpiEvIsNotifyObject (Node))
-    {
-        Status = AE_TYPE;
-        goto UnlockAndExit;
-    }
-
-    /* Check for an existing internal object, might not exist */
-
-    ObjDesc = AcpiNsGetAttachedObject (Node);
-    if (!ObjDesc)
-    {
-        /* Create a new object */
-
-        ObjDesc = AcpiUtCreateInternalObject (Node->Type);
-        if (!ObjDesc)
-        {
-            Status = AE_NO_MEMORY;
-            goto UnlockAndExit;
-        }
-
-        /* Attach new object to the Node, remove local reference */
-
-        Status = AcpiNsAttachObject (Device, ObjDesc, Node->Type);
-        AcpiUtRemoveReference (ObjDesc);
-        if (ACPI_FAILURE (Status))
-        {
-            goto UnlockAndExit;
-        }
-    }
-
-    /* Ensure that the handler is not already installed in the lists */
-
-    for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
-    {
-        if (HandlerType & (i+1))
-        {
-            HandlerObj = ObjDesc->CommonNotify.NotifyList[i];
-            while (HandlerObj)
-            {
-                if (HandlerObj->Notify.Handler == Handler)
-                {
-                    Status = AE_ALREADY_EXISTS;
-                    goto UnlockAndExit;
-                }
-
-                HandlerObj = HandlerObj->Notify.Next[i];
-            }
-        }
-    }
-
-    /* Create and populate a new notify handler object */
-
-    HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_NOTIFY);
-    if (!HandlerObj)
-    {
-        Status = AE_NO_MEMORY;
-        goto UnlockAndExit;
-    }
-
-    HandlerObj->Notify.Node = Node;
-    HandlerObj->Notify.HandlerType = HandlerType;
-    HandlerObj->Notify.Handler = Handler;
-    HandlerObj->Notify.Context = Context;
-
-    /* Install the handler at the list head(s) */
-
-    for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
-    {
-        if (HandlerType & (i+1))
-        {
-            HandlerObj->Notify.Next[i] =
-                ObjDesc->CommonNotify.NotifyList[i];
-
-            ObjDesc->CommonNotify.NotifyList[i] = HandlerObj;
-        }
-    }
-
-    /* Add an extra reference if handler was installed in both lists */
-
-    if (HandlerType == ACPI_ALL_NOTIFY)
-    {
-        AcpiUtAddReference (HandlerObj);
-    }
-
-
-UnlockAndExit:
-    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiInstallNotifyHandler)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiRemoveNotifyHandler
- *
- * PARAMETERS:  Device          - The device for which the handler is installed
- *              HandlerType     - The type of handler:
- *                                  ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
- *                                  ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
- *                                  ACPI_ALL_NOTIFY:    Both System and Device
- *              Handler         - Address of the handler
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Remove a handler for notifies on an ACPI device
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiRemoveNotifyHandler (
-    ACPI_HANDLE             Device,
-    UINT32                  HandlerType,
-    ACPI_NOTIFY_HANDLER     Handler)
-{
-    ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Device);
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_OPERAND_OBJECT     *HandlerObj;
-    ACPI_OPERAND_OBJECT     *PreviousHandlerObj;
-    ACPI_STATUS             Status = AE_OK;
-    UINT32                  i;
-
-
-    ACPI_FUNCTION_TRACE (AcpiRemoveNotifyHandler);
-
-
-    /* Parameter validation */
-
-    if ((!Device) || (!Handler) || (!HandlerType) ||
-        (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    /* Root Object. Global handlers are removed here */
-
-    if (Device == ACPI_ROOT_OBJECT)
-    {
-        for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
-        {
-            if (HandlerType & (i+1))
-            {
-                Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
-                if (ACPI_FAILURE (Status))
-                {
-                    return_ACPI_STATUS (Status);
-                }
-
-                if (!AcpiGbl_GlobalNotify[i].Handler ||
-                    (AcpiGbl_GlobalNotify[i].Handler != Handler))
-                {
-                    Status = AE_NOT_EXIST;
-                    goto UnlockAndExit;
-                }
-
-                ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
-                    "Removing global notify handler\n"));
-
-                AcpiGbl_GlobalNotify[i].Handler = NULL;
-                AcpiGbl_GlobalNotify[i].Context = NULL;
-
-                (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
-
-                /* Make sure all deferred notify tasks are completed */
-
-                AcpiOsWaitEventsComplete ();
-            }
-        }
-
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* All other objects: Are Notifies allowed on this object? */
-
-    if (!AcpiEvIsNotifyObject (Node))
-    {
-        return_ACPI_STATUS (AE_TYPE);
-    }
-
-    /* Must have an existing internal object */
-
-    ObjDesc = AcpiNsGetAttachedObject (Node);
-    if (!ObjDesc)
-    {
-        return_ACPI_STATUS (AE_NOT_EXIST);
-    }
-
-    /* Internal object exists. Find the handler and remove it */
-
-    for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
-    {
-        if (HandlerType & (i+1))
-        {
-            Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
-            if (ACPI_FAILURE (Status))
-            {
-                return_ACPI_STATUS (Status);
-            }
-
-            HandlerObj = ObjDesc->CommonNotify.NotifyList[i];
-            PreviousHandlerObj = NULL;
-
-            /* Attempt to find the handler in the handler list */
-
-            while (HandlerObj &&
-                  (HandlerObj->Notify.Handler != Handler))
-            {
-                PreviousHandlerObj = HandlerObj;
-                HandlerObj = HandlerObj->Notify.Next[i];
-            }
-
-            if (!HandlerObj)
-            {
-                Status = AE_NOT_EXIST;
-                goto UnlockAndExit;
-            }
-
-            /* Remove the handler object from the list */
-
-            if (PreviousHandlerObj) /* Handler is not at the list head */
-            {
-                PreviousHandlerObj->Notify.Next[i] =
-                    HandlerObj->Notify.Next[i];
-            }
-            else /* Handler is at the list head */
-            {
-                ObjDesc->CommonNotify.NotifyList[i] =
-                    HandlerObj->Notify.Next[i];
-            }
-
-            (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
-
-            /* Make sure all deferred notify tasks are completed */
-
-            AcpiOsWaitEventsComplete ();
-            AcpiUtRemoveReference (HandlerObj);
-        }
-    }
-
-    return_ACPI_STATUS (Status);
-
-
-UnlockAndExit:
-    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiRemoveNotifyHandler)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiInstallExceptionHandler
- *
- * PARAMETERS:  Handler         - Pointer to the handler function for the
- *                                event
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Saves the pointer to the handler function
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiInstallExceptionHandler (
-    ACPI_EXCEPTION_HANDLER  Handler)
-{
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (AcpiInstallExceptionHandler);
-
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Don't allow two handlers. */
-
-    if (AcpiGbl_ExceptionHandler)
-    {
-        Status = AE_ALREADY_EXISTS;
-        goto Cleanup;
-    }
-
-    /* Install the handler */
-
-    AcpiGbl_ExceptionHandler = Handler;
-
-Cleanup:
-    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiInstallExceptionHandler)
-
-
-#if (!ACPI_REDUCED_HARDWARE)
-/*******************************************************************************
- *
- * FUNCTION:    AcpiInstallSciHandler
- *
- * PARAMETERS:  Address             - Address of the handler
- *              Context             - Value passed to the handler on each SCI
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Install a handler for a System Control Interrupt.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiInstallSciHandler (
-    ACPI_SCI_HANDLER        Address,
-    void                    *Context)
-{
-    ACPI_SCI_HANDLER_INFO   *NewSciHandler;
-    ACPI_SCI_HANDLER_INFO   *SciHandler;
-    ACPI_CPU_FLAGS          Flags;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (AcpiInstallSciHandler);
-
-
-    if (!Address)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    /* Allocate and init a handler object */
-
-    NewSciHandler = ACPI_ALLOCATE (sizeof (ACPI_SCI_HANDLER_INFO));
-    if (!NewSciHandler)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    NewSciHandler->Address = Address;
-    NewSciHandler->Context = Context;
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
-    if (ACPI_FAILURE (Status))
-    {
-        goto Exit;
-    }
-
-    /* Lock list during installation */
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-    SciHandler = AcpiGbl_SciHandlerList;
-
-    /* Ensure handler does not already exist */
-
-    while (SciHandler)
-    {
-        if (Address == SciHandler->Address)
-        {
-            Status = AE_ALREADY_EXISTS;
-            goto UnlockAndExit;
-        }
-
-        SciHandler = SciHandler->Next;
-    }
-
-    /* Install the new handler into the global list (at head) */
-
-    NewSciHandler->Next = AcpiGbl_SciHandlerList;
-    AcpiGbl_SciHandlerList = NewSciHandler;
-
-
-UnlockAndExit:
-
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-
-Exit:
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_FREE (NewSciHandler);
-    }
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiInstallSciHandler)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiRemoveSciHandler
- *
- * PARAMETERS:  Address             - Address of the handler
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Remove a handler for a System Control Interrupt.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiRemoveSciHandler (
-    ACPI_SCI_HANDLER        Address)
-{
-    ACPI_SCI_HANDLER_INFO   *PrevSciHandler;
-    ACPI_SCI_HANDLER_INFO   *NextSciHandler;
-    ACPI_CPU_FLAGS          Flags;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (AcpiRemoveSciHandler);
-
-
-    if (!Address)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Remove the SCI handler with lock */
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    PrevSciHandler = NULL;
-    NextSciHandler = AcpiGbl_SciHandlerList;
-    while (NextSciHandler)
-    {
-        if (NextSciHandler->Address == Address)
-        {
-            /* Unlink and free the SCI handler info block */
-
-            if (PrevSciHandler)
-            {
-                PrevSciHandler->Next = NextSciHandler->Next;
-            }
-            else
-            {
-                AcpiGbl_SciHandlerList = NextSciHandler->Next;
-            }
-
-            AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-            ACPI_FREE (NextSciHandler);
-            goto UnlockAndExit;
-        }
-
-        PrevSciHandler = NextSciHandler;
-        NextSciHandler = NextSciHandler->Next;
-    }
-
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    Status = AE_NOT_EXIST;
-
-
-UnlockAndExit:
-    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiRemoveSciHandler)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiInstallGlobalEventHandler
- *
- * PARAMETERS:  Handler         - Pointer to the global event handler function
- *              Context         - Value passed to the handler on each event
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Saves the pointer to the handler function. The global handler
- *              is invoked upon each incoming GPE and Fixed Event. It is
- *              invoked at interrupt level at the time of the event dispatch.
- *              Can be used to update event counters, etc.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiInstallGlobalEventHandler (
-    ACPI_GBL_EVENT_HANDLER  Handler,
-    void                    *Context)
-{
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (AcpiInstallGlobalEventHandler);
-
-
-    /* Parameter validation */
-
-    if (!Handler)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Don't allow two handlers. */
-
-    if (AcpiGbl_GlobalEventHandler)
-    {
-        Status = AE_ALREADY_EXISTS;
-        goto Cleanup;
-    }
-
-    AcpiGbl_GlobalEventHandler = Handler;
-    AcpiGbl_GlobalEventHandlerContext = Context;
-
-
-Cleanup:
-    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiInstallGlobalEventHandler)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiInstallFixedEventHandler
- *
- * PARAMETERS:  Event           - Event type to enable.
- *              Handler         - Pointer to the handler function for the
- *                                event
- *              Context         - Value passed to the handler on each GPE
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Saves the pointer to the handler function and then enables the
- *              event.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiInstallFixedEventHandler (
-    UINT32                  Event,
-    ACPI_EVENT_HANDLER      Handler,
-    void                    *Context)
-{
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (AcpiInstallFixedEventHandler);
-
-
-    /* Parameter validation */
-
-    if (Event > ACPI_EVENT_MAX)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Do not allow multiple handlers */
-
-    if (AcpiGbl_FixedEventHandlers[Event].Handler)
-    {
-        Status = AE_ALREADY_EXISTS;
-        goto Cleanup;
-    }
-
-    /* Install the handler before enabling the event */
-
-    AcpiGbl_FixedEventHandlers[Event].Handler = Handler;
-    AcpiGbl_FixedEventHandlers[Event].Context = Context;
-
-    Status = AcpiEnableEvent (Event, 0);
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_WARNING ((AE_INFO,
-            "Could not enable fixed event - %s (%u)",
-            AcpiUtGetEventName (Event), Event));
-
-        /* Remove the handler */
-
-        AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
-        AcpiGbl_FixedEventHandlers[Event].Context = NULL;
-    }
-    else
-    {
-        ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
-            "Enabled fixed event %s (%X), Handler=%p\n",
-            AcpiUtGetEventName (Event), Event, Handler));
-    }
-
-
-Cleanup:
-    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiInstallFixedEventHandler)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiRemoveFixedEventHandler
- *
- * PARAMETERS:  Event           - Event type to disable.
- *              Handler         - Address of the handler
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Disables the event and unregisters the event handler.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiRemoveFixedEventHandler (
-    UINT32                  Event,
-    ACPI_EVENT_HANDLER      Handler)
-{
-    ACPI_STATUS             Status = AE_OK;
-
-
-    ACPI_FUNCTION_TRACE (AcpiRemoveFixedEventHandler);
-
-
-    /* Parameter validation */
-
-    if (Event > ACPI_EVENT_MAX)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Disable the event before removing the handler */
-
-    Status = AcpiDisableEvent (Event, 0);
-
-    /* Always Remove the handler */
-
-    AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
-    AcpiGbl_FixedEventHandlers[Event].Context = NULL;
-
-    if (ACPI_FAILURE (Status))
-    {
-        ACPI_WARNING ((AE_INFO,
-            "Could not disable fixed event - %s (%u)",
-            AcpiUtGetEventName (Event), Event));
-    }
-    else
-    {
-        ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
-            "Disabled fixed event - %s (%X)\n",
-            AcpiUtGetEventName (Event), Event));
-    }
-
-    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiRemoveFixedEventHandler)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEvInstallGpeHandler
- *
- * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT
- *                                defined GPEs)
- *              GpeNumber       - The GPE number within the GPE block
- *              Type            - Whether this GPE should be treated as an
- *                                edge- or level-triggered interrupt.
- *              IsRawHandler    - Whether this GPE should be handled using
- *                                the special GPE handler mode.
- *              Address         - Address of the handler
- *              Context         - Value passed to the handler on each GPE
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Internal function to install a handler for a General Purpose
- *              Event.
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiEvInstallGpeHandler (
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber,
-    UINT32                  Type,
-    BOOLEAN                 IsRawHandler,
-    ACPI_GPE_HANDLER        Address,
-    void                    *Context)
-{
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    ACPI_GPE_HANDLER_INFO   *Handler;
-    ACPI_STATUS             Status;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (EvInstallGpeHandler);
-
-
-    /* Parameter validation */
-
-    if ((!Address) || (Type & ~ACPI_GPE_XRUPT_TYPE_MASK))
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Allocate and init handler object (before lock) */
-
-    Handler = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_HANDLER_INFO));
-    if (!Handler)
-    {
-        Status = AE_NO_MEMORY;
-        goto UnlockAndExit;
-    }
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /* Ensure that we have a valid GPE number */
-
-    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
-    if (!GpeEventInfo)
-    {
-        Status = AE_BAD_PARAMETER;
-        goto FreeAndExit;
-    }
-
-    /* Make sure that there isn't a handler there already */
-
-    if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
-            ACPI_GPE_DISPATCH_HANDLER) ||
-        (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
-            ACPI_GPE_DISPATCH_RAW_HANDLER))
-    {
-        Status = AE_ALREADY_EXISTS;
-        goto FreeAndExit;
-    }
-
-    Handler->Address = Address;
-    Handler->Context = Context;
-    Handler->MethodNode = GpeEventInfo->Dispatch.MethodNode;
-    Handler->OriginalFlags = (UINT8) (GpeEventInfo->Flags &
-        (ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK));
-
-    /*
-     * If the GPE is associated with a method, it may have been enabled
-     * automatically during initialization, in which case it has to be
-     * disabled now to avoid spurious execution of the handler.
-     */
-    if (((ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
-            ACPI_GPE_DISPATCH_METHOD) ||
-         (ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
-            ACPI_GPE_DISPATCH_NOTIFY)) &&
-        GpeEventInfo->RuntimeCount)
-    {
-        Handler->OriginallyEnabled = TRUE;
-        (void) AcpiEvRemoveGpeReference (GpeEventInfo);
-
-        /* Sanity check of original type against new type */
-
-        if (Type != (UINT32) (GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK))
-        {
-            ACPI_WARNING ((AE_INFO, "GPE type mismatch (level/edge)"));
-        }
-    }
-
-    /* Install the handler */
-
-    GpeEventInfo->Dispatch.Handler = Handler;
-
-    /* Setup up dispatch flags to indicate handler (vs. method/notify) */
-
-    GpeEventInfo->Flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
-    GpeEventInfo->Flags |= (UINT8) (Type | (IsRawHandler ?
-        ACPI_GPE_DISPATCH_RAW_HANDLER : ACPI_GPE_DISPATCH_HANDLER));
-
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-
-
-UnlockAndExit:
-    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-    return_ACPI_STATUS (Status);
-
-FreeAndExit:
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    ACPI_FREE (Handler);
-    goto UnlockAndExit;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiInstallGpeHandler
- *
- * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT
- *                                defined GPEs)
- *              GpeNumber       - The GPE number within the GPE block
- *              Type            - Whether this GPE should be treated as an
- *                                edge- or level-triggered interrupt.
- *              Address         - Address of the handler
- *              Context         - Value passed to the handler on each GPE
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Install a handler for a General Purpose Event.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiInstallGpeHandler (
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber,
-    UINT32                  Type,
-    ACPI_GPE_HANDLER        Address,
-    void                    *Context)
-{
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler);
-
-
-    Status = AcpiEvInstallGpeHandler (GpeDevice, GpeNumber, Type,
-        FALSE, Address, Context);
-
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiInstallGpeHandler)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiInstallGpeRawHandler
- *
- * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT
- *                                defined GPEs)
- *              GpeNumber       - The GPE number within the GPE block
- *              Type            - Whether this GPE should be treated as an
- *                                edge- or level-triggered interrupt.
- *              Address         - Address of the handler
- *              Context         - Value passed to the handler on each GPE
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Install a handler for a General Purpose Event.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiInstallGpeRawHandler (
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber,
-    UINT32                  Type,
-    ACPI_GPE_HANDLER        Address,
-    void                    *Context)
-{
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (AcpiInstallGpeRawHandler);
-
-
-    Status = AcpiEvInstallGpeHandler (GpeDevice, GpeNumber, Type,
-        TRUE, Address, Context);
-
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiInstallGpeRawHandler)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiRemoveGpeHandler
- *
- * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT
- *                                defined GPEs)
- *              GpeNumber       - The event to remove a handler
- *              Address         - Address of the handler
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiRemoveGpeHandler (
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber,
-    ACPI_GPE_HANDLER        Address)
-{
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    ACPI_GPE_HANDLER_INFO   *Handler;
-    ACPI_STATUS             Status;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (AcpiRemoveGpeHandler);
-
-
-    /* Parameter validation */
-
-    if (!Address)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /* Ensure that we have a valid GPE number */
-
-    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
-    if (!GpeEventInfo)
-    {
-        Status = AE_BAD_PARAMETER;
-        goto UnlockAndExit;
-    }
-
-    /* Make sure that a handler is indeed installed */
-
-    if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
-            ACPI_GPE_DISPATCH_HANDLER) &&
-        (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
-            ACPI_GPE_DISPATCH_RAW_HANDLER))
-    {
-        Status = AE_NOT_EXIST;
-        goto UnlockAndExit;
-    }
-
-    /* Make sure that the installed handler is the same */
-
-    if (GpeEventInfo->Dispatch.Handler->Address != Address)
-    {
-        Status = AE_BAD_PARAMETER;
-        goto UnlockAndExit;
-    }
-
-    /* Remove the handler */
-
-    Handler = GpeEventInfo->Dispatch.Handler;
-    GpeEventInfo->Dispatch.Handler = NULL;
-
-    /* Restore Method node (if any), set dispatch flags */
-
-    GpeEventInfo->Dispatch.MethodNode = Handler->MethodNode;
-    GpeEventInfo->Flags &=
-        ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
-    GpeEventInfo->Flags |= Handler->OriginalFlags;
-
-    /*
-     * If the GPE was previously associated with a method and it was
-     * enabled, it should be enabled at this point to restore the
-     * post-initialization configuration.
-     */
-    if (((ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
-            ACPI_GPE_DISPATCH_METHOD) ||
-         (ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
-            ACPI_GPE_DISPATCH_NOTIFY)) &&
-        Handler->OriginallyEnabled)
-    {
-        (void) AcpiEvAddGpeReference (GpeEventInfo);
-        if (ACPI_GPE_IS_POLLING_NEEDED (GpeEventInfo))
-        {
-            /* Poll edge triggered GPEs to handle existing events */
-
-            AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-            (void) AcpiEvDetectGpe (
-                GpeDevice, GpeEventInfo, GpeNumber);
-            Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-        }
-    }
-
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-
-    /* Make sure all deferred GPE tasks are completed */
-
-    AcpiOsWaitEventsComplete ();
-
-    /* Now we can free the handler object */
-
-    ACPI_FREE (Handler);
-    return_ACPI_STATUS (Status);
-
-UnlockAndExit:
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiRemoveGpeHandler)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiAcquireGlobalLock
- *
- * PARAMETERS:  Timeout         - How long the caller is willing to wait
- *              Handle          - Where the handle to the lock is returned
- *                                (if acquired)
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Acquire the ACPI Global Lock
- *
- * Note: Allows callers with the same thread ID to acquire the global lock
- * multiple times. In other words, externally, the behavior of the global lock
- * is identical to an AML mutex. On the first acquire, a new handle is
- * returned. On any subsequent calls to acquire by the same thread, the same
- * handle is returned.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiAcquireGlobalLock (
-    UINT16                  Timeout,
-    UINT32                  *Handle)
-{
-    ACPI_STATUS             Status;
-
-
-    if (!Handle)
-    {
-        return (AE_BAD_PARAMETER);
-    }
-
-    /* Must lock interpreter to prevent race conditions */
-
-    AcpiExEnterInterpreter ();
-
-    Status = AcpiExAcquireMutexObject (Timeout,
-        AcpiGbl_GlobalLockMutex, AcpiOsGetThreadId ());
-
-    if (ACPI_SUCCESS (Status))
-    {
-        /* Return the global lock handle (updated in AcpiEvAcquireGlobalLock) */
-
-        *Handle = AcpiGbl_GlobalLockHandle;
-    }
-
-    AcpiExExitInterpreter ();
-    return (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiAcquireGlobalLock)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiReleaseGlobalLock
- *
- * PARAMETERS:  Handle      - Returned from AcpiAcquireGlobalLock
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiReleaseGlobalLock (
-    UINT32                  Handle)
-{
-    ACPI_STATUS             Status;
-
-
-    if (!Handle || (Handle != AcpiGbl_GlobalLockHandle))
-    {
-        return (AE_NOT_ACQUIRED);
-    }
-
-    Status = AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex);
-    return (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiReleaseGlobalLock)
-
-#endif /* !ACPI_REDUCED_HARDWARE */

+ 0 - 451
h2o/localdep/acpica/events/evxfevnt.c

@@ -1,451 +0,0 @@
-/******************************************************************************
- *
- * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#define EXPORT_ACPI_INTERFACES
-
-#include "acpi.h"
-#include "accommon.h"
-#include "actables.h"
-
-#define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evxfevnt")
-
-
-#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEnable
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Transfers the system into ACPI mode.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEnable (
-    void)
-{
-    ACPI_STATUS             Status = AE_OK;
-
-
-    ACPI_FUNCTION_TRACE (AcpiEnable);
-
-
-    /* ACPI tables must be present */
-
-    if (AcpiGbl_FadtIndex == ACPI_INVALID_TABLE_INDEX)
-    {
-        return_ACPI_STATUS (AE_NO_ACPI_TABLES);
-    }
-
-    /* If the Hardware Reduced flag is set, machine is always in acpi mode */
-
-    if (AcpiGbl_ReducedHardware)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Check current mode */
-
-    if (AcpiHwGetMode() == ACPI_SYS_MODE_ACPI)
-    {
-        ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
-            "System is already in ACPI mode\n"));
-    }
-    else
-    {
-        /* Transition to ACPI mode */
-
-        Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI);
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_ERROR ((AE_INFO, "Could not transition to ACPI mode"));
-            return_ACPI_STATUS (Status);
-        }
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
-            "Transition to ACPI mode successful\n"));
-    }
-
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiEnable)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDisable
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDisable (
-    void)
-{
-    ACPI_STATUS             Status = AE_OK;
-
-
-    ACPI_FUNCTION_TRACE (AcpiDisable);
-
-
-    /* If the Hardware Reduced flag is set, machine is always in acpi mode */
-
-    if (AcpiGbl_ReducedHardware)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY)
-    {
-        ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
-            "System is already in legacy (non-ACPI) mode\n"));
-    }
-    else
-    {
-        /* Transition to LEGACY mode */
-
-        Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY);
-
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_ERROR ((AE_INFO,
-                "Could not exit ACPI mode to legacy mode"));
-            return_ACPI_STATUS (Status);
-        }
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
-            "ACPI mode disabled\n"));
-    }
-
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiDisable)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEnableEvent
- *
- * PARAMETERS:  Event           - The fixed eventto be enabled
- *              Flags           - Reserved
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Enable an ACPI event (fixed)
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEnableEvent (
-    UINT32                  Event,
-    UINT32                  Flags)
-{
-    ACPI_STATUS             Status = AE_OK;
-    UINT32                  Value;
-
-
-    ACPI_FUNCTION_TRACE (AcpiEnableEvent);
-
-
-    /* If Hardware Reduced flag is set, there are no fixed events */
-
-    if (AcpiGbl_ReducedHardware)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Decode the Fixed Event */
-
-    if (Event > ACPI_EVENT_MAX)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    /*
-     * Enable the requested fixed event (by writing a one to the enable
-     * register bit)
-     */
-    Status = AcpiWriteBitRegister (
-        AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
-        ACPI_ENABLE_EVENT);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Make sure that the hardware responded */
-
-    Status = AcpiReadBitRegister (
-        AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    if (Value != 1)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "Could not enable %s event", AcpiUtGetEventName (Event)));
-        return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
-    }
-
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiEnableEvent)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDisableEvent
- *
- * PARAMETERS:  Event           - The fixed event to be disabled
- *              Flags           - Reserved
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Disable an ACPI event (fixed)
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDisableEvent (
-    UINT32                  Event,
-    UINT32                  Flags)
-{
-    ACPI_STATUS             Status = AE_OK;
-    UINT32                  Value;
-
-
-    ACPI_FUNCTION_TRACE (AcpiDisableEvent);
-
-
-    /* If Hardware Reduced flag is set, there are no fixed events */
-
-    if (AcpiGbl_ReducedHardware)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Decode the Fixed Event */
-
-    if (Event > ACPI_EVENT_MAX)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    /*
-     * Disable the requested fixed event (by writing a zero to the enable
-     * register bit)
-     */
-    Status = AcpiWriteBitRegister (
-        AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
-        ACPI_DISABLE_EVENT);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    Status = AcpiReadBitRegister (
-        AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    if (Value != 0)
-    {
-        ACPI_ERROR ((AE_INFO,
-            "Could not disable %s events", AcpiUtGetEventName (Event)));
-        return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
-    }
-
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiDisableEvent)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiClearEvent
- *
- * PARAMETERS:  Event           - The fixed event to be cleared
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Clear an ACPI event (fixed)
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiClearEvent (
-    UINT32                  Event)
-{
-    ACPI_STATUS             Status = AE_OK;
-
-
-    ACPI_FUNCTION_TRACE (AcpiClearEvent);
-
-
-    /* If Hardware Reduced flag is set, there are no fixed events */
-
-    if (AcpiGbl_ReducedHardware)
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Decode the Fixed Event */
-
-    if (Event > ACPI_EVENT_MAX)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    /*
-     * Clear the requested fixed event (By writing a one to the status
-     * register bit)
-     */
-    Status = AcpiWriteBitRegister (
-        AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
-        ACPI_CLEAR_STATUS);
-
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiClearEvent)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiGetEventStatus
- *
- * PARAMETERS:  Event           - The fixed event
- *              EventStatus     - Where the current status of the event will
- *                                be returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Obtains and returns the current status of the event
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiGetEventStatus (
-    UINT32                  Event,
-    ACPI_EVENT_STATUS       *EventStatus)
-{
-    ACPI_STATUS             Status;
-    ACPI_EVENT_STATUS       LocalEventStatus = 0;
-    UINT32                  InByte;
-
-
-    ACPI_FUNCTION_TRACE (AcpiGetEventStatus);
-
-
-    if (!EventStatus)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    /* Decode the Fixed Event */
-
-    if (Event > ACPI_EVENT_MAX)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    /* Fixed event currently can be dispatched? */
-
-    if (AcpiGbl_FixedEventHandlers[Event].Handler)
-    {
-        LocalEventStatus |= ACPI_EVENT_FLAG_HAS_HANDLER;
-    }
-
-    /* Fixed event currently enabled? */
-
-    Status = AcpiReadBitRegister (
-        AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &InByte);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    if (InByte)
-    {
-        LocalEventStatus |=
-            (ACPI_EVENT_FLAG_ENABLED | ACPI_EVENT_FLAG_ENABLE_SET);
-    }
-
-    /* Fixed event currently active? */
-
-    Status = AcpiReadBitRegister (
-        AcpiGbl_FixedEventInfo[Event].StatusRegisterId, &InByte);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    if (InByte)
-    {
-        LocalEventStatus |= ACPI_EVENT_FLAG_STATUS_SET;
-    }
-
-    (*EventStatus) = LocalEventStatus;
-    return_ACPI_STATUS (AE_OK);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiGetEventStatus)
-
-#endif /* !ACPI_REDUCED_HARDWARE */

+ 0 - 1182
h2o/localdep/acpica/events/evxfgpe.c

@@ -1,1182 +0,0 @@
-/******************************************************************************
- *
- * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#define EXPORT_ACPI_INTERFACES
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acevents.h"
-#include "acnamesp.h"
-
-#define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evxfgpe")
-
-
-#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
-/*******************************************************************************
- *
- * FUNCTION:    AcpiUpdateAllGpes
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
- *              associated _Lxx or _Exx methods and are not pointed to by any
- *              device _PRW methods (this indicates that these GPEs are
- *              generally intended for system or device wakeup. Such GPEs
- *              have to be enabled directly when the devices whose _PRW
- *              methods point to them are set up for wakeup signaling.)
- *
- * NOTE: Should be called after any GPEs are added to the system. Primarily,
- * after the system _PRW methods have been run, but also after a GPE Block
- * Device has been added or if any new GPE methods have been added via a
- * dynamic table load.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiUpdateAllGpes (
-    void)
-{
-    ACPI_STATUS             Status;
-    BOOLEAN                 IsPollingNeeded = FALSE;
-
-
-    ACPI_FUNCTION_TRACE (AcpiUpdateAllGpes);
-
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    if (AcpiGbl_AllGpesInitialized)
-    {
-        goto UnlockAndExit;
-    }
-
-    Status = AcpiEvWalkGpeList (AcpiEvInitializeGpeBlock,
-        &IsPollingNeeded);
-    if (ACPI_SUCCESS (Status))
-    {
-        AcpiGbl_AllGpesInitialized = TRUE;
-    }
-
-UnlockAndExit:
-    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-
-    if (IsPollingNeeded && AcpiGbl_AllGpesInitialized)
-    {
-        /* Poll GPEs to handle already triggered events */
-
-        AcpiEvGpeDetect (AcpiGbl_GpeXruptListHead);
-    }
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiUpdateAllGpes)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiEnableGpe
- *
- * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
- *              GpeNumber           - GPE level within the GPE block
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
- *              hardware-enabled.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEnableGpe (
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber)
-{
-    ACPI_STATUS             Status = AE_BAD_PARAMETER;
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (AcpiEnableGpe);
-
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /*
-     * Ensure that we have a valid GPE number and that there is some way
-     * of handling the GPE (handler or a GPE method). In other words, we
-     * won't allow a valid GPE to be enabled if there is no way to handle it.
-     */
-    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
-    if (GpeEventInfo)
-    {
-        if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
-            ACPI_GPE_DISPATCH_NONE)
-        {
-            Status = AcpiEvAddGpeReference (GpeEventInfo);
-            if (ACPI_SUCCESS (Status) &&
-                ACPI_GPE_IS_POLLING_NEEDED (GpeEventInfo))
-            {
-                /* Poll edge-triggered GPEs to handle existing events */
-
-                AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-                (void) AcpiEvDetectGpe (
-                    GpeDevice, GpeEventInfo, GpeNumber);
-                Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-            }
-        }
-        else
-        {
-            Status = AE_NO_HANDLER;
-        }
-    }
-
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiEnableGpe)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDisableGpe
- *
- * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
- *              GpeNumber           - GPE level within the GPE block
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Remove a reference to a GPE. When the last reference is
- *              removed, only then is the GPE disabled (for runtime GPEs), or
- *              the GPE mask bit disabled (for wake GPEs)
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDisableGpe (
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber)
-{
-    ACPI_STATUS             Status = AE_BAD_PARAMETER;
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (AcpiDisableGpe);
-
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /* Ensure that we have a valid GPE number */
-
-    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
-    if (GpeEventInfo)
-    {
-        Status = AcpiEvRemoveGpeReference (GpeEventInfo);
-    }
-
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiDisableGpe)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiSetGpe
- *
- * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
- *              GpeNumber           - GPE level within the GPE block
- *              Action              - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
- *              the reference count mechanism used in the AcpiEnableGpe(),
- *              AcpiDisableGpe() interfaces.
- *              This API is typically used by the GPE raw handler mode driver
- *              to switch between the polling mode and the interrupt mode after
- *              the driver has enabled the GPE.
- *              The APIs should be invoked in this order:
- *               AcpiEnableGpe()              <- Ensure the reference count > 0
- *               AcpiSetGpe(ACPI_GPE_DISABLE) <- Enter polling mode
- *               AcpiSetGpe(ACPI_GPE_ENABLE)  <- Leave polling mode
- *               AcpiDisableGpe()             <- Decrease the reference count
- *
- * Note: If a GPE is shared by 2 silicon components, then both the drivers
- *       should support GPE polling mode or disabling the GPE for long period
- *       for one driver may break the other. So use it with care since all
- *       firmware _Lxx/_Exx handlers currently rely on the GPE interrupt mode.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiSetGpe (
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber,
-    UINT8                   Action)
-{
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    ACPI_STATUS             Status;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (AcpiSetGpe);
-
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /* Ensure that we have a valid GPE number */
-
-    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
-    if (!GpeEventInfo)
-    {
-        Status = AE_BAD_PARAMETER;
-        goto UnlockAndExit;
-    }
-
-    /* Perform the action */
-
-    switch (Action)
-    {
-    case ACPI_GPE_ENABLE:
-
-        Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_ENABLE);
-        GpeEventInfo->DisableForDispatch = FALSE;
-        break;
-
-    case ACPI_GPE_DISABLE:
-
-        Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
-        GpeEventInfo->DisableForDispatch = TRUE;
-        break;
-
-    default:
-
-        Status = AE_BAD_PARAMETER;
-        break;
-    }
-
-UnlockAndExit:
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiSetGpe)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiMaskGpe
- *
- * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
- *              GpeNumber           - GPE level within the GPE block
- *              IsMasked            - Whether the GPE is masked or not
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Unconditionally mask/unmask the an individual GPE, ex., to
- *              prevent a GPE flooding.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiMaskGpe (
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber,
-    BOOLEAN                 IsMasked)
-{
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    ACPI_STATUS             Status;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (AcpiMaskGpe);
-
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /* Ensure that we have a valid GPE number */
-
-    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
-    if (!GpeEventInfo)
-    {
-        Status = AE_BAD_PARAMETER;
-        goto UnlockAndExit;
-    }
-
-    Status = AcpiEvMaskGpe (GpeEventInfo, IsMasked);
-
-UnlockAndExit:
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiMaskGpe)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiMarkGpeForWake
- *
- * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
- *              GpeNumber           - GPE level within the GPE block
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Mark a GPE as having the ability to wake the system. Simply
- *              sets the ACPI_GPE_CAN_WAKE flag.
- *
- * Some potential callers of AcpiSetupGpeForWake may know in advance that
- * there won't be any notify handlers installed for device wake notifications
- * from the given GPE (one example is a button GPE in Linux). For these cases,
- * AcpiMarkGpeForWake should be used instead of AcpiSetupGpeForWake.
- * This will set the ACPI_GPE_CAN_WAKE flag for the GPE without trying to
- * setup implicit wake notification for it (since there's no handler method).
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiMarkGpeForWake (
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber)
-{
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    ACPI_STATUS             Status = AE_BAD_PARAMETER;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (AcpiMarkGpeForWake);
-
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /* Ensure that we have a valid GPE number */
-
-    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
-    if (GpeEventInfo)
-    {
-        /* Mark the GPE as a possible wake event */
-
-        GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
-        Status = AE_OK;
-    }
-
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiMarkGpeForWake)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiSetupGpeForWake
- *
- * PARAMETERS:  WakeDevice          - Device associated with the GPE (via _PRW)
- *              GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
- *              GpeNumber           - GPE level within the GPE block
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
- *              interface is intended to be used as the host executes the
- *              _PRW methods (Power Resources for Wake) in the system tables.
- *              Each _PRW appears under a Device Object (The WakeDevice), and
- *              contains the info for the wake GPE associated with the
- *              WakeDevice.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiSetupGpeForWake (
-    ACPI_HANDLE             WakeDevice,
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber)
-{
-    ACPI_STATUS             Status;
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    ACPI_NAMESPACE_NODE     *DeviceNode;
-    ACPI_GPE_NOTIFY_INFO    *Notify;
-    ACPI_GPE_NOTIFY_INFO    *NewNotify;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (AcpiSetupGpeForWake);
-
-
-    /* Parameter Validation */
-
-    if (!WakeDevice)
-    {
-        /*
-         * By forcing WakeDevice to be valid, we automatically enable the
-         * implicit notify feature on all hosts.
-         */
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    /* Handle root object case */
-
-    if (WakeDevice == ACPI_ROOT_OBJECT)
-    {
-        DeviceNode = AcpiGbl_RootNode;
-    }
-    else
-    {
-        DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, WakeDevice);
-    }
-
-    /* Validate WakeDevice is of type Device */
-
-    if (DeviceNode->Type != ACPI_TYPE_DEVICE)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    /*
-     * Allocate a new notify object up front, in case it is needed.
-     * Memory allocation while holding a spinlock is a big no-no
-     * on some hosts.
-     */
-    NewNotify = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_NOTIFY_INFO));
-    if (!NewNotify)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /* Ensure that we have a valid GPE number */
-
-    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
-    if (!GpeEventInfo)
-    {
-        Status = AE_BAD_PARAMETER;
-        goto UnlockAndExit;
-    }
-
-    /*
-     * If there is no method or handler for this GPE, then the
-     * WakeDevice will be notified whenever this GPE fires. This is
-     * known as an "implicit notify". Note: The GPE is assumed to be
-     * level-triggered (for windows compatibility).
-     */
-    if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
-        ACPI_GPE_DISPATCH_NONE)
-    {
-        /*
-         * This is the first device for implicit notify on this GPE.
-         * Just set the flags here, and enter the NOTIFY block below.
-         */
-        GpeEventInfo->Flags =
-            (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
-    }
-    else if (GpeEventInfo->Flags & ACPI_GPE_AUTO_ENABLED)
-    {
-        /*
-         * A reference to this GPE has been added during the GPE block
-         * initialization, so drop it now to prevent the GPE from being
-         * permanently enabled and clear its ACPI_GPE_AUTO_ENABLED flag.
-         */
-        (void) AcpiEvRemoveGpeReference (GpeEventInfo);
-        GpeEventInfo->Flags &= ~~ACPI_GPE_AUTO_ENABLED;
-    }
-
-    /*
-     * If we already have an implicit notify on this GPE, add
-     * this device to the notify list.
-     */
-    if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
-        ACPI_GPE_DISPATCH_NOTIFY)
-    {
-        /* Ensure that the device is not already in the list */
-
-        Notify = GpeEventInfo->Dispatch.NotifyList;
-        while (Notify)
-        {
-            if (Notify->DeviceNode == DeviceNode)
-            {
-                Status = AE_ALREADY_EXISTS;
-                goto UnlockAndExit;
-            }
-            Notify = Notify->Next;
-        }
-
-        /* Add this device to the notify list for this GPE */
-
-        NewNotify->DeviceNode = DeviceNode;
-        NewNotify->Next = GpeEventInfo->Dispatch.NotifyList;
-        GpeEventInfo->Dispatch.NotifyList = NewNotify;
-        NewNotify = NULL;
-    }
-
-    /* Mark the GPE as a possible wake event */
-
-    GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
-    Status = AE_OK;
-
-
-UnlockAndExit:
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-
-    /* Delete the notify object if it was not used above */
-
-    if (NewNotify)
-    {
-        ACPI_FREE (NewNotify);
-    }
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiSetupGpeForWake)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiSetGpeWakeMask
- *
- * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
- *              GpeNumber           - GPE level within the GPE block
- *              Action              - Enable or Disable
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
- *              already be marked as a WAKE GPE.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiSetGpeWakeMask (
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber,
-    UINT8                   Action)
-{
-    ACPI_STATUS             Status = AE_OK;
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
-    ACPI_CPU_FLAGS          Flags;
-    UINT32                  RegisterBit;
-
-
-    ACPI_FUNCTION_TRACE (AcpiSetGpeWakeMask);
-
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /*
-     * Ensure that we have a valid GPE number and that this GPE is in
-     * fact a wake GPE
-     */
-    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
-    if (!GpeEventInfo)
-    {
-        Status = AE_BAD_PARAMETER;
-        goto UnlockAndExit;
-    }
-
-    if (!(GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
-    {
-        Status = AE_TYPE;
-        goto UnlockAndExit;
-    }
-
-    GpeRegisterInfo = GpeEventInfo->RegisterInfo;
-    if (!GpeRegisterInfo)
-    {
-        Status = AE_NOT_EXIST;
-        goto UnlockAndExit;
-    }
-
-    RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
-
-    /* Perform the action */
-
-    switch (Action)
-    {
-    case ACPI_GPE_ENABLE:
-
-        ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
-        break;
-
-    case ACPI_GPE_DISABLE:
-
-        ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
-        break;
-
-    default:
-
-        ACPI_ERROR ((AE_INFO, "%u, Invalid action", Action));
-        Status = AE_BAD_PARAMETER;
-        break;
-    }
-
-UnlockAndExit:
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiSetGpeWakeMask)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiClearGpe
- *
- * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
- *              GpeNumber           - GPE level within the GPE block
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Clear an ACPI event (general purpose)
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiClearGpe (
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber)
-{
-    ACPI_STATUS             Status = AE_OK;
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (AcpiClearGpe);
-
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /* Ensure that we have a valid GPE number */
-
-    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
-    if (!GpeEventInfo)
-    {
-        Status = AE_BAD_PARAMETER;
-        goto UnlockAndExit;
-    }
-
-    Status = AcpiHwClearGpe (GpeEventInfo);
-
-UnlockAndExit:
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiClearGpe)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiGetGpeStatus
- *
- * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
- *              GpeNumber           - GPE level within the GPE block
- *              EventStatus         - Where the current status of the event
- *                                    will be returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiGetGpeStatus (
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber,
-    ACPI_EVENT_STATUS       *EventStatus)
-{
-    ACPI_STATUS             Status = AE_OK;
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (AcpiGetGpeStatus);
-
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /* Ensure that we have a valid GPE number */
-
-    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
-    if (!GpeEventInfo)
-    {
-        Status = AE_BAD_PARAMETER;
-        goto UnlockAndExit;
-    }
-
-    /* Obtain status on the requested GPE number */
-
-    Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
-
-UnlockAndExit:
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiGetGpeStatus)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiFinishGpe
- *
- * PARAMETERS:  GpeDevice           - Namespace node for the GPE Block
- *                                    (NULL for FADT defined GPEs)
- *              GpeNumber           - GPE level within the GPE block
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Clear and conditionally re-enable a GPE. This completes the GPE
- *              processing. Intended for use by asynchronous host-installed
- *              GPE handlers. The GPE is only re-enabled if the EnableForRun bit
- *              is set in the GPE info.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiFinishGpe (
-    ACPI_HANDLE             GpeDevice,
-    UINT32                  GpeNumber)
-{
-    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
-    ACPI_STATUS             Status;
-    ACPI_CPU_FLAGS          Flags;
-
-
-    ACPI_FUNCTION_TRACE (AcpiFinishGpe);
-
-
-    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
-
-    /* Ensure that we have a valid GPE number */
-
-    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
-    if (!GpeEventInfo)
-    {
-        Status = AE_BAD_PARAMETER;
-        goto UnlockAndExit;
-    }
-
-    Status = AcpiEvFinishGpe (GpeEventInfo);
-
-UnlockAndExit:
-    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiFinishGpe)
-
-
-/******************************************************************************
- *
- * FUNCTION:    AcpiDisableAllGpes
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiDisableAllGpes (
-    void)
-{
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (AcpiDisableAllGpes);
-
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    Status = AcpiHwDisableAllGpes ();
-    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiDisableAllGpes)
-
-
-/******************************************************************************
- *
- * FUNCTION:    AcpiEnableAllRuntimeGpes
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEnableAllRuntimeGpes (
-    void)
-{
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (AcpiEnableAllRuntimeGpes);
-
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    Status = AcpiHwEnableAllRuntimeGpes ();
-    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiEnableAllRuntimeGpes)
-
-
-/******************************************************************************
- *
- * FUNCTION:    AcpiEnableAllWakeupGpes
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Enable all "wakeup" GPEs and disable all of the other GPEs, in
- *              all GPE blocks.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiEnableAllWakeupGpes (
-    void)
-{
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (AcpiEnableAllWakeupGpes);
-
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    Status = AcpiHwEnableAllWakeupGpes ();
-    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
-
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiEnableAllWakeupGpes)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiInstallGpeBlock
- *
- * PARAMETERS:  GpeDevice           - Handle to the parent GPE Block Device
- *              GpeBlockAddress     - Address and SpaceID
- *              RegisterCount       - Number of GPE register pairs in the block
- *              InterruptNumber     - H/W interrupt for the block
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
- *              enabled here.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiInstallGpeBlock (
-    ACPI_HANDLE             GpeDevice,
-    ACPI_GENERIC_ADDRESS    *GpeBlockAddress,
-    UINT32                  RegisterCount,
-    UINT32                  InterruptNumber)
-{
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_GPE_BLOCK_INFO     *GpeBlock;
-
-
-    ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
-
-
-    if ((!GpeDevice)       ||
-        (!GpeBlockAddress) ||
-        (!RegisterCount))
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    Node = AcpiNsValidateHandle (GpeDevice);
-    if (!Node)
-    {
-        Status = AE_BAD_PARAMETER;
-        goto UnlockAndExit;
-    }
-
-    /* Validate the parent device */
-
-    if (Node->Type != ACPI_TYPE_DEVICE)
-    {
-        Status = AE_TYPE;
-        goto UnlockAndExit;
-    }
-
-    if (Node->Object)
-    {
-        Status = AE_ALREADY_EXISTS;
-        goto UnlockAndExit;
-    }
-
-    /*
-     * For user-installed GPE Block Devices, the GpeBlockBaseNumber
-     * is always zero
-     */
-    Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress->Address,
-        GpeBlockAddress->SpaceId, RegisterCount,
-        0, InterruptNumber, &GpeBlock);
-    if (ACPI_FAILURE (Status))
-    {
-        goto UnlockAndExit;
-    }
-
-    /* Install block in the DeviceObject attached to the node */
-
-    ObjDesc = AcpiNsGetAttachedObject (Node);
-    if (!ObjDesc)
-    {
-        /*
-         * No object, create a new one (Device nodes do not always have
-         * an attached object)
-         */
-        ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
-        if (!ObjDesc)
-        {
-            Status = AE_NO_MEMORY;
-            goto UnlockAndExit;
-        }
-
-        Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
-
-        /* Remove local reference to the object */
-
-        AcpiUtRemoveReference (ObjDesc);
-        if (ACPI_FAILURE (Status))
-        {
-            goto UnlockAndExit;
-        }
-    }
-
-    /* Now install the GPE block in the DeviceObject */
-
-    ObjDesc->Device.GpeBlock = GpeBlock;
-
-
-UnlockAndExit:
-    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiInstallGpeBlock)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiRemoveGpeBlock
- *
- * PARAMETERS:  GpeDevice           - Handle to the parent GPE Block Device
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Remove a previously installed block of GPE registers
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiRemoveGpeBlock (
-    ACPI_HANDLE             GpeDevice)
-{
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_STATUS             Status;
-    ACPI_NAMESPACE_NODE     *Node;
-
-
-    ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
-
-
-    if (!GpeDevice)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    Node = AcpiNsValidateHandle (GpeDevice);
-    if (!Node)
-    {
-        Status = AE_BAD_PARAMETER;
-        goto UnlockAndExit;
-    }
-
-    /* Validate the parent device */
-
-    if (Node->Type != ACPI_TYPE_DEVICE)
-    {
-        Status = AE_TYPE;
-        goto UnlockAndExit;
-    }
-
-    /* Get the DeviceObject attached to the node */
-
-    ObjDesc = AcpiNsGetAttachedObject (Node);
-    if (!ObjDesc ||
-        !ObjDesc->Device.GpeBlock)
-    {
-        return_ACPI_STATUS (AE_NULL_OBJECT);
-    }
-
-    /* Delete the GPE block (but not the DeviceObject) */
-
-    Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
-    if (ACPI_SUCCESS (Status))
-    {
-        ObjDesc->Device.GpeBlock = NULL;
-    }
-
-UnlockAndExit:
-    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiRemoveGpeBlock)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiGetGpeDevice
- *
- * PARAMETERS:  Index               - System GPE index (0-CurrentGpeCount)
- *              GpeDevice           - Where the parent GPE Device is returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
- *              gpe device indicates that the gpe number is contained in one of
- *              the FADT-defined gpe blocks. Otherwise, the GPE block device.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiGetGpeDevice (
-    UINT32                  Index,
-    ACPI_HANDLE             *GpeDevice)
-{
-    ACPI_GPE_DEVICE_INFO    Info;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (AcpiGetGpeDevice);
-
-
-    if (!GpeDevice)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    if (Index >= AcpiCurrentGpeCount)
-    {
-        return_ACPI_STATUS (AE_NOT_EXIST);
-    }
-
-    /* Setup and walk the GPE list */
-
-    Info.Index = Index;
-    Info.Status = AE_NOT_EXIST;
-    Info.GpeDevice = NULL;
-    Info.NextBlockBaseIndex = 0;
-
-    Status = AcpiEvWalkGpeList (AcpiEvGetGpeDevice, &Info);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    *GpeDevice = ACPI_CAST_PTR (ACPI_HANDLE, Info.GpeDevice);
-    return_ACPI_STATUS (Info.Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiGetGpeDevice)
-
-#endif /* !ACPI_REDUCED_HARDWARE */

+ 0 - 280
h2o/localdep/acpica/events/evxfregn.c

@@ -1,280 +0,0 @@
-/******************************************************************************
- *
- * Module Name: evxfregn - External Interfaces, ACPI Operation Regions and
- *                         Address Spaces.
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#define EXPORT_ACPI_INTERFACES
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acnamesp.h"
-#include "acevents.h"
-
-#define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evxfregn")
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiInstallAddressSpaceHandler
- *
- * PARAMETERS:  Device          - Handle for the device
- *              SpaceId         - The address space ID
- *              Handler         - Address of the handler
- *              Setup           - Address of the setup function
- *              Context         - Value passed to the handler on each access
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
- *
- * NOTE: This function should only be called after AcpiEnableSubsystem has
- * been called. This is because any _REG methods associated with the Space ID
- * are executed here, and these methods can only be safely executed after
- * the default handlers have been installed and the hardware has been
- * initialized (via AcpiEnableSubsystem.)
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiInstallAddressSpaceHandler (
-    ACPI_HANDLE             Device,
-    ACPI_ADR_SPACE_TYPE     SpaceId,
-    ACPI_ADR_SPACE_HANDLER  Handler,
-    ACPI_ADR_SPACE_SETUP    Setup,
-    void                    *Context)
-{
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (AcpiInstallAddressSpaceHandler);
-
-
-    /* Parameter validation */
-
-    if (!Device)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Convert and validate the device handle */
-
-    Node = AcpiNsValidateHandle (Device);
-    if (!Node)
-    {
-        Status = AE_BAD_PARAMETER;
-        goto UnlockAndExit;
-    }
-
-    /* Install the handler for all Regions for this Space ID */
-
-    Status = AcpiEvInstallSpaceHandler (
-        Node, SpaceId, Handler, Setup, Context);
-    if (ACPI_FAILURE (Status))
-    {
-        goto UnlockAndExit;
-    }
-
-    /* Run all _REG methods for this address space */
-
-    AcpiEvExecuteRegMethods (Node, SpaceId, ACPI_REG_CONNECT);
-
-
-UnlockAndExit:
-    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiInstallAddressSpaceHandler)
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiRemoveAddressSpaceHandler
- *
- * PARAMETERS:  Device          - Handle for the device
- *              SpaceId         - The address space ID
- *              Handler         - Address of the handler
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Remove a previously installed handler.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiRemoveAddressSpaceHandler (
-    ACPI_HANDLE             Device,
-    ACPI_ADR_SPACE_TYPE     SpaceId,
-    ACPI_ADR_SPACE_HANDLER  Handler)
-{
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_OPERAND_OBJECT     *HandlerObj;
-    ACPI_OPERAND_OBJECT     *RegionObj;
-    ACPI_OPERAND_OBJECT     **LastObjPtr;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (AcpiRemoveAddressSpaceHandler);
-
-
-    /* Parameter validation */
-
-    if (!Device)
-    {
-        return_ACPI_STATUS (AE_BAD_PARAMETER);
-    }
-
-    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Convert and validate the device handle */
-
-    Node = AcpiNsValidateHandle (Device);
-    if (!Node ||
-        ((Node->Type != ACPI_TYPE_DEVICE)    &&
-         (Node->Type != ACPI_TYPE_PROCESSOR) &&
-         (Node->Type != ACPI_TYPE_THERMAL)   &&
-         (Node != AcpiGbl_RootNode)))
-    {
-        Status = AE_BAD_PARAMETER;
-        goto UnlockAndExit;
-    }
-
-    /* Make sure the internal object exists */
-
-    ObjDesc = AcpiNsGetAttachedObject (Node);
-    if (!ObjDesc)
-    {
-        Status = AE_NOT_EXIST;
-        goto UnlockAndExit;
-    }
-
-    /* Find the address handler the user requested */
-
-    HandlerObj = ObjDesc->CommonNotify.Handler;
-    LastObjPtr = &ObjDesc->CommonNotify.Handler;
-    while (HandlerObj)
-    {
-        /* We have a handler, see if user requested this one */
-
-        if (HandlerObj->AddressSpace.SpaceId == SpaceId)
-        {
-            /* Handler must be the same as the installed handler */
-
-            if (HandlerObj->AddressSpace.Handler != Handler)
-            {
-                Status = AE_BAD_PARAMETER;
-                goto UnlockAndExit;
-            }
-
-            /* Matched SpaceId, first dereference this in the Regions */
-
-            ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-                "Removing address handler %p(%p) for region %s "
-                "on Device %p(%p)\n",
-                HandlerObj, Handler, AcpiUtGetRegionName (SpaceId),
-                Node, ObjDesc));
-
-            RegionObj = HandlerObj->AddressSpace.RegionList;
-
-            /* Walk the handler's region list */
-
-            while (RegionObj)
-            {
-                /*
-                 * First disassociate the handler from the region.
-                 *
-                 * NOTE: this doesn't mean that the region goes away
-                 * The region is just inaccessible as indicated to
-                 * the _REG method
-                 */
-                AcpiEvDetachRegion (RegionObj, TRUE);
-
-                /*
-                 * Walk the list: Just grab the head because the
-                 * DetachRegion removed the previous head.
-                 */
-                RegionObj = HandlerObj->AddressSpace.RegionList;
-            }
-
-            /* Remove this Handler object from the list */
-
-            *LastObjPtr = HandlerObj->AddressSpace.Next;
-
-            /* Now we can delete the handler object */
-
-            AcpiUtRemoveReference (HandlerObj);
-            goto UnlockAndExit;
-        }
-
-        /* Walk the linked list of handlers */
-
-        LastObjPtr = &HandlerObj->AddressSpace.Next;
-        HandlerObj = HandlerObj->AddressSpace.Next;
-    }
-
-    /* The handler does not exist */
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-        "Unable to remove address handler %p for %s(%X), DevNode %p, obj %p\n",
-        Handler, AcpiUtGetRegionName (SpaceId), SpaceId, Node, ObjDesc));
-
-    Status = AE_NOT_EXIST;
-
-UnlockAndExit:
-    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
-    return_ACPI_STATUS (Status);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiRemoveAddressSpaceHandler)

+ 0 - 461
h2o/localdep/acpica/executer/exconcat.c

@@ -1,461 +0,0 @@
-/******************************************************************************
- *
- * Module Name: exconcat - Concatenate-type AML operators
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acinterp.h"
-#include "amlresrc.h"
-
-
-#define _COMPONENT          ACPI_EXECUTER
-        ACPI_MODULE_NAME    ("exconcat")
-
-/* Local Prototypes */
-
-static ACPI_STATUS
-AcpiExConvertToObjectTypeString (
-    ACPI_OPERAND_OBJECT     *ObjDesc,
-    ACPI_OPERAND_OBJECT     **ResultDesc);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExDoConcatenate
- *
- * PARAMETERS:  Operand0            - First source object
- *              Operand1            - Second source object
- *              ActualReturnDesc    - Where to place the return object
- *              WalkState           - Current walk state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Concatenate two objects with the ACPI-defined conversion
- *              rules as necessary.
- * NOTE:
- * Per the ACPI spec (up to 6.1), Concatenate only supports Integer,
- * String, and Buffer objects. However, we support all objects here
- * as an extension. This improves the usefulness of both Concatenate
- * and the Printf/Fprintf macros. The extension returns a string
- * describing the object type for the other objects.
- * 02/2016.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExDoConcatenate (
-    ACPI_OPERAND_OBJECT     *Operand0,
-    ACPI_OPERAND_OBJECT     *Operand1,
-    ACPI_OPERAND_OBJECT     **ActualReturnDesc,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_OPERAND_OBJECT     *LocalOperand0 = Operand0;
-    ACPI_OPERAND_OBJECT     *LocalOperand1 = Operand1;
-    ACPI_OPERAND_OBJECT     *TempOperand1 = NULL;
-    ACPI_OPERAND_OBJECT     *ReturnDesc;
-    char                    *Buffer;
-    ACPI_OBJECT_TYPE        Operand0Type;
-    ACPI_OBJECT_TYPE        Operand1Type;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE (ExDoConcatenate);
-
-
-    /* Operand 0 preprocessing */
-
-    switch (Operand0->Common.Type)
-    {
-    case ACPI_TYPE_INTEGER:
-    case ACPI_TYPE_STRING:
-    case ACPI_TYPE_BUFFER:
-
-        Operand0Type = Operand0->Common.Type;
-        break;
-
-    default:
-
-        /* For all other types, get the "object type" string */
-
-        Status = AcpiExConvertToObjectTypeString (
-            Operand0, &LocalOperand0);
-        if (ACPI_FAILURE (Status))
-        {
-            goto Cleanup;
-        }
-
-        Operand0Type = ACPI_TYPE_STRING;
-        break;
-    }
-
-    /* Operand 1 preprocessing */
-
-    switch (Operand1->Common.Type)
-    {
-    case ACPI_TYPE_INTEGER:
-    case ACPI_TYPE_STRING:
-    case ACPI_TYPE_BUFFER:
-
-        Operand1Type = Operand1->Common.Type;
-        break;
-
-    default:
-
-        /* For all other types, get the "object type" string */
-
-        Status = AcpiExConvertToObjectTypeString (
-            Operand1, &LocalOperand1);
-        if (ACPI_FAILURE (Status))
-        {
-            goto Cleanup;
-        }
-
-        Operand1Type = ACPI_TYPE_STRING;
-        break;
-    }
-
-    /*
-     * Convert the second operand if necessary. The first operand (0)
-     * determines the type of the second operand (1) (See the Data Types
-     * section of the ACPI specification). Both object types are
-     * guaranteed to be either Integer/String/Buffer by the operand
-     * resolution mechanism.
-     */
-    switch (Operand0Type)
-    {
-    case ACPI_TYPE_INTEGER:
-
-        Status = AcpiExConvertToInteger (LocalOperand1, &TempOperand1,
-            ACPI_IMPLICIT_CONVERSION);
-        break;
-
-    case ACPI_TYPE_BUFFER:
-
-        Status = AcpiExConvertToBuffer (LocalOperand1, &TempOperand1);
-        break;
-
-    case ACPI_TYPE_STRING:
-
-        switch (Operand1Type)
-        {
-        case ACPI_TYPE_INTEGER:
-        case ACPI_TYPE_STRING:
-        case ACPI_TYPE_BUFFER:
-
-            /* Other types have already been converted to string */
-
-            Status = AcpiExConvertToString (
-                LocalOperand1, &TempOperand1, ACPI_IMPLICIT_CONVERT_HEX);
-            break;
-
-        default:
-
-            Status = AE_OK;
-            break;
-        }
-        break;
-
-    default:
-
-        ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X",
-            Operand0->Common.Type));
-        Status = AE_AML_INTERNAL;
-    }
-
-    if (ACPI_FAILURE (Status))
-    {
-        goto Cleanup;
-    }
-
-    /* Take care with any newly created operand objects */
-
-    if ((LocalOperand1 != Operand1) &&
-        (LocalOperand1 != TempOperand1))
-    {
-        AcpiUtRemoveReference (LocalOperand1);
-    }
-
-    LocalOperand1 = TempOperand1;
-
-    /*
-     * Both operands are now known to be the same object type
-     * (Both are Integer, String, or Buffer), and we can now perform
-     * the concatenation.
-     *
-     * There are three cases to handle, as per the ACPI spec:
-     *
-     * 1) Two Integers concatenated to produce a new Buffer
-     * 2) Two Strings concatenated to produce a new String
-     * 3) Two Buffers concatenated to produce a new Buffer
-     */
-    switch (Operand0Type)
-    {
-    case ACPI_TYPE_INTEGER:
-
-        /* Result of two Integers is a Buffer */
-        /* Need enough buffer space for two integers */
-
-        ReturnDesc = AcpiUtCreateBufferObject (
-            (ACPI_SIZE) ACPI_MUL_2 (AcpiGbl_IntegerByteWidth));
-        if (!ReturnDesc)
-        {
-            Status = AE_NO_MEMORY;
-            goto Cleanup;
-        }
-
-        Buffer = (char *) ReturnDesc->Buffer.Pointer;
-
-        /* Copy the first integer, LSB first */
-
-        memcpy (Buffer, &Operand0->Integer.Value,
-            AcpiGbl_IntegerByteWidth);
-
-        /* Copy the second integer (LSB first) after the first */
-
-        memcpy (Buffer + AcpiGbl_IntegerByteWidth,
-            &LocalOperand1->Integer.Value, AcpiGbl_IntegerByteWidth);
-        break;
-
-    case ACPI_TYPE_STRING:
-
-        /* Result of two Strings is a String */
-
-        ReturnDesc = AcpiUtCreateStringObject (
-            ((ACPI_SIZE) LocalOperand0->String.Length +
-            LocalOperand1->String.Length));
-        if (!ReturnDesc)
-        {
-            Status = AE_NO_MEMORY;
-            goto Cleanup;
-        }
-
-        Buffer = ReturnDesc->String.Pointer;
-
-        /* Concatenate the strings */
-
-        strcpy (Buffer, LocalOperand0->String.Pointer);
-        strcat (Buffer, LocalOperand1->String.Pointer);
-        break;
-
-    case ACPI_TYPE_BUFFER:
-
-        /* Result of two Buffers is a Buffer */
-
-        ReturnDesc = AcpiUtCreateBufferObject (
-            ((ACPI_SIZE) Operand0->Buffer.Length +
-            LocalOperand1->Buffer.Length));
-        if (!ReturnDesc)
-        {
-            Status = AE_NO_MEMORY;
-            goto Cleanup;
-        }
-
-        Buffer = (char *) ReturnDesc->Buffer.Pointer;
-
-        /* Concatenate the buffers */
-
-        memcpy (Buffer, Operand0->Buffer.Pointer,
-            Operand0->Buffer.Length);
-        memcpy (Buffer + Operand0->Buffer.Length,
-            LocalOperand1->Buffer.Pointer,
-            LocalOperand1->Buffer.Length);
-        break;
-
-    default:
-
-        /* Invalid object type, should not happen here */
-
-        ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X",
-            Operand0->Common.Type));
-        Status = AE_AML_INTERNAL;
-        goto Cleanup;
-    }
-
-    *ActualReturnDesc = ReturnDesc;
-
-Cleanup:
-    if (LocalOperand0 != Operand0)
-    {
-        AcpiUtRemoveReference (LocalOperand0);
-    }
-
-    if (LocalOperand1 != Operand1)
-    {
-        AcpiUtRemoveReference (LocalOperand1);
-    }
-
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExConvertToObjectTypeString
- *
- * PARAMETERS:  ObjDesc             - Object to be converted
- *              ReturnDesc          - Where to place the return object
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Convert an object of arbitrary type to a string object that
- *              contains the namestring for the object. Used for the
- *              concatenate operator.
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiExConvertToObjectTypeString (
-    ACPI_OPERAND_OBJECT     *ObjDesc,
-    ACPI_OPERAND_OBJECT     **ResultDesc)
-{
-    ACPI_OPERAND_OBJECT     *ReturnDesc;
-    const char              *TypeString;
-
-
-    TypeString = AcpiUtGetTypeName (ObjDesc->Common.Type);
-
-    ReturnDesc = AcpiUtCreateStringObject (
-        ((ACPI_SIZE) strlen (TypeString) + 9)); /* 9 For "[ Object]" */
-    if (!ReturnDesc)
-    {
-        return (AE_NO_MEMORY);
-    }
-
-    strcpy (ReturnDesc->String.Pointer, "[");
-    strcat (ReturnDesc->String.Pointer, TypeString);
-    strcat (ReturnDesc->String.Pointer, " Object]");
-
-    *ResultDesc = ReturnDesc;
-    return (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExConcatTemplate
- *
- * PARAMETERS:  Operand0            - First source object
- *              Operand1            - Second source object
- *              ActualReturnDesc    - Where to place the return object
- *              WalkState           - Current walk state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Concatenate two resource templates
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExConcatTemplate (
-    ACPI_OPERAND_OBJECT     *Operand0,
-    ACPI_OPERAND_OBJECT     *Operand1,
-    ACPI_OPERAND_OBJECT     **ActualReturnDesc,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     *ReturnDesc;
-    UINT8                   *NewBuf;
-    UINT8                   *EndTag;
-    ACPI_SIZE               Length0;
-    ACPI_SIZE               Length1;
-    ACPI_SIZE               NewLength;
-
-
-    ACPI_FUNCTION_TRACE (ExConcatTemplate);
-
-
-    /*
-     * Find the EndTag descriptor in each resource template.
-     * Note1: returned pointers point TO the EndTag, not past it.
-     * Note2: zero-length buffers are allowed; treated like one EndTag
-     */
-
-    /* Get the length of the first resource template */
-
-    Status = AcpiUtGetResourceEndTag (Operand0, &EndTag);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    Length0 = ACPI_PTR_DIFF (EndTag, Operand0->Buffer.Pointer);
-
-    /* Get the length of the second resource template */
-
-    Status = AcpiUtGetResourceEndTag (Operand1, &EndTag);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    Length1 = ACPI_PTR_DIFF (EndTag, Operand1->Buffer.Pointer);
-
-    /* Combine both lengths, minimum size will be 2 for EndTag */
-
-    NewLength = Length0 + Length1 + sizeof (AML_RESOURCE_END_TAG);
-
-    /* Create a new buffer object for the result (with one EndTag) */
-
-    ReturnDesc = AcpiUtCreateBufferObject (NewLength);
-    if (!ReturnDesc)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    /*
-     * Copy the templates to the new buffer, 0 first, then 1 follows. One
-     * EndTag descriptor is copied from Operand1.
-     */
-    NewBuf = ReturnDesc->Buffer.Pointer;
-    memcpy (NewBuf, Operand0->Buffer.Pointer, Length0);
-    memcpy (NewBuf + Length0, Operand1->Buffer.Pointer, Length1);
-
-    /* Insert EndTag and set the checksum to zero, means "ignore checksum" */
-
-    NewBuf[NewLength - 1] = 0;
-    NewBuf[NewLength - 2] = ACPI_RESOURCE_NAME_END_TAG | 1;
-
-    /* Return the completed resource template */
-
-    *ActualReturnDesc = ReturnDesc;
-    return_ACPI_STATUS (AE_OK);
-}

+ 0 - 621
h2o/localdep/acpica/executer/exconfig.c

@@ -1,621 +0,0 @@
-/******************************************************************************
- *
- * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acinterp.h"
-#include "acnamesp.h"
-#include "actables.h"
-#include "acdispat.h"
-#include "acevents.h"
-#include "amlcode.h"
-
-
-#define _COMPONENT          ACPI_EXECUTER
-        ACPI_MODULE_NAME    ("exconfig")
-
-/* Local prototypes */
-
-static ACPI_STATUS
-AcpiExAddTable (
-    UINT32                  TableIndex,
-    ACPI_OPERAND_OBJECT     **DdbHandle);
-
-static ACPI_STATUS
-AcpiExRegionRead (
-    ACPI_OPERAND_OBJECT     *ObjDesc,
-    UINT32                  Length,
-    UINT8                   *Buffer);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExAddTable
- *
- * PARAMETERS:  Table               - Pointer to raw table
- *              ParentNode          - Where to load the table (scope)
- *              DdbHandle           - Where to return the table handle.
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Common function to Install and Load an ACPI table with a
- *              returned table handle.
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiExAddTable (
-    UINT32                  TableIndex,
-    ACPI_OPERAND_OBJECT     **DdbHandle)
-{
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-
-
-    ACPI_FUNCTION_TRACE (ExAddTable);
-
-
-    /* Create an object to be the table handle */
-
-    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
-    if (!ObjDesc)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    /* Init the table handle */
-
-    ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
-    ObjDesc->Reference.Class = ACPI_REFCLASS_TABLE;
-    ObjDesc->Reference.Value = TableIndex;
-    *DdbHandle = ObjDesc;
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExLoadTableOp
- *
- * PARAMETERS:  WalkState           - Current state with operands
- *              ReturnDesc          - Where to store the return object
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExLoadTableOp (
-    ACPI_WALK_STATE         *WalkState,
-    ACPI_OPERAND_OBJECT     **ReturnDesc)
-{
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
-    ACPI_NAMESPACE_NODE     *ParentNode;
-    ACPI_NAMESPACE_NODE     *StartNode;
-    ACPI_NAMESPACE_NODE     *ParameterNode = NULL;
-    ACPI_OPERAND_OBJECT     *DdbHandle;
-    UINT32                  TableIndex;
-
-
-    ACPI_FUNCTION_TRACE (ExLoadTableOp);
-
-
-    /* Find the ACPI table in the RSDT/XSDT */
-
-    AcpiExExitInterpreter ();
-    Status = AcpiTbFindTable (
-        Operand[0]->String.Pointer,
-        Operand[1]->String.Pointer,
-        Operand[2]->String.Pointer, &TableIndex);
-    AcpiExEnterInterpreter ();
-    if (ACPI_FAILURE (Status))
-    {
-        if (Status != AE_NOT_FOUND)
-        {
-            return_ACPI_STATUS (Status);
-        }
-
-        /* Table not found, return an Integer=0 and AE_OK */
-
-        DdbHandle = AcpiUtCreateIntegerObject ((UINT64) 0);
-        if (!DdbHandle)
-        {
-            return_ACPI_STATUS (AE_NO_MEMORY);
-        }
-
-        *ReturnDesc = DdbHandle;
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /* Default nodes */
-
-    StartNode = WalkState->ScopeInfo->Scope.Node;
-    ParentNode = AcpiGbl_RootNode;
-
-    /* RootPath (optional parameter) */
-
-    if (Operand[3]->String.Length > 0)
-    {
-        /*
-         * Find the node referenced by the RootPathString. This is the
-         * location within the namespace where the table will be loaded.
-         */
-        Status = AcpiNsGetNodeUnlocked (StartNode,
-            Operand[3]->String.Pointer, ACPI_NS_SEARCH_PARENT,
-            &ParentNode);
-        if (ACPI_FAILURE (Status))
-        {
-            return_ACPI_STATUS (Status);
-        }
-    }
-
-    /* ParameterPath (optional parameter) */
-
-    if (Operand[4]->String.Length > 0)
-    {
-        if ((Operand[4]->String.Pointer[0] != AML_ROOT_PREFIX) &&
-            (Operand[4]->String.Pointer[0] != AML_PARENT_PREFIX))
-        {
-            /*
-             * Path is not absolute, so it will be relative to the node
-             * referenced by the RootPathString (or the NS root if omitted)
-             */
-            StartNode = ParentNode;
-        }
-
-        /* Find the node referenced by the ParameterPathString */
-
-        Status = AcpiNsGetNodeUnlocked (StartNode,
-            Operand[4]->String.Pointer, ACPI_NS_SEARCH_PARENT,
-            &ParameterNode);
-        if (ACPI_FAILURE (Status))
-        {
-            return_ACPI_STATUS (Status);
-        }
-    }
-
-    /* Load the table into the namespace */
-
-    ACPI_INFO (("Dynamic OEM Table Load:"));
-    AcpiExExitInterpreter ();
-    Status = AcpiTbLoadTable (TableIndex, ParentNode);
-    AcpiExEnterInterpreter ();
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    Status = AcpiExAddTable (TableIndex, &DdbHandle);
-    if (ACPI_FAILURE (Status))
-    {
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Complete the initialization/resolution of package objects */
-
-    Status = AcpiNsWalkNamespace (ACPI_TYPE_PACKAGE, ACPI_ROOT_OBJECT,
-        ACPI_UINT32_MAX, 0, AcpiNsInitOnePackage, NULL, NULL, NULL);
-
-    /* Parameter Data (optional) */
-
-    if (ParameterNode)
-    {
-        /* Store the parameter data into the optional parameter object */
-
-        Status = AcpiExStore (Operand[5],
-            ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode), WalkState);
-        if (ACPI_FAILURE (Status))
-        {
-            (void) AcpiExUnloadTable (DdbHandle);
-
-            AcpiUtRemoveReference (DdbHandle);
-            return_ACPI_STATUS (Status);
-        }
-    }
-
-    *ReturnDesc = DdbHandle;
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExRegionRead
- *
- * PARAMETERS:  ObjDesc         - Region descriptor
- *              Length          - Number of bytes to read
- *              Buffer          - Pointer to where to put the data
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Read data from an operation region. The read starts from the
- *              beginning of the region.
- *
- ******************************************************************************/
-
-static ACPI_STATUS
-AcpiExRegionRead (
-    ACPI_OPERAND_OBJECT     *ObjDesc,
-    UINT32                  Length,
-    UINT8                   *Buffer)
-{
-    ACPI_STATUS             Status;
-    UINT64                  Value;
-    UINT32                  RegionOffset = 0;
-    UINT32                  i;
-
-
-    /* Bytewise reads */
-
-    for (i = 0; i < Length; i++)
-    {
-        Status = AcpiEvAddressSpaceDispatch (ObjDesc, NULL, ACPI_READ,
-            RegionOffset, 8, &Value);
-        if (ACPI_FAILURE (Status))
-        {
-            return (Status);
-        }
-
-        *Buffer = (UINT8) Value;
-        Buffer++;
-        RegionOffset++;
-    }
-
-    return (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExLoadOp
- *
- * PARAMETERS:  ObjDesc         - Region or Buffer/Field where the table will be
- *                                obtained
- *              Target          - Where a handle to the table will be stored
- *              WalkState       - Current state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Load an ACPI table from a field or operation region
- *
- * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
- *       objects before this code is reached.
- *
- *       If source is an operation region, it must refer to SystemMemory, as
- *       per the ACPI specification.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExLoadOp (
-    ACPI_OPERAND_OBJECT     *ObjDesc,
-    ACPI_OPERAND_OBJECT     *Target,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_OPERAND_OBJECT     *DdbHandle;
-    ACPI_TABLE_HEADER       *TableHeader;
-    ACPI_TABLE_HEADER       *Table;
-    UINT32                  TableIndex;
-    ACPI_STATUS             Status;
-    UINT32                  Length;
-
-
-    ACPI_FUNCTION_TRACE (ExLoadOp);
-
-
-    /* Source Object can be either an OpRegion or a Buffer/Field */
-
-    switch (ObjDesc->Common.Type)
-    {
-    case ACPI_TYPE_REGION:
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-            "Load table from Region %p\n", ObjDesc));
-
-        /* Region must be SystemMemory (from ACPI spec) */
-
-        if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
-        {
-            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
-        }
-
-        /*
-         * If the Region Address and Length have not been previously
-         * evaluated, evaluate them now and save the results.
-         */
-        if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
-        {
-            Status = AcpiDsGetRegionArguments (ObjDesc);
-            if (ACPI_FAILURE (Status))
-            {
-                return_ACPI_STATUS (Status);
-            }
-        }
-
-        /* Get the table header first so we can get the table length */
-
-        TableHeader = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
-        if (!TableHeader)
-        {
-            return_ACPI_STATUS (AE_NO_MEMORY);
-        }
-
-        Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER),
-            ACPI_CAST_PTR (UINT8, TableHeader));
-        Length = TableHeader->Length;
-        ACPI_FREE (TableHeader);
-
-        if (ACPI_FAILURE (Status))
-        {
-            return_ACPI_STATUS (Status);
-        }
-
-        /* Must have at least an ACPI table header */
-
-        if (Length < sizeof (ACPI_TABLE_HEADER))
-        {
-            return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
-        }
-
-        /*
-         * The original implementation simply mapped the table, with no copy.
-         * However, the memory region is not guaranteed to remain stable and
-         * we must copy the table to a local buffer. For example, the memory
-         * region is corrupted after suspend on some machines. Dynamically
-         * loaded tables are usually small, so this overhead is minimal.
-         *
-         * The latest implementation (5/2009) does not use a mapping at all.
-         * We use the low-level operation region interface to read the table
-         * instead of the obvious optimization of using a direct mapping.
-         * This maintains a consistent use of operation regions across the
-         * entire subsystem. This is important if additional processing must
-         * be performed in the (possibly user-installed) operation region
-         * handler. For example, AcpiExec and ASLTS depend on this.
-         */
-
-        /* Allocate a buffer for the table */
-
-        Table = ACPI_ALLOCATE (Length);
-        if (!Table)
-        {
-            return_ACPI_STATUS (AE_NO_MEMORY);
-        }
-
-        /* Read the entire table */
-
-        Status = AcpiExRegionRead (ObjDesc, Length,
-            ACPI_CAST_PTR (UINT8, Table));
-        if (ACPI_FAILURE (Status))
-        {
-            ACPI_FREE (Table);
-            return_ACPI_STATUS (Status);
-        }
-        break;
-
-    case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-            "Load table from Buffer or Field %p\n", ObjDesc));
-
-        /* Must have at least an ACPI table header */
-
-        if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER))
-        {
-            return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
-        }
-
-        /* Get the actual table length from the table header */
-
-        TableHeader = ACPI_CAST_PTR (
-            ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer);
-        Length = TableHeader->Length;
-
-        /* Table cannot extend beyond the buffer */
-
-        if (Length > ObjDesc->Buffer.Length)
-        {
-            return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
-        }
-        if (Length < sizeof (ACPI_TABLE_HEADER))
-        {
-            return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
-        }
-
-        /*
-         * Copy the table from the buffer because the buffer could be
-         * modified or even deleted in the future
-         */
-        Table = ACPI_ALLOCATE (Length);
-        if (!Table)
-        {
-            return_ACPI_STATUS (AE_NO_MEMORY);
-        }
-
-        memcpy (Table, TableHeader, Length);
-        break;
-
-    default:
-
-        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
-    }
-
-    /* Install the new table into the local data structures */
-
-    ACPI_INFO (("Dynamic OEM Table Load:"));
-    AcpiExExitInterpreter ();
-    Status = AcpiTbInstallAndLoadTable (ACPI_PTR_TO_PHYSADDR (Table),
-        ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, TRUE, &TableIndex);
-    AcpiExEnterInterpreter ();
-    if (ACPI_FAILURE (Status))
-    {
-        /* Delete allocated table buffer */
-
-        ACPI_FREE (Table);
-        return_ACPI_STATUS (Status);
-    }
-
-    /*
-     * Add the table to the namespace.
-     *
-     * Note: Load the table objects relative to the root of the namespace.
-     * This appears to go against the ACPI specification, but we do it for
-     * compatibility with other ACPI implementations.
-     */
-    Status = AcpiExAddTable (TableIndex, &DdbHandle);
-    if (ACPI_FAILURE (Status))
-    {
-        /* On error, TablePtr was deallocated above */
-
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Complete the initialization/resolution of package objects */
-
-    Status = AcpiNsWalkNamespace (ACPI_TYPE_PACKAGE, ACPI_ROOT_OBJECT,
-        ACPI_UINT32_MAX, 0, AcpiNsInitOnePackage, NULL, NULL, NULL);
-
-    /* Store the DdbHandle into the Target operand */
-
-    Status = AcpiExStore (DdbHandle, Target, WalkState);
-    if (ACPI_FAILURE (Status))
-    {
-        (void) AcpiExUnloadTable (DdbHandle);
-
-        /* TablePtr was deallocated above */
-
-        AcpiUtRemoveReference (DdbHandle);
-        return_ACPI_STATUS (Status);
-    }
-
-    /* Remove the reference by added by AcpiExStore above */
-
-    AcpiUtRemoveReference (DdbHandle);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExUnloadTable
- *
- * PARAMETERS:  DdbHandle           - Handle to a previously loaded table
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Unload an ACPI table
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExUnloadTable (
-    ACPI_OPERAND_OBJECT     *DdbHandle)
-{
-    ACPI_STATUS             Status = AE_OK;
-    ACPI_OPERAND_OBJECT     *TableDesc = DdbHandle;
-    UINT32                  TableIndex;
-
-
-    ACPI_FUNCTION_TRACE (ExUnloadTable);
-
-
-    /*
-     * Temporarily emit a warning so that the ASL for the machine can be
-     * hopefully obtained. This is to say that the Unload() operator is
-     * extremely rare if not completely unused.
-     */
-    ACPI_WARNING ((AE_INFO,
-        "Received request to unload an ACPI table"));
-
-    /*
-     * May 2018: Unload is no longer supported for the following reasons:
-     * 1) A correct implementation on some hosts may not be possible.
-     * 2) Other ACPI implementations do not correctly/fully support it.
-     * 3) It requires host device driver support which does not exist.
-     *    (To properly support namespace unload out from underneath.)
-     * 4) This AML operator has never been seen in the field.
-     */
-    ACPI_EXCEPTION ((AE_INFO, AE_NOT_IMPLEMENTED,
-        "AML Unload operator is not supported"));
-
-    /*
-     * Validate the handle
-     * Although the handle is partially validated in AcpiExReconfiguration()
-     * when it calls AcpiExResolveOperands(), the handle is more completely
-     * validated here.
-     *
-     * Handle must be a valid operand object of type reference. Also, the
-     * DdbHandle must still be marked valid (table has not been previously
-     * unloaded)
-     */
-    if ((!DdbHandle) ||
-        (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
-        (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) ||
-        (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID)))
-    {
-        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
-    }
-
-    /* Get the table index from the DdbHandle */
-
-    TableIndex = TableDesc->Reference.Value;
-
-    /*
-     * Release the interpreter lock so that the table lock won't have
-     * strict order requirement against it.
-     */
-    AcpiExExitInterpreter ();
-    Status = AcpiTbUnloadTable (TableIndex);
-    AcpiExEnterInterpreter ();
-
-    /*
-     * Invalidate the handle. We do this because the handle may be stored
-     * in a named object and may not be actually deleted until much later.
-     */
-    if (ACPI_SUCCESS (Status))
-    {
-        DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID;
-    }
-    return_ACPI_STATUS (Status);
-}

+ 0 - 774
h2o/localdep/acpica/executer/exconvrt.c

@@ -1,774 +0,0 @@
-/******************************************************************************
- *
- * Module Name: exconvrt - Object conversion routines
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acinterp.h"
-#include "amlcode.h"
-
-
-#define _COMPONENT          ACPI_EXECUTER
-        ACPI_MODULE_NAME    ("exconvrt")
-
-/* Local prototypes */
-
-static UINT32
-AcpiExConvertToAscii (
-    UINT64                  Integer,
-    UINT16                  Base,
-    UINT8                   *String,
-    UINT8                   MaxLength);
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExConvertToInteger
- *
- * PARAMETERS:  ObjDesc             - Object to be converted. Must be an
- *                                    Integer, Buffer, or String
- *              ResultDesc          - Where the new Integer object is returned
- *              ImplicitConversion  - Used for string conversion
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Convert an ACPI Object to an integer.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExConvertToInteger (
-    ACPI_OPERAND_OBJECT     *ObjDesc,
-    ACPI_OPERAND_OBJECT     **ResultDesc,
-    UINT32                  ImplicitConversion)
-{
-    ACPI_OPERAND_OBJECT     *ReturnDesc;
-    UINT8                   *Pointer;
-    UINT64                  Result;
-    UINT32                  i;
-    UINT32                  Count;
-
-
-    ACPI_FUNCTION_TRACE_PTR (ExConvertToInteger, ObjDesc);
-
-
-    switch (ObjDesc->Common.Type)
-    {
-    case ACPI_TYPE_INTEGER:
-
-        /* No conversion necessary */
-
-        *ResultDesc = ObjDesc;
-        return_ACPI_STATUS (AE_OK);
-
-    case ACPI_TYPE_BUFFER:
-    case ACPI_TYPE_STRING:
-
-        /* Note: Takes advantage of common buffer/string fields */
-
-        Pointer = ObjDesc->Buffer.Pointer;
-        Count   = ObjDesc->Buffer.Length;
-        break;
-
-    default:
-
-        return_ACPI_STATUS (AE_TYPE);
-    }
-
-    /*
-     * Convert the buffer/string to an integer. Note that both buffers and
-     * strings are treated as raw data - we don't convert ascii to hex for
-     * strings.
-     *
-     * There are two terminating conditions for the loop:
-     * 1) The size of an integer has been reached, or
-     * 2) The end of the buffer or string has been reached
-     */
-    Result = 0;
-
-    /* String conversion is different than Buffer conversion */
-
-    switch (ObjDesc->Common.Type)
-    {
-    case ACPI_TYPE_STRING:
-        /*
-         * Convert string to an integer - for most cases, the string must be
-         * hexadecimal as per the ACPI specification. The only exception (as
-         * of ACPI 3.0) is that the ToInteger() operator allows both decimal
-         * and hexadecimal strings (hex prefixed with "0x").
-         *
-         * Explicit conversion is used only by ToInteger.
-         * All other string-to-integer conversions are implicit conversions.
-         */
-        if (ImplicitConversion)
-        {
-            Result = AcpiUtImplicitStrtoul64 (ACPI_CAST_PTR (char, Pointer));
-        }
-        else
-        {
-            Result = AcpiUtExplicitStrtoul64 (ACPI_CAST_PTR (char, Pointer));
-        }
-        break;
-
-    case ACPI_TYPE_BUFFER:
-
-        /* Check for zero-length buffer */
-
-        if (!Count)
-        {
-            return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
-        }
-
-        /* Transfer no more than an integer's worth of data */
-
-        if (Count > AcpiGbl_IntegerByteWidth)
-        {
-            Count = AcpiGbl_IntegerByteWidth;
-        }
-
-        /*
-         * Convert buffer to an integer - we simply grab enough raw data
-         * from the buffer to fill an integer
-         */
-        for (i = 0; i < Count; i++)
-        {
-            /*
-             * Get next byte and shift it into the Result.
-             * Little endian is used, meaning that the first byte of the buffer
-             * is the LSB of the integer
-             */
-            Result |= (((UINT64) Pointer[i]) << (i * 8));
-        }
-        break;
-
-    default:
-
-        /* No other types can get here */
-
-        break;
-    }
-
-    /* Create a new integer */
-
-    ReturnDesc = AcpiUtCreateIntegerObject (Result);
-    if (!ReturnDesc)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
-        ACPI_FORMAT_UINT64 (Result)));
-
-    /* Save the Result */
-
-    (void) AcpiExTruncateFor32bitTable (ReturnDesc);
-    *ResultDesc = ReturnDesc;
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExConvertToBuffer
- *
- * PARAMETERS:  ObjDesc         - Object to be converted. Must be an
- *                                Integer, Buffer, or String
- *              ResultDesc      - Where the new buffer object is returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Convert an ACPI Object to a Buffer
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExConvertToBuffer (
-    ACPI_OPERAND_OBJECT     *ObjDesc,
-    ACPI_OPERAND_OBJECT     **ResultDesc)
-{
-    ACPI_OPERAND_OBJECT     *ReturnDesc;
-    UINT8                   *NewBuf;
-
-
-    ACPI_FUNCTION_TRACE_PTR (ExConvertToBuffer, ObjDesc);
-
-
-    switch (ObjDesc->Common.Type)
-    {
-    case ACPI_TYPE_BUFFER:
-
-        /* No conversion necessary */
-
-        *ResultDesc = ObjDesc;
-        return_ACPI_STATUS (AE_OK);
-
-
-    case ACPI_TYPE_INTEGER:
-        /*
-         * Create a new Buffer object.
-         * Need enough space for one integer
-         */
-        ReturnDesc = AcpiUtCreateBufferObject (AcpiGbl_IntegerByteWidth);
-        if (!ReturnDesc)
-        {
-            return_ACPI_STATUS (AE_NO_MEMORY);
-        }
-
-        /* Copy the integer to the buffer, LSB first */
-
-        NewBuf = ReturnDesc->Buffer.Pointer;
-        memcpy (NewBuf, &ObjDesc->Integer.Value, AcpiGbl_IntegerByteWidth);
-        break;
-
-    case ACPI_TYPE_STRING:
-        /*
-         * Create a new Buffer object
-         * Size will be the string length
-         *
-         * NOTE: Add one to the string length to include the null terminator.
-         * The ACPI spec is unclear on this subject, but there is existing
-         * ASL/AML code that depends on the null being transferred to the new
-         * buffer.
-         */
-        ReturnDesc = AcpiUtCreateBufferObject ((ACPI_SIZE)
-            ObjDesc->String.Length + 1);
-        if (!ReturnDesc)
-        {
-            return_ACPI_STATUS (AE_NO_MEMORY);
-        }
-
-        /* Copy the string to the buffer */
-
-        NewBuf = ReturnDesc->Buffer.Pointer;
-        strncpy ((char *) NewBuf, (char *) ObjDesc->String.Pointer,
-            ObjDesc->String.Length);
-        break;
-
-    default:
-
-        return_ACPI_STATUS (AE_TYPE);
-    }
-
-    /* Mark buffer initialized */
-
-    ReturnDesc->Common.Flags |= AOPOBJ_DATA_VALID;
-    *ResultDesc = ReturnDesc;
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExConvertToAscii
- *
- * PARAMETERS:  Integer         - Value to be converted
- *              Base            - ACPI_STRING_DECIMAL or ACPI_STRING_HEX
- *              String          - Where the string is returned
- *              DataWidth       - Size of data item to be converted, in bytes
- *
- * RETURN:      Actual string length
- *
- * DESCRIPTION: Convert an ACPI Integer to a hex or decimal string
- *
- ******************************************************************************/
-
-static UINT32
-AcpiExConvertToAscii (
-    UINT64                  Integer,
-    UINT16                  Base,
-    UINT8                   *String,
-    UINT8                   DataWidth)
-{
-    UINT64                  Digit;
-    UINT32                  i;
-    UINT32                  j;
-    UINT32                  k = 0;
-    UINT32                  HexLength;
-    UINT32                  DecimalLength;
-    UINT32                  Remainder;
-    BOOLEAN                 SupressZeros;
-
-
-    ACPI_FUNCTION_ENTRY ();
-
-
-    switch (Base)
-    {
-    case 10:
-
-        /* Setup max length for the decimal number */
-
-        switch (DataWidth)
-        {
-        case 1:
-
-            DecimalLength = ACPI_MAX8_DECIMAL_DIGITS;
-            break;
-
-        case 4:
-
-            DecimalLength = ACPI_MAX32_DECIMAL_DIGITS;
-            break;
-
-        case 8:
-        default:
-
-            DecimalLength = ACPI_MAX64_DECIMAL_DIGITS;
-            break;
-        }
-
-        SupressZeros = TRUE;     /* No leading zeros */
-        Remainder = 0;
-
-        for (i = DecimalLength; i > 0; i--)
-        {
-            /* Divide by nth factor of 10 */
-
-            Digit = Integer;
-            for (j = 0; j < i; j++)
-            {
-                (void) AcpiUtShortDivide (Digit, 10, &Digit, &Remainder);
-            }
-
-            /* Handle leading zeros */
-
-            if (Remainder != 0)
-            {
-                SupressZeros = FALSE;
-            }
-
-            if (!SupressZeros)
-            {
-                String[k] = (UINT8) (ACPI_ASCII_ZERO + Remainder);
-                k++;
-            }
-        }
-        break;
-
-    case 16:
-
-        /* HexLength: 2 ascii hex chars per data byte */
-
-        HexLength = (DataWidth * 2);
-        for (i = 0, j = (HexLength-1); i < HexLength; i++, j--)
-        {
-            /* Get one hex digit, most significant digits first */
-
-            String[k] = (UINT8)
-                AcpiUtHexToAsciiChar (Integer, ACPI_MUL_4 (j));
-            k++;
-        }
-        break;
-
-    default:
-        return (0);
-    }
-
-    /*
-     * Since leading zeros are suppressed, we must check for the case where
-     * the integer equals 0
-     *
-     * Finally, null terminate the string and return the length
-     */
-    if (!k)
-    {
-        String [0] = ACPI_ASCII_ZERO;
-        k = 1;
-    }
-
-    String [k] = 0;
-    return ((UINT32) k);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExConvertToString
- *
- * PARAMETERS:  ObjDesc         - Object to be converted. Must be an
- *                                Integer, Buffer, or String
- *              ResultDesc      - Where the string object is returned
- *              Type            - String flags (base and conversion type)
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Convert an ACPI Object to a string. Supports both implicit
- *              and explicit conversions and related rules.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExConvertToString (
-    ACPI_OPERAND_OBJECT     *ObjDesc,
-    ACPI_OPERAND_OBJECT     **ResultDesc,
-    UINT32                  Type)
-{
-    ACPI_OPERAND_OBJECT     *ReturnDesc;
-    UINT8                   *NewBuf;
-    UINT32                  i;
-    UINT32                  StringLength = 0;
-    UINT16                  Base = 16;
-    UINT8                   Separator = ',';
-
-
-    ACPI_FUNCTION_TRACE_PTR (ExConvertToString, ObjDesc);
-
-
-    switch (ObjDesc->Common.Type)
-    {
-    case ACPI_TYPE_STRING:
-
-        /* No conversion necessary */
-
-        *ResultDesc = ObjDesc;
-        return_ACPI_STATUS (AE_OK);
-
-    case ACPI_TYPE_INTEGER:
-
-        switch (Type)
-        {
-        case ACPI_EXPLICIT_CONVERT_DECIMAL:
-            /*
-             * From ToDecimalString, integer source.
-             *
-             * Make room for the maximum decimal number size
-             */
-            StringLength = ACPI_MAX_DECIMAL_DIGITS;
-            Base = 10;
-            break;
-
-        default:
-
-            /* Two hex string characters for each integer byte */
-
-            StringLength = ACPI_MUL_2 (AcpiGbl_IntegerByteWidth);
-            break;
-        }
-
-        /*
-         * Create a new String
-         * Need enough space for one ASCII integer (plus null terminator)
-         */
-        ReturnDesc = AcpiUtCreateStringObject ((ACPI_SIZE) StringLength);
-        if (!ReturnDesc)
-        {
-            return_ACPI_STATUS (AE_NO_MEMORY);
-        }
-
-        NewBuf = ReturnDesc->Buffer.Pointer;
-
-        /* Convert integer to string */
-
-        StringLength = AcpiExConvertToAscii (
-            ObjDesc->Integer.Value, Base, NewBuf, AcpiGbl_IntegerByteWidth);
-
-        /* Null terminate at the correct place */
-
-        ReturnDesc->String.Length = StringLength;
-        NewBuf [StringLength] = 0;
-        break;
-
-    case ACPI_TYPE_BUFFER:
-
-        /* Setup string length, base, and separator */
-
-        switch (Type)
-        {
-        case ACPI_EXPLICIT_CONVERT_DECIMAL: /* Used by ToDecimalString */
-            /*
-             * Explicit conversion from the ToDecimalString ASL operator.
-             *
-             * From ACPI: "If the input is a buffer, it is converted to a
-             * a string of decimal values separated by commas."
-             */
-            Base = 10;
-
-            /*
-             * Calculate the final string length. Individual string values
-             * are variable length (include separator for each)
-             */
-            for (i = 0; i < ObjDesc->Buffer.Length; i++)
-            {
-                if (ObjDesc->Buffer.Pointer[i] >= 100)
-                {
-                    StringLength += 4;
-                }
-                else if (ObjDesc->Buffer.Pointer[i] >= 10)
-                {
-                    StringLength += 3;
-                }
-                else
-                {
-                    StringLength += 2;
-                }
-            }
-            break;
-
-        case ACPI_IMPLICIT_CONVERT_HEX:
-            /*
-             * Implicit buffer-to-string conversion
-             *
-             * From the ACPI spec:
-             * "The entire contents of the buffer are converted to a string of
-             * two-character hexadecimal numbers, each separated by a space."
-             *
-             * Each hex number is prefixed with 0x (11/2018)
-             */
-            Separator = ' ';
-            StringLength = (ObjDesc->Buffer.Length * 5);
-            break;
-
-        case ACPI_EXPLICIT_CONVERT_HEX:
-            /*
-             * Explicit conversion from the ToHexString ASL operator.
-             *
-             * From ACPI: "If Data is a buffer, it is converted to a string of
-             * hexadecimal values separated by commas."
-             *
-             * Each hex number is prefixed with 0x (11/2018)
-             */
-            Separator = ',';
-            StringLength = (ObjDesc->Buffer.Length * 5);
-            break;
-
-        default:
-            return_ACPI_STATUS (AE_BAD_PARAMETER);
-        }
-
-        /*
-         * Create a new string object and string buffer
-         * (-1 because of extra separator included in StringLength from above)
-         * Allow creation of zero-length strings from zero-length buffers.
-         */
-        if (StringLength)
-        {
-            StringLength--;
-        }
-
-        ReturnDesc = AcpiUtCreateStringObject ((ACPI_SIZE) StringLength);
-        if (!ReturnDesc)
-        {
-            return_ACPI_STATUS (AE_NO_MEMORY);
-        }
-
-        NewBuf = ReturnDesc->Buffer.Pointer;
-
-        /*
-         * Convert buffer bytes to hex or decimal values
-         * (separated by commas or spaces)
-         */
-        for (i = 0; i < ObjDesc->Buffer.Length; i++)
-        {
-            if (Base == 16)
-            {
-                /* Emit 0x prefix for explicit/implicit hex conversion */
-
-                *NewBuf++ = '0';
-                *NewBuf++ = 'x';
-            }
-
-            NewBuf += AcpiExConvertToAscii (
-                (UINT64) ObjDesc->Buffer.Pointer[i], Base, NewBuf, 1);
-
-            /* Each digit is separated by either a comma or space */
-
-            *NewBuf++ = Separator;
-        }
-
-        /*
-         * Null terminate the string
-         * (overwrites final comma/space from above)
-         */
-        if (ObjDesc->Buffer.Length)
-        {
-            NewBuf--;
-        }
-        *NewBuf = 0;
-        break;
-
-    default:
-
-        return_ACPI_STATUS (AE_TYPE);
-    }
-
-    *ResultDesc = ReturnDesc;
-    return_ACPI_STATUS (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExConvertToTargetType
- *
- * PARAMETERS:  DestinationType     - Current type of the destination
- *              SourceDesc          - Source object to be converted.
- *              ResultDesc          - Where the converted object is returned
- *              WalkState           - Current method state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Implements "implicit conversion" rules for storing an object.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExConvertToTargetType (
-    ACPI_OBJECT_TYPE        DestinationType,
-    ACPI_OPERAND_OBJECT     *SourceDesc,
-    ACPI_OPERAND_OBJECT     **ResultDesc,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status = AE_OK;
-
-
-    ACPI_FUNCTION_TRACE (ExConvertToTargetType);
-
-
-    /* Default behavior */
-
-    *ResultDesc = SourceDesc;
-
-    /*
-     * If required by the target,
-     * perform implicit conversion on the source before we store it.
-     */
-    switch (GET_CURRENT_ARG_TYPE (WalkState->OpInfo->RuntimeArgs))
-    {
-    case ARGI_SIMPLE_TARGET:
-    case ARGI_FIXED_TARGET:
-    case ARGI_INTEGER_REF:      /* Handles Increment, Decrement cases */
-
-        switch (DestinationType)
-        {
-        case ACPI_TYPE_LOCAL_REGION_FIELD:
-            /*
-             * Named field can always handle conversions
-             */
-            break;
-
-        default:
-
-            /* No conversion allowed for these types */
-
-            if (DestinationType != SourceDesc->Common.Type)
-            {
-                ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
-                    "Explicit operator, will store (%s) over existing type (%s)\n",
-                    AcpiUtGetObjectTypeName (SourceDesc),
-                    AcpiUtGetTypeName (DestinationType)));
-                Status = AE_TYPE;
-            }
-        }
-        break;
-
-    case ARGI_TARGETREF:
-    case ARGI_STORE_TARGET:
-
-        switch (DestinationType)
-        {
-        case ACPI_TYPE_INTEGER:
-        case ACPI_TYPE_BUFFER_FIELD:
-        case ACPI_TYPE_LOCAL_BANK_FIELD:
-        case ACPI_TYPE_LOCAL_INDEX_FIELD:
-            /*
-             * These types require an Integer operand. We can convert
-             * a Buffer or a String to an Integer if necessary.
-             */
-            Status = AcpiExConvertToInteger (SourceDesc, ResultDesc,
-                ACPI_IMPLICIT_CONVERSION);
-            break;
-
-        case ACPI_TYPE_STRING:
-            /*
-             * The operand must be a String. We can convert an
-             * Integer or Buffer if necessary
-             */
-            Status = AcpiExConvertToString (SourceDesc, ResultDesc,
-                ACPI_IMPLICIT_CONVERT_HEX);
-            break;
-
-        case ACPI_TYPE_BUFFER:
-            /*
-             * The operand must be a Buffer. We can convert an
-             * Integer or String if necessary
-             */
-            Status = AcpiExConvertToBuffer (SourceDesc, ResultDesc);
-            break;
-
-        default:
-
-            ACPI_ERROR ((AE_INFO,
-                "Bad destination type during conversion: 0x%X",
-                DestinationType));
-            Status = AE_AML_INTERNAL;
-            break;
-        }
-        break;
-
-    case ARGI_REFERENCE:
-        /*
-         * CreateXxxxField cases - we are storing the field object into the name
-         */
-        break;
-
-    default:
-
-        ACPI_ERROR ((AE_INFO,
-            "Unknown Target type ID 0x%X AmlOpcode 0x%X DestType %s",
-            GET_CURRENT_ARG_TYPE (WalkState->OpInfo->RuntimeArgs),
-            WalkState->Opcode, AcpiUtGetTypeName (DestinationType)));
-        Status = AE_AML_INTERNAL;
-    }
-
-    /*
-     * Source-to-Target conversion semantics:
-     *
-     * If conversion to the target type cannot be performed, then simply
-     * overwrite the target with the new object and type.
-     */
-    if (Status == AE_TYPE)
-    {
-        Status = AE_OK;
-    }
-
-    return_ACPI_STATUS (Status);
-}

+ 0 - 550
h2o/localdep/acpica/executer/excreate.c

@@ -1,550 +0,0 @@
-/******************************************************************************
- *
- * Module Name: excreate - Named object creation
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acinterp.h"
-#include "amlcode.h"
-#include "acnamesp.h"
-
-
-#define _COMPONENT          ACPI_EXECUTER
-        ACPI_MODULE_NAME    ("excreate")
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExCreateAlias
- *
- * PARAMETERS:  WalkState            - Current state, contains operands
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Create a new named alias
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExCreateAlias (
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_NAMESPACE_NODE     *TargetNode;
-    ACPI_NAMESPACE_NODE     *AliasNode;
-    ACPI_STATUS             Status = AE_OK;
-
-
-    ACPI_FUNCTION_TRACE (ExCreateAlias);
-
-
-    /* Get the source/alias operands (both namespace nodes) */
-
-    AliasNode =  (ACPI_NAMESPACE_NODE *) WalkState->Operands[0];
-    TargetNode = (ACPI_NAMESPACE_NODE *) WalkState->Operands[1];
-
-    if ((TargetNode->Type == ACPI_TYPE_LOCAL_ALIAS)  ||
-        (TargetNode->Type == ACPI_TYPE_LOCAL_METHOD_ALIAS))
-    {
-        /*
-         * Dereference an existing alias so that we don't create a chain
-         * of aliases. With this code, we guarantee that an alias is
-         * always exactly one level of indirection away from the
-         * actual aliased name.
-         */
-        TargetNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, TargetNode->Object);
-    }
-
-    /* Ensure that the target node is valid */
-
-    if (!TargetNode)
-    {
-        return_ACPI_STATUS (AE_NULL_OBJECT);
-    }
-
-    /* Construct the alias object (a namespace node) */
-
-    switch (TargetNode->Type)
-    {
-    case ACPI_TYPE_METHOD:
-        /*
-         * Control method aliases need to be differentiated with
-         * a special type
-         */
-        AliasNode->Type = ACPI_TYPE_LOCAL_METHOD_ALIAS;
-        break;
-
-    default:
-        /*
-         * All other object types.
-         *
-         * The new alias has the type ALIAS and points to the original
-         * NS node, not the object itself.
-         */
-        AliasNode->Type = ACPI_TYPE_LOCAL_ALIAS;
-        AliasNode->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
-        break;
-    }
-
-    /* Since both operands are Nodes, we don't need to delete them */
-
-    AliasNode->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExCreateEvent
- *
- * PARAMETERS:  WalkState           - Current state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Create a new event object
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExCreateEvent (
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-
-
-    ACPI_FUNCTION_TRACE (ExCreateEvent);
-
-
-    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_EVENT);
-    if (!ObjDesc)
-    {
-        Status = AE_NO_MEMORY;
-        goto Cleanup;
-    }
-
-    /*
-     * Create the actual OS semaphore, with zero initial units -- meaning
-     * that the event is created in an unsignalled state
-     */
-    Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0,
-        &ObjDesc->Event.OsSemaphore);
-    if (ACPI_FAILURE (Status))
-    {
-        goto Cleanup;
-    }
-
-    /* Attach object to the Node */
-
-    Status = AcpiNsAttachObject (
-        (ACPI_NAMESPACE_NODE *) WalkState->Operands[0],
-        ObjDesc, ACPI_TYPE_EVENT);
-
-Cleanup:
-    /*
-     * Remove local reference to the object (on error, will cause deletion
-     * of both object and semaphore if present.)
-     */
-    AcpiUtRemoveReference (ObjDesc);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExCreateMutex
- *
- * PARAMETERS:  WalkState           - Current state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Create a new mutex object
- *
- *              Mutex (Name[0], SyncLevel[1])
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExCreateMutex (
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status = AE_OK;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-
-
-    ACPI_FUNCTION_TRACE_PTR (ExCreateMutex, ACPI_WALK_OPERANDS);
-
-
-    /* Create the new mutex object */
-
-    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_MUTEX);
-    if (!ObjDesc)
-    {
-        Status = AE_NO_MEMORY;
-        goto Cleanup;
-    }
-
-    /* Create the actual OS Mutex */
-
-    Status = AcpiOsCreateMutex (&ObjDesc->Mutex.OsMutex);
-    if (ACPI_FAILURE (Status))
-    {
-        goto Cleanup;
-    }
-
-    /* Init object and attach to NS node */
-
-    ObjDesc->Mutex.SyncLevel = (UINT8) WalkState->Operands[1]->Integer.Value;
-    ObjDesc->Mutex.Node = (ACPI_NAMESPACE_NODE *) WalkState->Operands[0];
-
-    Status = AcpiNsAttachObject (
-        ObjDesc->Mutex.Node, ObjDesc, ACPI_TYPE_MUTEX);
-
-
-Cleanup:
-    /*
-     * Remove local reference to the object (on error, will cause deletion
-     * of both object and semaphore if present.)
-     */
-    AcpiUtRemoveReference (ObjDesc);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExCreateRegion
- *
- * PARAMETERS:  AmlStart            - Pointer to the region declaration AML
- *              AmlLength           - Max length of the declaration AML
- *              SpaceId             - Address space ID for the region
- *              WalkState           - Current state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Create a new operation region object
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExCreateRegion (
-    UINT8                   *AmlStart,
-    UINT32                  AmlLength,
-    UINT8                   SpaceId,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_NAMESPACE_NODE     *Node;
-    ACPI_OPERAND_OBJECT     *RegionObj2;
-
-
-    ACPI_FUNCTION_TRACE (ExCreateRegion);
-
-
-    /* Get the Namespace Node */
-
-    Node = WalkState->Op->Common.Node;
-
-    /*
-     * If the region object is already attached to this node,
-     * just return
-     */
-    if (AcpiNsGetAttachedObject (Node))
-    {
-        return_ACPI_STATUS (AE_OK);
-    }
-
-    /*
-     * Space ID must be one of the predefined IDs, or in the user-defined
-     * range
-     */
-    if (!AcpiIsValidSpaceId (SpaceId))
-    {
-        /*
-         * Print an error message, but continue. We don't want to abort
-         * a table load for this exception. Instead, if the region is
-         * actually used at runtime, abort the executing method.
-         */
-        ACPI_ERROR ((AE_INFO,
-            "Invalid/unknown Address Space ID: 0x%2.2X", SpaceId));
-    }
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Region Type - %s (0x%X)\n",
-        AcpiUtGetRegionName (SpaceId), SpaceId));
-
-    /* Create the region descriptor */
-
-    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
-    if (!ObjDesc)
-    {
-        Status = AE_NO_MEMORY;
-        goto Cleanup;
-    }
-
-    /*
-     * Remember location in AML stream of address & length
-     * operands since they need to be evaluated at run time.
-     */
-    RegionObj2 = AcpiNsGetSecondaryObject (ObjDesc);
-    RegionObj2->Extra.AmlStart = AmlStart;
-    RegionObj2->Extra.AmlLength = AmlLength;
-    RegionObj2->Extra.Method_REG = NULL;
-    if (WalkState->ScopeInfo)
-    {
-        RegionObj2->Extra.ScopeNode = WalkState->ScopeInfo->Scope.Node;
-    }
-    else
-    {
-        RegionObj2->Extra.ScopeNode = Node;
-    }
-
-    /* Init the region from the operands */
-
-    ObjDesc->Region.SpaceId = SpaceId;
-    ObjDesc->Region.Address = 0;
-    ObjDesc->Region.Length = 0;
-    ObjDesc->Region.Node = Node;
-    ObjDesc->Region.Handler = NULL;
-    ObjDesc->Common.Flags &=
-        ~(AOPOBJ_SETUP_COMPLETE | AOPOBJ_REG_CONNECTED |
-          AOPOBJ_OBJECT_INITIALIZED);
-
-    /* Install the new region object in the parent Node */
-
-    Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_REGION);
-
-
-Cleanup:
-
-    /* Remove local reference to the object */
-
-    AcpiUtRemoveReference (ObjDesc);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExCreateProcessor
- *
- * PARAMETERS:  WalkState           - Current state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Create a new processor object and populate the fields
- *
- *              Processor (Name[0], CpuID[1], PblockAddr[2], PblockLength[3])
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExCreateProcessor (
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_STATUS             Status;
-
-
-    ACPI_FUNCTION_TRACE_PTR (ExCreateProcessor, WalkState);
-
-
-    /* Create the processor object */
-
-    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PROCESSOR);
-    if (!ObjDesc)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    /* Initialize the processor object from the operands */
-
-    ObjDesc->Processor.ProcId = (UINT8) Operand[1]->Integer.Value;
-    ObjDesc->Processor.Length = (UINT8) Operand[3]->Integer.Value;
-    ObjDesc->Processor.Address = (ACPI_IO_ADDRESS) Operand[2]->Integer.Value;
-
-    /* Install the processor object in the parent Node */
-
-    Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],
-        ObjDesc, ACPI_TYPE_PROCESSOR);
-
-    /* Remove local reference to the object */
-
-    AcpiUtRemoveReference (ObjDesc);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExCreatePowerResource
- *
- * PARAMETERS:  WalkState           - Current state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Create a new PowerResource object and populate the fields
- *
- *              PowerResource (Name[0], SystemLevel[1], ResourceOrder[2])
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExCreatePowerResource (
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
-    ACPI_STATUS             Status;
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-
-
-    ACPI_FUNCTION_TRACE_PTR (ExCreatePowerResource, WalkState);
-
-
-    /* Create the power resource object */
-
-    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_POWER);
-    if (!ObjDesc)
-    {
-        return_ACPI_STATUS (AE_NO_MEMORY);
-    }
-
-    /* Initialize the power object from the operands */
-
-    ObjDesc->PowerResource.SystemLevel = (UINT8) Operand[1]->Integer.Value;
-    ObjDesc->PowerResource.ResourceOrder = (UINT16) Operand[2]->Integer.Value;
-
-    /* Install the  power resource object in the parent Node */
-
-    Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],
-        ObjDesc, ACPI_TYPE_POWER);
-
-    /* Remove local reference to the object */
-
-    AcpiUtRemoveReference (ObjDesc);
-    return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExCreateMethod
- *
- * PARAMETERS:  AmlStart        - First byte of the method's AML
- *              AmlLength       - AML byte count for this method
- *              WalkState       - Current state
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Create a new method object
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiExCreateMethod (
-    UINT8                   *AmlStart,
-    UINT32                  AmlLength,
-    ACPI_WALK_STATE         *WalkState)
-{
-    ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
-    ACPI_OPERAND_OBJECT     *ObjDesc;
-    ACPI_STATUS             Status;
-    UINT8                   MethodFlags;
-
-
-    ACPI_FUNCTION_TRACE_PTR (ExCreateMethod, WalkState);
-
-
-    /* Create a new method object */
-
-    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
-    if (!ObjDesc)
-    {
-       Status = AE_NO_MEMORY;
-       goto Exit;
-    }
-
-    /* Save the method's AML pointer and length  */
-
-    ObjDesc->Method.AmlStart = AmlStart;
-    ObjDesc->Method.AmlLength = AmlLength;
-    ObjDesc->Method.Node = Operand[0];
-
-    /*
-     * Disassemble the method flags. Split off the ArgCount, Serialized
-     * flag, and SyncLevel for efficiency.
-     */
-    MethodFlags = (UINT8) Operand[1]->Integer.Value;
-    ObjDesc->Method.ParamCount = (UINT8)
-        (MethodFlags & AML_METHOD_ARG_COUNT);
-
-    /*
-     * Get the SyncLevel. If method is serialized, a mutex will be
-     * created for this method when it is parsed.
-     */
-    if (MethodFlags & AML_METHOD_SERIALIZED)
-    {
-        ObjDesc->Method.InfoFlags = ACPI_METHOD_SERIALIZED;
-
-        /*
-         * ACPI 1.0: SyncLevel = 0
-         * ACPI 2.0: SyncLevel = SyncLevel in method declaration
-         */
-        ObjDesc->Method.SyncLevel = (UINT8)
-            ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
-    }
-
-    /* Attach the new object to the method Node */
-
-    Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],
-        ObjDesc, ACPI_TYPE_METHOD);
-
-    /* Remove local reference to the object */
-
-    AcpiUtRemoveReference (ObjDesc);
-
-Exit:
-    /* Remove a reference to the operand */
-
-    AcpiUtRemoveReference (Operand[1]);
-    return_ACPI_STATUS (Status);
-}

+ 0 - 353
h2o/localdep/acpica/executer/exdebug.c

@@ -1,353 +0,0 @@
-/******************************************************************************
- *
- * Module Name: exdebug - Support for stores to the AML Debug Object
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2019, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include "acpi.h"
-#include "accommon.h"
-#include "acinterp.h"
-
-
-#define _COMPONENT          ACPI_EXECUTER
-        ACPI_MODULE_NAME    ("exdebug")
-
-
-#ifndef ACPI_NO_ERROR_MESSAGES
-/*******************************************************************************
- *
- * FUNCTION:    AcpiExDoDebugObject
- *
- * PARAMETERS:  SourceDesc          - Object to be output to "Debug Object"
- *              Level               - Indentation level (used for packages)
- *              Index               - Current package element, zero if not pkg
- *
- * RETURN:      None
- *
- * DESCRIPTION: Handles stores to the AML Debug Object. For example:
- *              Store(INT1, Debug)
- *
- * This function is not compiled if ACPI_NO_ERROR_MESSAGES is set.
- *
- * This function is only enabled if AcpiGbl_EnableAmlDebugObject is set, or
- * if ACPI_LV_DEBUG_OBJECT is set in the AcpiDbgLevel. Thus, in the normal
- * operational case, stores to the debug object are ignored but can be easily
- * enabled if necessary.
- *
- ******************************************************************************/
-
-void
-AcpiExDoDebugObject (
-    ACPI_OPERAND_OBJECT     *SourceDesc,
-    UINT32                  Level,
-    UINT32                  Index)
-{
-    UINT32                  i;
-    UINT32                  Timer;
-    ACPI_OPERAND_OBJECT     *ObjectDesc;
-    UINT32                  Value;
-
-
-    ACPI_FUNCTION_TRACE_PTR (ExDoDebugObject, SourceDesc);
-
-
-    /* Output must be enabled via the DebugObject global or the DbgLevel */
-
-    if (!AcpiGbl_EnableAmlDebugObject &&
-        !(AcpiDbgLevel & ACPI_LV_DEBUG_OBJECT))
-    {
-        return_VOID;
-    }
-
-    /* Newline -- don't emit the line header */
-
-    if (SourceDesc &&
-        (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_OPERAND) &&
-        (SourceDesc->Common.Type == ACPI_TYPE_STRING))
-    {
-        if ((SourceDesc->String.Length == 1) &&
-            (*SourceDesc->String.Pointer == '\n'))
-        {
-            AcpiOsPrintf ("\n");
-            return_VOID;
-        }
-    }
-
-    /*
-     * Print line header as long as we are not in the middle of an
-     * object display
-     */
-    if (!((Level > 0) && Index == 0))
-    {
-        if (AcpiGbl_DisplayDebugTimer)
-        {
-            /*
-             * We will emit the current timer value (in microseconds) with each
-             * debug output. Only need the lower 26 bits. This allows for 67
-             * million microseconds or 67 seconds before rollover.
-             *
-             * Convert 100 nanosecond units to microseconds
-             */
-            Timer = ((UINT32) AcpiOsGetTimer () / 10);
-            Timer &= 0x03FFFFFF;
-
-            AcpiOsPrintf ("ACPI Debug: T=0x%8.8X %*s", Timer, Level, " ");
-        }
-        else
-        {
-            AcpiOsPrintf ("ACPI Debug: %*s", Level, " ");
-        }
-    }
-
-    /* Display the index for package output only */
-
-    if (Index > 0)
-    {
-       AcpiOsPrintf ("(%.2u) ", Index - 1);
-    }
-
-    if (!SourceDesc)
-    {
-        AcpiOsPrintf ("[Null Object]\n");
-        return_VOID;
-    }
-
-    if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_OPERAND)
-    {
-        /* No object type prefix needed for integers and strings */
-
-        if ((SourceDesc->Common.Type != ACPI_TYPE_INTEGER) &&
-            (SourceDesc->Common.Type != ACPI_TYPE_STRING))
-        {
-            AcpiOsPrintf ("%s  ", AcpiUtGetObjectTypeName (SourceDesc));
-        }
-
-        if (!AcpiUtValidInternalObject (SourceDesc))
-        {
-           AcpiOsPrintf ("%p, Invalid Internal Object!\n", SourceDesc);
-           return_VOID;
-        }
-    }
-    else if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED)
-    {
-        AcpiOsPrintf ("%s  (Node %p)\n",
-            AcpiUtGetTypeName (((ACPI_NAMESPACE_NODE *) SourceDesc)->Type),
-                SourceDesc);
-        return_VOID;
-    }
-    else
-    {
-        return_VOID;
-    }
-
-    /* SourceDesc is of type ACPI_DESC_TYPE_OPERAND */
-
-    switch (SourceDesc->Common.Type)
-    {
-    case ACPI_TYPE_INTEGER:
-
-        /* Output correct integer width */
-
-        if (AcpiGbl_IntegerByteWidth == 4)
-        {
-            AcpiOsPrintf ("0x%8.8X\n",
-                (UINT32) SourceDesc->Integer.Value);
-        }
-        else
-        {
-            AcpiOsPrintf ("0x%8.8X%8.8X\n",
-                ACPI_FORMAT_UINT64 (SourceDesc->Integer.Value));
-        }
-        break;
-
-    case ACPI_TYPE_BUFFER:
-
-        AcpiOsPrintf ("[0x%.2X]\n", (UINT32) SourceDesc->Buffer.Length);
-        AcpiUtDumpBuffer (SourceDesc->Buffer.Pointer,
-            (SourceDesc->Buffer.Length < 256) ?
-                SourceDesc->Buffer.Length : 256, DB_BYTE_DISPLAY, 0);
-        break;
-
-    case ACPI_TYPE_STRING:
-
-        AcpiOsPrintf ("\"%s\"\n", SourceDesc->String.Pointer);
-        break;
-
-    case ACPI_TYPE_PACKAGE:
-
-        AcpiOsPrintf ("(Contains 0x%.2X Elements):\n",
-            SourceDesc->Package.Count);
-
-        /* Output the entire contents of the package */
-
-        for (i = 0; i < SourceDesc->Package.Count; i++)
-        {
-            AcpiExDoDebugObject (SourceDesc->Package.Elements[i],
-                Level + 4, i + 1);
-        }
-        break;
-
-    case ACPI_TYPE_LOCAL_REFERENCE:
-
-        AcpiOsPrintf ("[%s] ", AcpiUtGetReferenceName (SourceDesc));
-
-        /* Decode the reference */
-
-        switch (SourceDesc->Reference.Class)
-        {
-        case ACPI_REFCLASS_INDEX:
-
-            AcpiOsPrintf ("0x%X\n", SourceDesc->Reference.Value);
-            break;
-
-        case ACPI_REFCLASS_TABLE:
-
-            /* Case for DdbHandle */
-
-            AcpiOsPrintf ("Table Index 0x%X\n", SourceDesc->Reference.Value);
-            return_VOID;
-
-        default:
-
-            break;
-        }
-
-        AcpiOsPrintf ("  ");
-
-        /* Check for valid node first, then valid object */
-
-        if (SourceDesc->Reference.Node)
-        {
-            if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Node) !=
-                ACPI_DESC_TYPE_NAMED)
-            {
-                AcpiOsPrintf (" %p - Not a valid namespace node\n",
-                    SourceDesc->Reference.Node);
-            }
-            else
-            {
-                AcpiOsPrintf ("Node %p [%4.4s] ", SourceDesc->Reference.Node,
-                    (SourceDesc->Reference.Node)->Name.Ascii);
-
-                switch ((SourceDesc->Reference.Node)->Type)
-                {
-                /* These types have no attached object */
-
-                case ACPI_TYPE_DEVICE:
-                    AcpiOsPrintf ("Device\n");
-                    break;
-
-                case ACPI_TYPE_THERMAL:
-                    AcpiOsPrintf ("Thermal Zone\n");
-                    break;
-
-                default:
-
-                    AcpiExDoDebugObject ((SourceDesc->Reference.Node)->Object,
-                        Level + 4, 0);
-                    break;
-                }
-            }
-        }
-        else if (SourceDesc->Reference.Object)
-        {
-            if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Object) ==
-                ACPI_DESC_TYPE_NAMED)
-            {
-                /* Reference object is a namespace node */
-
-                AcpiExDoDebugObject (ACPI_CAST_PTR (ACPI_OPERAND_OBJECT,
-                    SourceDesc->Reference.Object),
-                    Level + 4, 0);
-            }
-            else
-            {
-                ObjectDesc = SourceDesc->Reference.Object;
-                Value = SourceDesc->Reference.Value;
-
-                switch (ObjectDesc->Common.Type)
-                {
-                case ACPI_TYPE_BUFFER:
-
-                    AcpiOsPrintf ("Buffer[%u] = 0x%2.2X\n",
-                        Value, *SourceDesc->Reference.IndexPointer);
-                    break;
-
-                case ACPI_TYPE_STRING:
-
-                    AcpiOsPrintf ("String[%u] = \"%c\" (0x%2.2X)\n",
-                        Value, *SourceDesc->Reference.IndexPointer,
-                        *SourceDesc->Reference.IndexPointer);
-                    break;
-
-                case ACPI_TYPE_PACKAGE:
-
-                    AcpiOsPrintf ("Package[%u] = ", Value);
-                    if (!(*SourceDesc->Reference.Where))
-                    {
-                        AcpiOsPrintf ("[Uninitialized Package Element]\n");
-                    }
-                    else
-                    {
-                        AcpiExDoDebugObject (*SourceDesc->Reference.Where,
-                            Level+4, 0);
-                    }
-                    break;
-
-                default:
-
-                    AcpiOsPrintf ("Unknown Reference object type %X\n",
-                        ObjectDesc->Common.Type);
-                    break;
-                }
-            }
-        }
-        break;
-
-    default:
-
-        AcpiOsPrintf ("(Descriptor %p)\n", SourceDesc);
-        break;
-    }
-
-    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
-    return_VOID;
-}
-#endif

Some files were not shown because too many files changed in this diff