Home | History | Annotate | Download | only in acpi
      1 /* ----------------------------------------------------------------------- *
      2  *
      3  *   Copyright 2009-2011 Erwan Velu - All Rights Reserved
      4  *
      5  *   This program is free software; you can redistribute it and/or modify
      6  *   it under the terms of the GNU General Public License as published by
      7  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
      8  *   Boston MA 02111-1307, USA; either version 2 of the License, or
      9  *   (at your option) any later version; incorporated herein by reference.
     10  *
     11  * ----------------------------------------------------------------------- */
     12 
     13 #ifndef MADT_H
     14 #define MADT_H
     15 #include <inttypes.h>
     16 #include <stdbool.h>
     17 
     18 #define MADT "MADT"
     19 #define APIC "APIC"
     20 
     21 enum {
     22     PROCESSOR_LOCAL_APIC = 0,
     23     IO_APIC = 1,
     24     INTERRUPT_SOURCE_OVERRIDE = 2,
     25     NMI = 3,
     26     LOCAL_APIC_NMI_STRUCTURE = 4,
     27     LOCAL_APIC_ADDRESS_OVERRIDE_STRUCTURE = 5,
     28     IO_SAPIC = 6,
     29     LOCAL_SAPIC = 7,
     30     PLATEFORM_INTERRUPT_SOURCES = 8
     31 };
     32 
     33 /* Features flags for
     34  * - processor_local_apic flags
     35  * - local sapic flags
     36  */
     37 #define PROCESSOR_LOCAL_APIC_ENABLE 1
     38 
     39 #define MAX_S_L_P 255
     40 typedef struct {
     41     uint8_t type;
     42     uint8_t length;
     43     uint8_t acpi_id;
     44     uint8_t apic_id;
     45     uint32_t flags;
     46 } __attribute__ ((packed)) s_processor_local_apic;
     47 
     48 #define MAX_IO_APIC 255
     49 typedef struct {
     50     uint8_t type;
     51     uint8_t length;
     52     uint8_t io_apic_id;
     53     uint8_t reserved;
     54     uint32_t io_apic_address;
     55     uint32_t global_system_interrupt_base;
     56 } __attribute__ ((packed)) s_io_apic;
     57 
     58 /* Features flags for
     59  * - interrupt_source_override
     60  * - nmi
     61  */
     62 /* Bits 1&2 must be set to 0 */
     63 #define POLARITY_CONFORM_MASK 0x0
     64 #define POLARITY_ACTIVE_HIGH 0x1
     65 #define POLARITY_RESERVED 0x2
     66 #define POLARITY_ACTIVE_LOW 0x3
     67 /* Bits 3&4 must be set to 0 */
     68 #define TRIGGER_CONFORM_MASK 0x3
     69 #define TRIGGER_EDGE 0x4
     70 #define TRIGGER_RESERVED 0x8
     71 #define TRIGGER_LEVEL 0xA
     72 
     73 #define MAX_I_S_O 255
     74 typedef struct {
     75     uint8_t type;
     76     uint8_t length;
     77     uint8_t bus;
     78     uint8_t source;
     79     uint32_t global_system_interrupt;
     80     uint16_t flags;
     81 } __attribute__ ((packed)) s_interrupt_source_override;
     82 
     83 typedef struct {
     84     uint8_t type;
     85     uint8_t length;
     86     uint8_t flags;
     87     uint32_t global_system_interrupt;
     88 } __attribute__ ((packed)) s_nmi;
     89 
     90 #define MAX_LOCAL_APIC_NMI 255
     91 typedef struct {
     92     uint8_t type;
     93     uint8_t length;
     94     uint8_t acpi_processor_id;
     95     uint16_t flags;
     96     uint8_t local_apic_lint;
     97 } __attribute__ ((packed)) s_local_apic_nmi;
     98 
     99 #define MAX_L_A_A_O 255
    100 typedef struct {
    101     uint8_t type;
    102     uint8_t length;
    103     uint16_t reserved;
    104     uint64_t local_apic_address;
    105 } __attribute__ ((packed)) s_local_apic_address_override;
    106 
    107 #define MAX_IO_SAPIC 255
    108 typedef struct {
    109     uint8_t type;
    110     uint8_t length;
    111     uint8_t io_apic_id;
    112     uint8_t reserved;
    113     uint32_t global_system_interrupt_base;
    114     uint64_t io_sapic_address;
    115 } __attribute__ ((packed)) s_io_sapic;
    116 
    117 #define ACPI_PROCESSOR_UID_STRING_OFFSET 16
    118 #define MAX_LOCAL_SAPIC 255
    119 typedef struct {
    120     uint8_t type;
    121     uint8_t length;
    122     uint8_t acpi_processor_id;
    123     uint8_t local_sapic_id;
    124     uint8_t local_sapic_eid;
    125     uint8_t reserved[3];
    126     uint32_t flags;
    127     uint32_t acpi_processor_uid_value;
    128     char *acpi_processor_uid_string;
    129 } __attribute__ ((packed)) s_local_sapic;
    130 
    131 typedef struct {
    132     uint64_t *address;
    133     s_acpi_description_header header;
    134     uint32_t local_apic_address;
    135     uint32_t flags;
    136     s_processor_local_apic processor_local_apic[MAX_S_L_P];
    137     uint8_t processor_local_apic_count;
    138     s_io_apic io_apic[MAX_IO_APIC];
    139     uint8_t io_apic_count;
    140     s_interrupt_source_override interrupt_source_override[MAX_I_S_O];
    141     uint8_t interrupt_source_override_count;
    142     s_nmi nmi[MAX_I_S_O];
    143     uint8_t nmi_count;
    144     s_local_apic_nmi local_apic_nmi[MAX_LOCAL_APIC_NMI];
    145     uint8_t local_apic_nmi_count;
    146     s_local_apic_address_override local_apic_address_override[MAX_L_A_A_O];
    147     uint8_t local_apic_address_override_count;
    148     s_io_sapic io_sapic[MAX_IO_SAPIC];
    149     uint8_t io_sapic_count;
    150     s_local_sapic local_sapic[MAX_LOCAL_SAPIC];
    151     uint8_t local_sapic_count;
    152     bool valid;
    153 } s_madt;
    154 
    155 void print_madt(s_madt * madt);
    156 #endif
    157