1 /////////////////////////////////////////////////////////////////////////
2 // $Id: acpi.h 14112 2021-01-31 10:50:53Z vruppert $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 //  Copyright (C) 2006-2021  The Bochs Project
6 //
7 //  This library is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU Lesser General Public
9 //  License as published by the Free Software Foundation; either
10 //  version 2 of the License, or (at your option) any later version.
11 //
12 //  This library is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 //  Lesser General Public License for more details.
16 //
17 //  You should have received a copy of the GNU Lesser General Public
18 //  License along with this library; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20 //
21 
22 #ifndef BX_IODEV_ACPI_H
23 #define BX_IODEV_ACPI_H
24 
25 #if BX_USE_ACPI_SMF
26 #  define BX_ACPI_SMF static
27 #  define BX_ACPI_THIS theACPIController->
28 #  define BX_ACPI_THIS_PTR theACPIController
29 #else
30 #  define BX_ACPI_SMF
31 #  define BX_ACPI_THIS this->
32 #  define BX_ACPI_THIS_PTR this
33 #endif
34 
35 class bx_acpi_ctrl_c : public bx_acpi_ctrl_stub_c {
36 public:
37   bx_acpi_ctrl_c();
38   virtual ~bx_acpi_ctrl_c();
39   virtual void init(void);
40   virtual void reset(unsigned type);
41   virtual void generate_smi(Bit8u value);
42   virtual void register_state(void);
43   virtual void after_restore_state(void);
44 
45   virtual void pci_write_handler(Bit8u address, Bit32u value, unsigned io_len);
46 
47   static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len);
48   static void   write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len);
49 #if !BX_USE_ACPI_SMF
50   Bit32u read(Bit32u address, unsigned io_len);
51   void   write(Bit32u address, Bit32u value, unsigned io_len);
52 #endif
53   BX_ACPI_SMF void timer(void);
54 
55 private:
56   BX_ACPI_SMF void set_irq_level(bool level);
57   BX_ACPI_SMF Bit32u get_pmtmr(void);
58   BX_ACPI_SMF Bit16u get_pmsts(void);
59   BX_ACPI_SMF void pm_update_sci(void);
60   static void timer_handler(void *);
61 
62   struct {
63     Bit8u devfunc;
64     Bit32u pm_base;
65     Bit32u sm_base;
66     Bit16u pmsts;
67     Bit16u pmen;
68     Bit16u pmcntrl;
69     Bit64u tmr_overflow_time;
70     Bit8u pmreg[0x38];
71     int timer_index;
72     struct {
73       Bit8u stat;
74       Bit8u ctl;
75       Bit8u cmd;
76       Bit8u addr;
77       Bit8u data0;
78       Bit8u data1;
79       Bit8u index;
80       Bit8u data[32];
81     } smbus;
82   } s;
83 };
84 
85 #endif
86