git: track the specific branch only
[akaros.git] / kern / include / acpi.h
index c9a340c..12fbfc7 100644 (file)
@@ -57,7 +57,7 @@
 
 enum {
 
-       Sdthdrsz = 36,                  /* size of SDT header */
+       Sdthdrsz = 36,          /* size of SDT header */
 
        /* ACPI regions. Gas ids */
        Rsysmem = 0,
@@ -71,7 +71,7 @@ enum {
        Rfixedhw = 0x7f,
 
        /* ACPI PM1 control */
-       Pm1SciEn = 0x1,                 /* Generate SCI and not SMI */
+       Pm1SciEn = 0x1,         /* Generate SCI and not SMI */
 
        /* ACPI tbdf as encoded in acpi region base addresses */
        Rpciregshift = 0,
@@ -85,21 +85,21 @@ enum {
 
        /* Apic structure types */
        ASlapic = 0,            /* processor local apic */
-       ASioapic,                       /* I/O apic */
-       ASintovr,                       /* Interrupt source override */
-       ASnmi,                          /* NMI source */
-       ASlnmi,                         /* local apic nmi */
-       ASladdr,                        /* local apic address override */
-       ASiosapic,                      /* I/O sapic */
-       ASlsapic,                       /* local sapic */
-       ASintsrc,                       /* platform interrupt sources */
-       ASlx2apic,                      /* local x2 apic */
-       ASlx2nmi,                       /* local x2 apic NMI */
+       ASioapic,               /* I/O apic */
+       ASintovr,               /* Interrupt source override */
+       ASnmi,                  /* NMI source */
+       ASlnmi,                 /* local apic nmi */
+       ASladdr,                /* local apic address override */
+       ASiosapic,              /* I/O sapic */
+       ASlsapic,               /* local sapic */
+       ASintsrc,               /* platform interrupt sources */
+       ASlx2apic,              /* local x2 apic */
+       ASlx2nmi,               /* local x2 apic NMI */
 
        /* Apic flags */
-       AFbus = 0,                      /* polarity/trigger like in ISA */
-       AFhigh = 1,                     /* active high */
-       AFlow = 3,                      /* active low */
+       AFbus = 0,              /* polarity/trigger like in ISA */
+       AFhigh = 1,             /* active high */
+       AFlow = 3,              /* active low */
        AFpmask = 3,            /* polarity bits */
        AFedge = 1 << 2,        /* edge triggered */
        AFlevel = 3 << 2,       /* level triggered */
@@ -130,18 +130,19 @@ enum {
        HPET,
        APIC,
        DMAR,
+       MCFG,
        /* DMAR types */
        DRHD,
        RMRR,
        ATSR,
        RHSA,
        ANDD,
-       NACPITBLS,                      /* Number of ACPI tables */
+       NACPITBLS,              /* Number of ACPI tables */
 
        /* SRAT types */
        SRlapic = 0,            /* Local apic/sapic affinity */
-       SRmem,                          /* Memory affinity */
-       SRlx2apic,                      /* x2 apic affinity */
+       SRmem,                  /* Memory affinity */
+       SRlx2apic,              /* x2 apic affinity */
 
        /* Atable constants */
        SIGSZ           = 4+1,  /* Size of the signature (including NUL) */
@@ -149,12 +150,12 @@ enum {
        OEMTBLIDSZ      = 8+1,  /* Size of the OEM Table ID (including NUL) */
 
        /* Arg for _PIC */
-       Ppic = 0,                       /* PIC interrupt model */
-       Papic,                          /* APIC interrupt model */
-       Psapic,                         /* SAPIC interrupt model */
+       Ppic = 0,               /* PIC interrupt model */
+       Papic,                  /* APIC interrupt model */
+       Psapic,                 /* SAPIC interrupt model */
 
        CMregion = 0,           /* regio name spc base len accsz */
-       CMgpe,                          /* gpe name id */
+       CMgpe,                  /* gpe name id */
 };
 
 /*
@@ -172,32 +173,32 @@ enum {
  * same array.
  */
 struct Atable {
-       struct qid qid;             /* QID corresponding to this table. */
-       struct qid rqid;                        /* This table's 'raw' QID. */
-       struct qid pqid;                        /* This table's 'pretty' QID. */
-       struct qid tqid;                        /* This table's 'table' QID. */
-       int type;                                       /* This table's type */
-       void *tbl;                                      /* pointer to the converted table, e.g. madt. */
-       char name[16];                          /* name of this table */
-
-       struct Atable *parent;          /* Parent pointer */
-       struct Atable **children;       /* children of this node (an array). */
-       struct dirtab *cdirs;           /* child directory entries of this node. */
-       size_t nchildren;                       /* count of this node's children */
-       struct Atable *next;            /* Pointer to the next sibling. */
-
-       size_t rawsize;                         /* Total size of raw table */
-       uint8_t *raw;                           /* Raw data. */
+       struct qid qid;         /* QID corresponding to this table. */
+       struct qid rqid;        /* This table's 'raw' QID. */
+       struct qid pqid;        /* This table's 'pretty' QID. */
+       struct qid tqid;        /* This table's 'table' QID. */
+       int type;               /* This table's type */
+       void *tbl;              /* pointer to the converted table, e.g. madt. */
+       char name[16];          /* name of this table */
+
+       struct Atable *parent;  /* Parent pointer */
+       struct Atable **children; /* children of this node (an array). */
+       struct dirtab *cdirs;   /* child directory entries of this node. */
+       size_t nchildren;       /* count of this node's children */
+       struct Atable *next;    /* Pointer to the next sibling. */
+
+       size_t rawsize;         /* Total size of raw table */
+       uint8_t *raw;           /* Raw data. */
 };
 
 struct Gpe {
-       uintptr_t stsio;                        /* port used for status */
-       int stsbit;                                     /* bit number */
-       uintptr_t enio;                         /* port used for enable */
-       int enbit;                                      /* bit number */
-       int nb;                                         /* event number */
-       char *obj;                                      /* handler object  */
-       int id;                                         /* id as supplied by user */
+       uintptr_t stsio;        /* port used for status */
+       int stsbit;             /* bit number */
+       uintptr_t enio;         /* port used for enable */
+       int enbit;              /* bit number */
+       int nb;                 /* event number */
+       char *obj;              /* handler object  */
+       int id;                 /* id as supplied by user */
 };
 
 struct Regio {
@@ -214,22 +215,22 @@ struct Regio {
 
 struct Reg {
        char *name;
-       int spc;                                        /* io space */
-       uint64_t base;                          /* address, physical */
-       uint8_t *p;                                     /* address, kmapped */
+       int spc;                /* io space */
+       uint64_t base;          /* address, physical */
+       uint8_t *p;             /* address, kmapped */
        uint64_t len;
        int tbdf;
-       int accsz;                                      /* access size */
+       int accsz;              /* access size */
 };
 
 /* Generic address structure.
  */
 struct Gas {
-       uint8_t spc;                            /* address space id */
-       uint8_t len;                            /* register size in bits */
-       uint8_t off;                            /* bit offset */
-       uint8_t accsz;                          /* 1: byte; 2: word; 3: dword; 4: qword */
-       uint64_t addr;                          /* address (or acpi encoded tbdf + reg) */
+       uint8_t spc;            /* address space id */
+       uint8_t len;            /* register size in bits */
+       uint8_t off;            /* bit offset */
+       uint8_t accsz;          /* 1: byte; 2: word; 3: dword; 4: qword */
+       uint64_t addr;          /* address (or acpi encoded tbdf + reg) */
 };
 
 /* Root system description table pointer.
@@ -242,21 +243,21 @@ struct Gas {
  *     - pointers to other tables for apics, etc.
  */
 struct Rsdp {
-       uint8_t signature[8];           /* "RSD PTR " */
+       uint8_t signature[8];   /* "RSD PTR " */
        uint8_t rchecksum;
        uint8_t oemid[6];
        uint8_t revision;
-       uint8_t raddr[4];                       /* RSDT */
+       uint8_t raddr[4];       /* RSDT */
        uint8_t length[4];
-       uint8_t xaddr[8];                       /* XSDT */
-       uint8_t xchecksum;                      /* XSDT */
-       uint8_t _reserved[3];                   /* reserved */
+       uint8_t xaddr[8];       /* XSDT */
+       uint8_t xchecksum;      /* XSDT */
+       uint8_t _reserved[3];   /* reserved */
 };
 
 /* Header for ACPI description tables
  */
 struct Sdthdr {
-       uint8_t sig[4];                         /* "FACP" or whatever */
+       uint8_t sig[4];         /* "FACP" or whatever */
        uint8_t length[4];
        uint8_t rev;
        uint8_t csum;
@@ -284,18 +285,18 @@ struct Facs {
 /* Maximum System Characteristics table
  */
 struct Msct {
-       int ndoms;                                      /* number of domains */
-       int nclkdoms;                           /* number of clock domains */
-       uint64_t maxpa;                         /* max physical address */
-       size_t nmdom;                           /* number of discovered domains */
-       struct Mdom *dom;                       /* array of domains */
+       int ndoms;              /* number of domains */
+       int nclkdoms;           /* number of clock domains */
+       uint64_t maxpa;         /* max physical address */
+       size_t nmdom;           /* number of discovered domains */
+       struct Mdom *dom;       /* array of domains */
 };
 
 struct Mdom {
-       int start;                                      /* start dom id */
-       int end;                                        /* end dom id */
-       int maxproc;                            /* max processor capacity */
-       uint64_t maxmem;                        /* max memory capacity */
+       int start;              /* start dom id */
+       int end;                /* end dom id */
+       int maxproc;            /* max processor capacity */
+       uint64_t maxmem;        /* max memory capacity */
 };
 
 /* Multiple APIC description table
@@ -305,55 +306,55 @@ struct Mdom {
  * Only enabled devices are linked, others are filtered out.
  */
 struct Madt {
-       uint64_t lapicpa;                       /* local APIC addr */
-       int pcat;                                       /* the machine has PC/AT 8259s */
+       uint64_t lapicpa;       /* local APIC addr */
+       int pcat;               /* the machine has PC/AT 8259s */
 };
 
 struct Apicst {
        int type;
        union {
                struct {
-                       int pid;                        /* processor id */
-                       int id;                         /* apic no */
+                       int pid;                /* processor id */
+                       int id;                 /* apic no */
                } lapic;
                struct {
-                       int id;                         /* io apic id */
+                       int id;                 /* io apic id */
                        uint32_t ibase;         /* interrupt base addr. */
                        uint64_t addr;          /* base address */
                } ioapic, iosapic;
                struct {
-                       int irq;                        /* bus intr. source (ISA only) */
-                       int intr;                       /* system interrupt */
-                       int flags;                      /* apic flags */
+                       int irq;                /* bus intr. source (ISA only) */
+                       int intr;               /* system interrupt */
+                       int flags;              /* apic flags */
                } intovr;
                struct {
-                       int intr;                       /* system interrupt */
-                       int flags;                      /* apic flags */
+                       int intr;               /* system interrupt */
+                       int flags;              /* apic flags */
                } nmi;
                struct {
-                       int pid;                        /* processor id */
-                       int flags;                      /* lapic flags */
-                       int lint;                       /* lapic LINTn for nmi */
+                       int pid;                /* processor id */
+                       int flags;              /* lapic flags */
+                       int lint;               /* lapic LINTn for nmi */
                } lnmi;
                struct {
-                       int pid;                        /* processor id */
-                       int id;                         /* apic id */
-                       int eid;                        /* apic eid */
-                       int puid;                       /* processor uid */
+                       int pid;                /* processor id */
+                       int id;                 /* apic id */
+                       int eid;                /* apic eid */
+                       int puid;               /* processor uid */
                        char *puids;            /* same thing */
                } lsapic;
                struct {
-                       int pid;                        /* processor id */
-                       int peid;                       /* processor eid */
-                       int iosv;                       /* io sapic vector */
-                       int intr;                       /* global sys intr. */
-                       int type;                       /* intr type */
-                       int flags;                      /* apic flags */
-                       int any;                        /* err sts at any proc */
+                       int pid;                /* processor id */
+                       int peid;               /* processor eid */
+                       int iosv;               /* io sapic vector */
+                       int intr;               /* global sys intr. */
+                       int type;               /* intr type */
+                       int flags;              /* apic flags */
+                       int any;                /* err sts at any proc */
                } intsrc;
                struct {
-                       int id;                         /* x2 apic id */
-                       int puid;                       /* processor uid */
+                       int id;                 /* x2 apic id */
+                       int puid;               /* processor uid */
                } lx2apic;
                struct {
                        int puid;
@@ -369,22 +370,22 @@ struct Srat {
        int type;
        union {
                struct {
-                       int dom;                        /* proximity domain */
-                       int apic;                       /* apic id */
-                       int sapic;                      /* sapic id */
-                       int clkdom;                     /* clock domain */
+                       int dom;                /* proximity domain */
+                       int apic;               /* apic id */
+                       int sapic;              /* sapic id */
+                       int clkdom;             /* clock domain */
                } lapic;
                struct {
-                       int dom;                        /* proximity domain */
+                       int dom;                /* proximity domain */
                        uint64_t addr;          /* base address */
                        uint64_t len;
-                       int hplug;                      /* hot pluggable */
-                       int nvram;                      /* non volatile */
+                       int hplug;              /* hot pluggable */
+                       int nvram;              /* non volatile */
                } mem;
                struct {
-                       int dom;                        /* proximity domain */
-                       int apic;                       /* x2 apic id */
-                       int clkdom;                     /* clock domain */
+                       int dom;                /* proximity domain */
+                       int apic;               /* x2 apic id */
+                       int clkdom;             /* clock domain */
                } lx2apic;
        };
 };
@@ -397,8 +398,8 @@ struct Slit {
 };
 
 struct SlEntry {
-       int dom;                                        /* proximity domain */
-       unsigned int dist;                      /* distance to proximity domain */
+       int dom;                        /* proximity domain */
+       unsigned int dist;              /* distance to proximity domain */
 };
 
 /* Fixed ACPI description table.
@@ -503,6 +504,32 @@ struct Dmar {
        int intr_remap;
 };
 
+struct acpi_mcfg {
+       uint8_t sig[4];
+       uint8_t length[4];
+       uint8_t rev;
+       uint8_t csum;
+       uint8_t oemid[6];
+       uint8_t oemtblid[8];
+       uint8_t oemrev[4];
+       uint8_t creatorid[4];
+       uint8_t creatorrev[4];
+       uint8_t _pad[8];
+       uint8_t entries[0];
+};
+
+struct acpi_mcfg_entry {
+       physaddr_t addr;
+       uint16_t segment;
+       uint8_t start_bus;
+       uint8_t end_bus;
+};
+
+struct acpi_mcfg_data {
+       size_t nr_entries;
+       struct acpi_mcfg_entry entries[];
+};
+
 int acpiinit(void);
 struct Atable *mkatable(struct Atable *parent,
                         int type, char *name, uint8_t *raw,
@@ -510,6 +537,9 @@ struct Atable *mkatable(struct Atable *parent,
 struct Atable *finatable(struct Atable *t, struct slice *slice);
 struct Atable *finatable_nochildren(struct Atable *t);
 
+int get_early_num_cores(void);
+physaddr_t acpi_pci_get_mmio_cfg_addr(int segment, int bus, int dev, int func);
+
 extern struct Atable *apics;
 extern struct Atable *dmar;
 extern struct Atable *srat;