[haiku-gsoc] Re: HPET GSoC Patch #2: Bootloader ACPI Split Patch

On Thu, Jul 17, 2008 at 5:56 AM, Stefano Ceccherini
<stefano.ceccherini@xxxxxxxxx> wrote:
> 2008/7/17 Stefano Ceccherini <stefano.ceccherini@xxxxxxxxx>:
>
>> The patch, except for these small issues (which I can fix myself
>> before applying it), looks okay. I'm building the tree as I write this
>> mail, so I'll test the patch on the field later.
>
> There's other small issues: with gcc 2.95.3, the patch doesn't build,
> because you declared some variables in the middle of a block:
>
> +       TRACE(("acpi: searching %ld entries for table '%.4s'\n", numEntries,
> signature));
> +       uint32 *pointer = (uint32 *)((uint8 *)sAcpiRsdt +
> sizeof(acpi_descriptor_header));
> +       int32 j;
>
> for example.
> This is forbidden in C89. So either we rename the file to .cpp so it
> gets compiled as C++ or we move the declarations of those variables at
> the beginning of the block (I'm doing the latter to get the patch
> compiled on my pc).
>
>

I had to move the declarations out of the for loop initializers
because I went with C and not C++.
In retrospect, that doesn't make much sense. I blame temporary insanity.
New patch is attached...

-- 

- DH
Index: src/system/kernel/arch/x86/timers/x86_apic.c
===================================================================
--- src/system/kernel/arch/x86/timers/x86_apic.c        (revision 26472)
+++ src/system/kernel/arch/x86/timers/x86_apic.c        (working copy)
@@ -11,7 +11,7 @@
 #include <arch/x86/timer.h>
 
 #include <int.h>
-#include <arch/x86/smp_apic.h>
+#include <arch/x86/arch_apic.h>
 
 #include <arch/cpu.h>
 #include <arch/smp.h>
Index: src/system/kernel/arch/x86/arch_smp.c
===================================================================
--- src/system/kernel/arch/x86/arch_smp.c       (revision 26472)
+++ src/system/kernel/arch/x86/arch_smp.c       (working copy)
@@ -20,7 +20,7 @@
 #include <timer.h>
 
 #include <arch/x86/smp_priv.h>
-#include <arch/x86/smp_apic.h>
+#include <arch/x86/arch_apic.h>
 #include <arch/x86/timer.h>
 
 #include <string.h>
Index: src/system/boot/platform/bios_ia32/acpi.h
===================================================================
--- src/system/boot/platform/bios_ia32/acpi.h   (revision 0)
+++ src/system/boot/platform/bios_ia32/acpi.h   (revision 0)
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2005, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx All rights reserved.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef ACPI_H
+#define ACPI_H
+
+#include <SupportDefs.h>
+#include <arch/x86/arch_acpi.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct scan_spots_struct {
+       uint32 start;
+       uint32 stop;
+       uint32 length;
+};
+
+acpi_descriptor_header *acpi_find_table(char *signature);
+void acpi_init(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ACPI_H */
Index: src/system/boot/platform/bios_ia32/Jamfile
===================================================================
--- src/system/boot/platform/bios_ia32/Jamfile  (revision 26472)
+++ src/system/boot/platform/bios_ia32/Jamfile  (working copy)
@@ -29,6 +29,7 @@
        menu.cpp
        mmu.cpp
        cpu.cpp
+       acpi.cpp
        smp.cpp
        smp_trampoline.S
        support.S
Index: src/system/boot/platform/bios_ia32/smp.cpp
===================================================================
--- src/system/boot/platform/bios_ia32/smp.cpp  (revision 26472)
+++ src/system/boot/platform/bios_ia32/smp.cpp  (working copy)
@@ -1,4 +1,5 @@
 /*
+ * Copyright 2008, Dustin Howett, dustin.howett@xxxxxxxxxx All rights reserved.
  * Copyright 2004-2005, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
  * Distributed under the terms of the MIT License.
  *
@@ -9,6 +10,7 @@
 
 #include "smp.h"
 #include "mmu.h"
+#include "acpi.h"
 
 #include <KernelExport.h>
 
@@ -16,8 +18,8 @@
 #include <safemode.h>
 #include <boot/stage2.h>
 #include <boot/menu.h>
-#include <arch/x86/smp_acpi.h>
-#include <arch/x86/smp_apic.h>
+#include <arch/x86/arch_acpi.h>
+#include <arch/x86/arch_apic.h>
 #include <arch/x86/arch_system_info.h>
 
 #include <string.h>
@@ -36,24 +38,12 @@
        uint32 *b;
 } _PACKED;
 
-struct smp_scan_spots_struct {
-       uint32 start;
-       uint32 stop;
-       uint32 length;
-};
-
-static struct smp_scan_spots_struct smp_scan_spots[] = {
+static struct scan_spots_struct smp_scan_spots[] = {
        { 0x9fc00, 0xa0000, 0xa0000 - 0x9fc00 },
        { 0xf0000, 0x100000, 0x100000 - 0xf0000 },
        { 0, 0, 0 }
 };
 
-static struct smp_scan_spots_struct acpi_scan_spots[] = {
-       { 0x0, 0x400, 0x400 - 0x0 },
-       { 0xe0000, 0x100000, 0x100000 - 0xe0000 },
-       { 0, 0, 0 }
-};
-
 extern "C" void execute_n_instructions(int count);
 
 extern "C" void smp_trampoline(void);
@@ -103,21 +93,6 @@
 }
 
 
-static acpi_rsdp *
-smp_acpi_probe(uint32 base, uint32 limit)
-{
-       TRACE(("smp_acpi_probe: entry base 0x%lx, limit 0x%lx\n", base, limit));
-       for (char *pointer = (char *)base; (uint32)pointer < limit; pointer += 
16) {
-               if (strncmp(pointer, ACPI_RSDP_SIGNATURE, 8) == 0) {
-                       TRACE(("smp_acpi_probe: found ACPI RSDP signature at 
%p\n", pointer));
-                       return (acpi_rsdp *)pointer;
-               }
-       }
-
-       return NULL;
-}
-
-
 static status_t
 smp_do_mp_config(mp_floating_struct *floatingStruct)
 {
@@ -241,85 +216,59 @@
 
 
 static status_t
-smp_do_acpi_config(acpi_rsdp *rsdp)
+smp_do_acpi_config(void)
 {
        TRACE(("smp: using ACPI to detect MP configuration\n"));
-       TRACE(("smp: found rsdp at %p oem id: %.6s\n", rsdp, rsdp->oem_id));
-       TRACE(("smp: rsdp points to rsdt at 0x%lx\n", rsdp->rsdt_address));
 
        // reset CPU count
        gKernelArgs.num_cpus = 0;
 
-       // map and validate the root system description table
-       acpi_descriptor_header *rsdt
-               = (acpi_descriptor_header *)mmu_map_physical_memory(
-               rsdp->rsdt_address, B_PAGE_SIZE, kDefaultPageFlags);
-       if (!rsdt || strncmp(rsdt->signature, ACPI_RSDT_SIGNATURE, 4) != 0) {
-               TRACE(("smp: invalid root system description table\n"));
-               return B_ERROR;
-       }
+       acpi_madt *madt = (acpi_madt *)acpi_find_table(ACPI_MADT_SIGNATURE);
 
-       int32 numEntries = (rsdt->length - sizeof(acpi_descriptor_header)) / 4;
-       if (numEntries <= 0) {
-               TRACE(("smp: root system description table is empty\n"));
+       if (madt == NULL) {
+               TRACE(("smp: Failed to find MADT!\n"));
                return B_ERROR;
        }
 
-       TRACE(("smp: searching %ld entries for APIC information\n", 
numEntries));
-       uint32 *pointer = (uint32 *)((uint8 *)rsdt + 
sizeof(acpi_descriptor_header));
-       for (int32 j = 0; j < numEntries; j++, pointer++) {
-               acpi_descriptor_header *header = (acpi_descriptor_header *)
-                       mmu_map_physical_memory(*pointer, B_PAGE_SIZE, 
kDefaultPageFlags);
-               if (!header || strncmp(header->signature, ACPI_MADT_SIGNATURE, 
4) != 0) {
-                       // not interesting for us
-                       TRACE(("smp: skipping uninteresting header '%.4s'\n", 
header->signature));
-                       continue;
-               }
+       gKernelArgs.arch_args.apic_phys = madt->local_apic_address;
+       TRACE(("smp: local apic address is 0x%lx\n", madt->local_apic_address));
 
-               acpi_madt *madt = (acpi_madt *)header;
-               gKernelArgs.arch_args.apic_phys = madt->local_apic_address;
-               TRACE(("smp: local apic address is 0x%lx\n", 
madt->local_apic_address));
-
-               acpi_apic *apic = (acpi_apic *)((uint8 *)madt + 
sizeof(acpi_madt));
-               acpi_apic *end = (acpi_apic *)((uint8 *)madt + header->length);
-               while (apic < end) {
-                       switch (apic->type) {
-                               case ACPI_MADT_LOCAL_APIC:
-                               {
-                                       if (gKernelArgs.num_cpus == 
MAX_BOOT_CPUS) {
-                                               TRACE(("smp: already reached 
maximum boot CPUs (%d)\n", MAX_BOOT_CPUS));
-                                               break;
-                                       }
-
-                                       acpi_local_apic *localApic = 
(acpi_local_apic *)apic;
-                                       TRACE(("smp: found local APIC with id 
%u\n", localApic->apic_id));
-                                       if ((localApic->flags & 
ACPI_LOCAL_APIC_ENABLED) == 0) {
-                                               TRACE(("smp: APIC is disabled 
and will not be used\n"));
-                                               break;
-                                       }
-
-                                       
gKernelArgs.arch_args.cpu_apic_id[gKernelArgs.num_cpus] = localApic->apic_id;
-                                       
gKernelArgs.arch_args.cpu_os_id[localApic->apic_id] = gKernelArgs.num_cpus;
-                                       // ToDo: how to find out? putting 0x10 
in to indicate a local apic
-                                       
gKernelArgs.arch_args.cpu_apic_version[gKernelArgs.num_cpus] = 0x10;
-                                       gKernelArgs.num_cpus++;
+       acpi_apic *apic = (acpi_apic *)((uint8 *)madt + sizeof(acpi_madt));
+       acpi_apic *end = (acpi_apic *)((uint8 *)madt + madt->header.length);
+       while (apic < end) {
+               switch (apic->type) {
+                       case ACPI_MADT_LOCAL_APIC:
+                       {
+                               if (gKernelArgs.num_cpus == MAX_BOOT_CPUS) {
+                                       TRACE(("smp: already reached maximum 
boot CPUs (%d)\n", MAX_BOOT_CPUS));
                                        break;
                                }
 
-                               case ACPI_MADT_IO_APIC: {
-                                       acpi_io_apic *ioApic = (acpi_io_apic 
*)apic;
-                                       TRACE(("smp: found io APIC with id %u 
and address 0x%lx\n",
-                                               ioApic->io_apic_id, 
ioApic->io_apic_address));
-                                       gKernelArgs.arch_args.ioapic_phys = 
ioApic->io_apic_address;
+                               acpi_local_apic *localApic = (acpi_local_apic 
*)apic;
+                               TRACE(("smp: found local APIC with id %u\n", 
localApic->apic_id));
+                               if ((localApic->flags & 
ACPI_LOCAL_APIC_ENABLED) == 0) {
+                                       TRACE(("smp: APIC is disabled and will 
not be used\n"));
                                        break;
                                }
+
+                               
gKernelArgs.arch_args.cpu_apic_id[gKernelArgs.num_cpus] = localApic->apic_id;
+                               
gKernelArgs.arch_args.cpu_os_id[localApic->apic_id] = gKernelArgs.num_cpus;
+                               // ToDo: how to find out? putting 0x10 in to 
indicate a local apic
+                               
gKernelArgs.arch_args.cpu_apic_version[gKernelArgs.num_cpus] = 0x10;
+                               gKernelArgs.num_cpus++;
+                               break;
                        }
 
-                       apic = (acpi_apic *)((uint8 *)apic + apic->length);
+                       case ACPI_MADT_IO_APIC: {
+                               acpi_io_apic *ioApic = (acpi_io_apic *)apic;
+                               TRACE(("smp: found io APIC with id %u and 
address 0x%lx\n",
+                                       ioApic->io_apic_id, 
ioApic->io_apic_address));
+                               gKernelArgs.arch_args.ioapic_phys = 
ioApic->io_apic_address;
+                               break;
+                       }
                }
 
-               if (gKernelArgs.num_cpus > 0)
-                       break;
+               apic = (acpi_apic *)((uint8 *)apic + apic->length);
        }
 
        return gKernelArgs.num_cpus > 0 ? B_OK : B_ERROR;
@@ -604,12 +553,8 @@
        // first try to find ACPI tables to get MP configuration as it handles
        // physical as well as logical MP configurations as in multiple cpus,
        // multiple cores or hyper threading.
-       for (int32 i = 0; acpi_scan_spots[i].length > 0; i++) {
-               acpi_rsdp *rsdp = smp_acpi_probe(smp_scan_spots[i].start,
-                       smp_scan_spots[i].stop);
-               if (rsdp != NULL && smp_do_acpi_config(rsdp) == B_OK)
-                       return;
-       }
+       if (smp_do_acpi_config() == B_OK)
+               return;
 
        // then try to find MPS tables and do configuration based on them
        for (int32 i = 0; smp_scan_spots[i].length > 0; i++) {
Index: src/system/boot/platform/bios_ia32/acpi.cpp
===================================================================
--- src/system/boot/platform/bios_ia32/acpi.cpp (revision 0)
+++ src/system/boot/platform/bios_ia32/acpi.cpp (revision 0)
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2008, Dustin Howett, dustin.howett@xxxxxxxxxx All rights reserved.
+ * Copyright 2004-2005, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
+ * Distributed under the terms of the MIT License.
+ *
+ * Copyright 2001, Travis Geiselbrecht. All rights reserved.
+ * Distributed under the terms of the NewOS License.
+*/
+
+
+#include "acpi.h"
+#include "mmu.h"
+
+#include <KernelExport.h>
+
+#include <arch/x86/arch_acpi.h>
+
+#include <string.h>
+
+#define TRACE_ACPI
+#ifdef TRACE_ACPI
+#      define TRACE(x) dprintf x
+#else
+#      define TRACE(x) ;
+#endif
+
+static struct scan_spots_struct acpi_scan_spots[] = {
+       { 0x0, 0x400, 0x400 - 0x0 },
+       { 0xe0000, 0x100000, 0x100000 - 0xe0000 },
+       { 0, 0, 0 }
+};
+
+static acpi_descriptor_header *sAcpiRsdt; // System Description Table
+
+
+static status_t
+acpi_check_rsdt(acpi_rsdp *rsdp)
+{
+       TRACE(("acpi: found rsdp at %p oem id: %.6s\n", rsdp, rsdp->oem_id));
+       TRACE(("acpi: rsdp points to rsdt at 0x%lx\n", rsdp->rsdt_address));
+
+       // map and validate the root system description table
+       acpi_descriptor_header *rsdt
+               = (acpi_descriptor_header *)mmu_map_physical_memory(
+               rsdp->rsdt_address, B_PAGE_SIZE, kDefaultPageFlags);
+       if (!rsdt || strncmp(rsdt->signature, ACPI_RSDT_SIGNATURE, 4) != 0) {
+               TRACE(("acpi: invalid root system description table\n"));
+               return B_ERROR;
+       }
+
+       sAcpiRsdt = rsdt;
+       return B_OK;
+}
+
+
+acpi_descriptor_header *
+acpi_find_table(char *signature)
+{
+       if (sAcpiRsdt == NULL) {
+               return NULL;
+       }
+
+       // Tried to keep numEntries a static variable; kept turning up 0 on 
table scan
+       // TODO: This calculates numEntries for every acpi probe.
+       int32 numEntries = (sAcpiRsdt->length - sizeof(acpi_descriptor_header)) 
/ 4;
+       if (numEntries <= 0) {
+               TRACE(("acpi: root system description table is empty\n"));
+               return NULL;
+       }
+
+       TRACE(("acpi: searching %ld entries for table '%.4s'\n", numEntries, 
signature));
+       uint32 *pointer = (uint32 *)((uint8 *)sAcpiRsdt + 
sizeof(acpi_descriptor_header));
+       for (int32 j = 0; j < numEntries; j++, pointer++) {
+               acpi_descriptor_header *header = (acpi_descriptor_header *)
+                       mmu_map_physical_memory(*pointer, B_PAGE_SIZE, 
kDefaultPageFlags);
+               if (!header || strncmp(header->signature, signature, 4) != 0) {
+                       // not interesting for us
+                       TRACE(("acpi: Looking for '%.4s'. Skipping '%.4s'\n", 
signature, header->signature));
+                       continue;
+               }
+               TRACE(("acpi: Found '%.4s' @ %p\n", signature));
+               return header;
+       }
+
+       // If we didn't find the table, return NULL.
+       return NULL;
+}
+
+
+void
+acpi_init(void)
+{
+       acpi_rsdp *rsdp = NULL;
+       // Try to find the ACPI RSDP.
+       for (int32 i = 0; acpi_scan_spots[i].length > 0; i++) {
+               char *pointer;
+               TRACE(("acpi_init: entry base 0x%lx, limit 0x%lx\n", 
acpi_scan_spots[i].start,
+                       acpi_scan_spots[i].stop));
+               for (pointer = (char *)acpi_scan_spots[i].start;
+                    (uint32)pointer < acpi_scan_spots[i].stop; pointer += 16) {
+                       if (strncmp(pointer, ACPI_RSDP_SIGNATURE, 8) == 0) {
+                               TRACE(("acpi_init: found ACPI RSDP signature at 
%p\n", pointer));
+                               rsdp = (acpi_rsdp *)pointer;
+                       }
+               }
+               if (acpi_check_rsdt(rsdp) == B_OK)
+                       break;
+       }
+
+}
Index: src/system/boot/platform/bios_ia32/start.c
===================================================================
--- src/system/boot/platform/bios_ia32/start.c  (revision 26472)
+++ src/system/boot/platform/bios_ia32/start.c  (working copy)
@@ -10,6 +10,7 @@
 #include "cpu.h"
 #include "mmu.h"
 #include "smp.h"
+#include "acpi.h"
 #include "keyboard.h"
 #include "bios.h"
 
@@ -132,6 +133,7 @@
                serial_enable();
 
        apm_init();
+       acpi_init();
        smp_init();
        main(&args);
 }
Index: headers/private/kernel/arch/x86/smp_apic.h
===================================================================
--- headers/private/kernel/arch/x86/smp_apic.h  (working copy)
+++ headers/private/kernel/arch/x86/smp_apic.h  (working copy)
@@ -1,194 +0,0 @@
-/*
- * Copyright 2005, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx All rights reserved.
- * Distributed under the terms of the MIT License.
- *
- * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
- * Distributed under the terms of the NewOS License.
- */
-#ifndef _KERNEL_ARCH_x86_SMP_APIC_H
-#define _KERNEL_ARCH_x86_SMP_APIC_H
-
-#define MP_FLOATING_SIGNATURE                  '_PM_'
-#define MP_CONFIG_TABLE_SIGNATURE              'PCMP'
-
-#define APIC_ENABLE                            0x100
-#define APIC_FOCUS                             (~(1 << 9))
-#define APIC_SIV                               (0xff)
-
-// offsets to APIC register
-#define APIC_ID                                                        0x020
-#define APIC_VERSION                                   0x030
-#define APIC_TASK_PRIORITY                             0x080
-#define APIC_ARBITRATION_PRIORITY              0x090
-#define APIC_PROCESSOR_PRIORITY                        0x0a0
-#define APIC_EOI                                               0x0b0
-#define APIC_LOGICAL_DEST                              0x0d0
-#define APIC_DEST_FORMAT                               0x0e0
-#define APIC_SPURIOUS_INTR_VECTOR              0x0f0
-#define APIC_ERROR_STATUS                              0x280
-#define APIC_INTR_COMMAND_1                            0x300   // bits 0-31
-#define APIC_INTR_COMMAND_2                            0x310   // bits 32-63
-#define APIC_LVT_TIMER                                 0x320
-#define APIC_LVT_THERMAL_SENSOR                        0x330
-#define APIC_LVT_PERFMON_COUNTERS              0x340
-#define APIC_LVT_LINT0                                 0x350
-#define APIC_LVT_LINT1                                 0x360
-#define APIC_LVT_ERROR                                 0x370
-#define APIC_INITIAL_TIMER_COUNT               0x380
-#define APIC_CURRENT_TIMER_COUNT               0x390
-#define APIC_TIMER_DIVIDE_CONFIG               0x3e0
-
-/* standard APIC interrupt defines */
-#define APIC_DELIVERY_MODE_FIXED                               0
-#define APIC_DELIVERY_MODE_LOWESTPRI                   (1 << 8)        // ICR1 
only
-#define APIC_DELIVERY_MODE_SMI                                 (2 << 8)
-#define APIC_DELIVERY_MODE_NMI                                 (4 << 8)
-#define APIC_DELIVERY_MODE_INIT                                        (5 << 8)
-#define APIC_DELIVERY_MODE_STARTUP                             (6 << 8)        
// ICR1 only
-#define APIC_DELIVERY_MODE_ExtINT                              (7 << 8)        
// LINT0/1 only
-
-#define APIC_DELIVERY_STATUS                                   (1 << 12)
-#define APIC_TRIGGER_MODE_LEVEL                                        (1 << 
15)
-
-/* Interrupt Command defines */
-#define APIC_INTR_COMMAND_1_MASK                               0xfff3f000
-#define APIC_INTR_COMMAND_2_MASK                               0x00ffffff
-
-#define APIC_INTR_COMMAND_1_DEST_MODE_PHYSICAL 0
-#define APIC_INTR_COMMAND_1_DEST_MODE_LOGICAL  (1 << 11)
-
-#define APIC_INTR_COMMAND_1_ASSERT                             (1 << 14)
-
-#define APIC_INTR_COMMAND_1_DEST_FIELD                 0
-#define APIC_INTR_COMMAND_1_DEST_SELF                  (1 << 18)
-#define APIC_INTR_COMMAND_1_DEST_ALL                   (2 << 18)
-#define APIC_INTR_COMMAND_1_DEST_ALL_BUT_SELF  (3 << 18)
-
-/* Local Vector Table defines */
-#define APIC_LVT_MASKED                                                        
(1 << 16)
-
-// timer defines
-#define APIC_LVT_TIMER_MASK                                            
0xfffcef00
-
-// LINT0/1 defines 
-#define APIC_LVT_LINT_MASK                                             
0xfffe0800
-#define APIC_LVT_LINT_INPUT_POLARITY                   (1 << 13)
-
-// Timer Divide Config Divisors
-#define APIC_TIMER_DIVIDE_CONFIG_1                             0x0b
-#define APIC_TIMER_DIVIDE_CONFIG_2                             0x00
-#define APIC_TIMER_DIVIDE_CONFIG_4                             0x01
-#define APIC_TIMER_DIVIDE_CONFIG_8                             0x02
-#define APIC_TIMER_DIVIDE_CONFIG_16                            0x03
-#define APIC_TIMER_DIVIDE_CONFIG_32                            0x08
-#define APIC_TIMER_DIVIDE_CONFIG_64                            0x09
-#define APIC_TIMER_DIVIDE_CONFIG_128                   0x0a
-
-/*
-#define APIC_LVT_DM                            0x00000700
-#define APIC_LVT_DM_ExtINT             0x00000700
-#define APIC_LVT_DM_NMI                        0x00000400
-#define APIC_LVT_IIPP                  0x00002000
-#define APIC_LVT_TM                            0x00008000
-#define APIC_LVT_M                             0x00010000
-#define APIC_LVT_OS                            0x00020000
-
-#define APIC_TPR_PRIO                  0x000000ff
-#define APIC_TPR_INT                   0x000000f0
-#define APIC_TPR_SUB                   0x0000000f
-
-#define APIC_SVR_SWEN                  0x00000100
-#define APIC_SVR_FOCUS                 0x00000200
-
-#define IOAPIC_ID                              0x0
-#define IOAPIC_VERSION                 0x1
-#define IOAPIC_ARB                             0x2
-#define IOAPIC_REDIR_TABLE             0x10
-
-#define IPI_CACHE_FLUSH                        0x40
-#define IPI_INV_TLB                            0x41
-#define IPI_INV_PTE                            0x42
-#define IPI_INV_RESCHED                        0x43
-#define IPI_STOP                               0x44
-*/
-
-struct mp_config_table {
-       uint32  signature;                      /* "PCMP" */
-       uint16  base_table_length;      /* length of the base table entries and 
this structure */
-       uint8   spec_revision;          /* spec supported, 1 for 1.1 or 4 for 
1.4 */
-       uint8   checksum;                       /* checksum, all bytes add up 
to zero */
-       char    oem[8];                         /* oem identification, not 
null-terminated */
-       char    product[12];            /* product name, not null-terminated */
-       void    *oem_table;                     /* addr of oem-defined table, 
zero if none */
-       uint16  oem_length;                     /* length of oem table */
-       uint16  num_base_entries;       /* number of entries in base table */
-       uint32  apic;                           /* address of apic */
-       uint16  ext_length;                     /* length of extended section */
-       uint8   ext_checksum;           /* checksum of extended table entries */
-       uint8   reserved;
-};
-
-struct mp_floating_struct {
-       uint32  signature;                      /* "_MP_" */
-       struct mp_config_table *config_table; /* address of mp configuration 
table */
-       uint8   config_length;          /* length of the table in 16-byte units 
*/
-       uint8   spec_revision;          /* spec supported, 1 for 1.1 or 4 for 
1.4 */
-       uint8   checksum;                       /* checksum, all bytes add up 
to zero */
-       uint8   mp_feature_1;           /* mp system configuration type if no 
mpc */
-       uint8   mp_feature_2;           /* imcrp */
-       uint8   mp_feature_3, mp_feature_4, mp_feature_5; /* reserved */
-};
-
-/* base config entry types */
-enum {
-       MP_BASE_PROCESSOR = 0,
-       MP_BASE_BUS,
-       MP_BASE_IO_APIC,
-       MP_BASE_IO_INTR,
-       MP_BASE_LOCAL_INTR,
-};
-
-struct mp_base_processor {
-       uint8   type;
-       uint8   apic_id;
-       uint8   apic_version;
-       uint8   cpu_flags;
-       uint32  signature;                      /* stepping, model, family, 
each four bits */
-       uint32  feature_flags;
-       uint32  res1, res2;
-};
-
-struct mp_base_ioapic {
-       uint8   type;
-       uint8   ioapic_id;
-       uint8   ioapic_version;
-       uint8   ioapic_flags;
-       uint32  *addr;
-};
-
-struct mp_base_bus {
-       uint8   type;
-       uint8   bus_id;
-       char    name[6];
-};
-
-struct mp_base_interrupt {
-       uint8   type;
-       uint8   interrupt_type;
-       uint16  polarity : 2;
-       uint16  trigger_mode : 2;
-       uint16  _reserved : 12;
-       uint8   source_bus_id;
-       uint8   source_bus_irq;
-       uint8   dest_apic_id;
-       uint8   dest_apic_int;
-};
-
-enum {
-       MP_INTR_TYPE_INT = 0,
-       MP_INTR_TYPE_NMI,
-       MP_INTR_TYPE_SMI,
-       MP_INTR_TYPE_ExtINT,
-};
-
-#endif /* _KERNEL_ARCH_x86_SMP_APIC_H */
Index: headers/private/kernel/arch/x86/smp_acpi.h
===================================================================
--- headers/private/kernel/arch/x86/smp_acpi.h  (working copy)
+++ headers/private/kernel/arch/x86/smp_acpi.h  (working copy)
@@ -1,71 +0,0 @@
-/*
- * Copyright 2007, Michael Lotz, mmlr@xxxxxxxxx All rights reserved.
- * Distributed under the terms of the MIT License.
- */
-#ifndef _KERNEL_ARCH_x86_SMP_ACPI_H
-#define _KERNEL_ARCH_x86_SMP_ACPI_H
-
-#define ACPI_RSDP_SIGNATURE            "RSD PTR "
-#define ACPI_RSDT_SIGNATURE            "RSDT"
-#define ACPI_MADT_SIGNATURE            "APIC"
-
-#define ACPI_LOCAL_APIC_ENABLED        0x01
-
-struct acpi_rsdp {
-       char    signature[8];                   /* "RSD PTR " including blank */
-       uint8   checksum;                               /* checksum of bytes 
0-19 (per ACPI 1.0) */
-       char    oem_id[6];                              /* not null terminated 
*/
-       uint8   revision;                               /* 0 = ACPI 1.0, 2 = 
ACPI 3.0 */
-       uint32  rsdt_address;                   /* physical memory address of 
RSDT */
-       uint32  rsdt_length;                    /* length in bytes including 
header */
-       uint64  xsdt_address;                   /* 64bit physical memory 
address of XSDT */
-       uint8   extended_checksum;              /* including entire table */
-       uint8   reserved[3];
-} _PACKED;
-
-struct acpi_descriptor_header {
-       char    signature[4];                   /* table identifier as ASCII 
string */
-       uint32  length;                                 /* length in bytes of 
the entire table */
-       uint8   revision;
-       uint8   checksum;                               /* checksum of entire 
table */
-       char    oem_id[6];                              /* not null terminated 
*/
-       char    oem_table_id[8];                /* oem supplied table 
identifier */
-       uint32  oem_revision;                   /* oem supplied revision number 
*/
-       char    creator_id[4];                  /* creator / asl compiler id */
-       uint32  creator_revision;               /* compiler revision */
-} _PACKED;
-
-struct acpi_madt {
-       acpi_descriptor_header  header; /* "APIC" signature */
-       uint32  local_apic_address;             /* physical address for local 
CPUs APICs */
-       uint32  flags;
-} _PACKED;
-
-enum {
-       ACPI_MADT_LOCAL_APIC = 0,
-       ACPI_MADT_IO_APIC = 1
-};
-
-struct acpi_apic {
-       uint8   type;
-       uint8   length;
-} _PACKED;
-
-struct acpi_local_apic {
-       uint8   type;                                   /* 0 = processor local 
APIC */
-       uint8   length;                                 /* 8 bytes */
-       uint8   acpi_processor_id;
-       uint8   apic_id;                                /* the id of this APIC 
*/
-       uint32  flags;                                  /* 1 = enabled */
-} _PACKED;
-
-struct acpi_io_apic {
-       uint8   type;                                   /* 1 = I/O APIC */
-       uint8   length;                                 /* 12 bytes */
-       uint8   io_apic_id;                             /* the id of this APIC 
*/
-       uint8   reserved;
-       uint32  io_apic_address;                /* phyisical address of I/O 
APIC */
-       uint32  interrupt_base;                 /* global system interrupt base 
*/
-} _PACKED;
-
-#endif /* _KERNEL_ARCH_x86_SMP_ACPI_H */
Index: headers/private/kernel/arch/x86/arch_apic.h
===================================================================
--- headers/private/kernel/arch/x86/arch_apic.h (revision 0)
+++ headers/private/kernel/arch/x86/arch_apic.h (revision 0)
@@ -0,0 +1,195 @@
+/*
+ * Copyright 2008, Dustin Howett, dustin.howett@xxxxxxxxxx All rights reserved.
+ * Copyright 2005, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx All rights reserved.
+ * Distributed under the terms of the MIT License.
+ *
+ * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
+ * Distributed under the terms of the NewOS License.
+ */
+#ifndef _KERNEL_ARCH_x86_ARCH_APIC_H
+#define _KERNEL_ARCH_x86_ARCH_APIC_H
+
+#define MP_FLOATING_SIGNATURE                  '_PM_'
+#define MP_CONFIG_TABLE_SIGNATURE              'PCMP'
+
+#define APIC_ENABLE                            0x100
+#define APIC_FOCUS                             (~(1 << 9))
+#define APIC_SIV                               (0xff)
+
+// offsets to APIC register
+#define APIC_ID                                                        0x020
+#define APIC_VERSION                                   0x030
+#define APIC_TASK_PRIORITY                             0x080
+#define APIC_ARBITRATION_PRIORITY              0x090
+#define APIC_PROCESSOR_PRIORITY                        0x0a0
+#define APIC_EOI                                               0x0b0
+#define APIC_LOGICAL_DEST                              0x0d0
+#define APIC_DEST_FORMAT                               0x0e0
+#define APIC_SPURIOUS_INTR_VECTOR              0x0f0
+#define APIC_ERROR_STATUS                              0x280
+#define APIC_INTR_COMMAND_1                            0x300   // bits 0-31
+#define APIC_INTR_COMMAND_2                            0x310   // bits 32-63
+#define APIC_LVT_TIMER                                 0x320
+#define APIC_LVT_THERMAL_SENSOR                        0x330
+#define APIC_LVT_PERFMON_COUNTERS              0x340
+#define APIC_LVT_LINT0                                 0x350
+#define APIC_LVT_LINT1                                 0x360
+#define APIC_LVT_ERROR                                 0x370
+#define APIC_INITIAL_TIMER_COUNT               0x380
+#define APIC_CURRENT_TIMER_COUNT               0x390
+#define APIC_TIMER_DIVIDE_CONFIG               0x3e0
+
+/* standard APIC interrupt defines */
+#define APIC_DELIVERY_MODE_FIXED                               0
+#define APIC_DELIVERY_MODE_LOWESTPRI                   (1 << 8)        // ICR1 
only
+#define APIC_DELIVERY_MODE_SMI                                 (2 << 8)
+#define APIC_DELIVERY_MODE_NMI                                 (4 << 8)
+#define APIC_DELIVERY_MODE_INIT                                        (5 << 8)
+#define APIC_DELIVERY_MODE_STARTUP                             (6 << 8)        
// ICR1 only
+#define APIC_DELIVERY_MODE_ExtINT                              (7 << 8)        
// LINT0/1 only
+
+#define APIC_DELIVERY_STATUS                                   (1 << 12)
+#define APIC_TRIGGER_MODE_LEVEL                                        (1 << 
15)
+
+/* Interrupt Command defines */
+#define APIC_INTR_COMMAND_1_MASK                               0xfff3f000
+#define APIC_INTR_COMMAND_2_MASK                               0x00ffffff
+
+#define APIC_INTR_COMMAND_1_DEST_MODE_PHYSICAL 0
+#define APIC_INTR_COMMAND_1_DEST_MODE_LOGICAL  (1 << 11)
+
+#define APIC_INTR_COMMAND_1_ASSERT                             (1 << 14)
+
+#define APIC_INTR_COMMAND_1_DEST_FIELD                 0
+#define APIC_INTR_COMMAND_1_DEST_SELF                  (1 << 18)
+#define APIC_INTR_COMMAND_1_DEST_ALL                   (2 << 18)
+#define APIC_INTR_COMMAND_1_DEST_ALL_BUT_SELF  (3 << 18)
+
+/* Local Vector Table defines */
+#define APIC_LVT_MASKED                                                        
(1 << 16)
+
+// timer defines
+#define APIC_LVT_TIMER_MASK                                            
0xfffcef00
+
+// LINT0/1 defines 
+#define APIC_LVT_LINT_MASK                                             
0xfffe0800
+#define APIC_LVT_LINT_INPUT_POLARITY                   (1 << 13)
+
+// Timer Divide Config Divisors
+#define APIC_TIMER_DIVIDE_CONFIG_1                             0x0b
+#define APIC_TIMER_DIVIDE_CONFIG_2                             0x00
+#define APIC_TIMER_DIVIDE_CONFIG_4                             0x01
+#define APIC_TIMER_DIVIDE_CONFIG_8                             0x02
+#define APIC_TIMER_DIVIDE_CONFIG_16                            0x03
+#define APIC_TIMER_DIVIDE_CONFIG_32                            0x08
+#define APIC_TIMER_DIVIDE_CONFIG_64                            0x09
+#define APIC_TIMER_DIVIDE_CONFIG_128                   0x0a
+
+/*
+#define APIC_LVT_DM                            0x00000700
+#define APIC_LVT_DM_ExtINT             0x00000700
+#define APIC_LVT_DM_NMI                        0x00000400
+#define APIC_LVT_IIPP                  0x00002000
+#define APIC_LVT_TM                            0x00008000
+#define APIC_LVT_M                             0x00010000
+#define APIC_LVT_OS                            0x00020000
+
+#define APIC_TPR_PRIO                  0x000000ff
+#define APIC_TPR_INT                   0x000000f0
+#define APIC_TPR_SUB                   0x0000000f
+
+#define APIC_SVR_SWEN                  0x00000100
+#define APIC_SVR_FOCUS                 0x00000200
+
+#define IOAPIC_ID                              0x0
+#define IOAPIC_VERSION                 0x1
+#define IOAPIC_ARB                             0x2
+#define IOAPIC_REDIR_TABLE             0x10
+
+#define IPI_CACHE_FLUSH                        0x40
+#define IPI_INV_TLB                            0x41
+#define IPI_INV_PTE                            0x42
+#define IPI_INV_RESCHED                        0x43
+#define IPI_STOP                               0x44
+*/
+
+struct mp_config_table {
+       uint32  signature;                      /* "PCMP" */
+       uint16  base_table_length;      /* length of the base table entries and 
this structure */
+       uint8   spec_revision;          /* spec supported, 1 for 1.1 or 4 for 
1.4 */
+       uint8   checksum;                       /* checksum, all bytes add up 
to zero */
+       char    oem[8];                         /* oem identification, not 
null-terminated */
+       char    product[12];            /* product name, not null-terminated */
+       void    *oem_table;                     /* addr of oem-defined table, 
zero if none */
+       uint16  oem_length;                     /* length of oem table */
+       uint16  num_base_entries;       /* number of entries in base table */
+       uint32  apic;                           /* address of apic */
+       uint16  ext_length;                     /* length of extended section */
+       uint8   ext_checksum;           /* checksum of extended table entries */
+       uint8   reserved;
+};
+
+struct mp_floating_struct {
+       uint32  signature;                      /* "_MP_" */
+       struct mp_config_table *config_table; /* address of mp configuration 
table */
+       uint8   config_length;          /* length of the table in 16-byte units 
*/
+       uint8   spec_revision;          /* spec supported, 1 for 1.1 or 4 for 
1.4 */
+       uint8   checksum;                       /* checksum, all bytes add up 
to zero */
+       uint8   mp_feature_1;           /* mp system configuration type if no 
mpc */
+       uint8   mp_feature_2;           /* imcrp */
+       uint8   mp_feature_3, mp_feature_4, mp_feature_5; /* reserved */
+};
+
+/* base config entry types */
+enum {
+       MP_BASE_PROCESSOR = 0,
+       MP_BASE_BUS,
+       MP_BASE_IO_APIC,
+       MP_BASE_IO_INTR,
+       MP_BASE_LOCAL_INTR,
+};
+
+struct mp_base_processor {
+       uint8   type;
+       uint8   apic_id;
+       uint8   apic_version;
+       uint8   cpu_flags;
+       uint32  signature;                      /* stepping, model, family, 
each four bits */
+       uint32  feature_flags;
+       uint32  res1, res2;
+};
+
+struct mp_base_ioapic {
+       uint8   type;
+       uint8   ioapic_id;
+       uint8   ioapic_version;
+       uint8   ioapic_flags;
+       uint32  *addr;
+};
+
+struct mp_base_bus {
+       uint8   type;
+       uint8   bus_id;
+       char    name[6];
+};
+
+struct mp_base_interrupt {
+       uint8   type;
+       uint8   interrupt_type;
+       uint16  polarity : 2;
+       uint16  trigger_mode : 2;
+       uint16  _reserved : 12;
+       uint8   source_bus_id;
+       uint8   source_bus_irq;
+       uint8   dest_apic_id;
+       uint8   dest_apic_int;
+};
+
+enum {
+       MP_INTR_TYPE_INT = 0,
+       MP_INTR_TYPE_NMI,
+       MP_INTR_TYPE_SMI,
+       MP_INTR_TYPE_ExtINT,
+};
+
+#endif /* _KERNEL_ARCH_x86_ARCH_APIC_H */
Index: headers/private/kernel/arch/x86/arch_acpi.h
===================================================================
--- headers/private/kernel/arch/x86/arch_acpi.h (revision 0)
+++ headers/private/kernel/arch/x86/arch_acpi.h (revision 0)
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2008, Dustin Howett, dustin.howett@xxxxxxxxxx All rights reserved.
+ * Copyright 2007, Michael Lotz, mmlr@xxxxxxxxx All rights reserved.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef _KERNEL_ARCH_x86_ARCH_ACPI_H
+#define _KERNEL_ARCH_x86_ARCH_ACPI_H
+
+#define ACPI_RSDP_SIGNATURE            "RSD PTR "
+#define ACPI_RSDT_SIGNATURE            "RSDT"
+#define ACPI_MADT_SIGNATURE            "APIC"
+
+#define ACPI_LOCAL_APIC_ENABLED        0x01
+
+typedef struct acpi_rsdp {
+       char    signature[8];                   /* "RSD PTR " including blank */
+       uint8   checksum;                               /* checksum of bytes 
0-19 (per ACPI 1.0) */
+       char    oem_id[6];                              /* not null terminated 
*/
+       uint8   revision;                               /* 0 = ACPI 1.0, 2 = 
ACPI 3.0 */
+       uint32  rsdt_address;                   /* physical memory address of 
RSDT */
+       uint32  rsdt_length;                    /* length in bytes including 
header */
+       uint64  xsdt_address;                   /* 64bit physical memory 
address of XSDT */
+       uint8   extended_checksum;              /* including entire table */
+       uint8   reserved[3];
+} _PACKED acpi_rsdp;
+
+typedef struct acpi_descriptor_header {
+       char    signature[4];                   /* table identifier as ASCII 
string */
+       uint32  length;                                 /* length in bytes of 
the entire table */
+       uint8   revision;
+       uint8   checksum;                               /* checksum of entire 
table */
+       char    oem_id[6];                              /* not null terminated 
*/
+       char    oem_table_id[8];                /* oem supplied table 
identifier */
+       uint32  oem_revision;                   /* oem supplied revision number 
*/
+       char    creator_id[4];                  /* creator / asl compiler id */
+       uint32  creator_revision;               /* compiler revision */
+} _PACKED acpi_descriptor_header;
+
+typedef struct acpi_madt {
+       acpi_descriptor_header  header;         /* "APIC" signature */
+       uint32  local_apic_address;             /* physical address for local 
CPUs APICs */
+       uint32  flags;
+} _PACKED acpi_madt;
+
+enum {
+       ACPI_MADT_LOCAL_APIC = 0,
+       ACPI_MADT_IO_APIC = 1
+};
+
+typedef struct acpi_apic {
+       uint8   type;
+       uint8   length;
+} _PACKED acpi_apic;
+
+typedef struct acpi_local_apic {
+       uint8   type;                                   /* 0 = processor local 
APIC */
+       uint8   length;                                 /* 8 bytes */
+       uint8   acpi_processor_id;
+       uint8   apic_id;                                /* the id of this APIC 
*/
+       uint32  flags;                                  /* 1 = enabled */
+} _PACKED acpi_local_apic;
+
+typedef struct acpi_io_apic {
+       uint8   type;                                   /* 1 = I/O APIC */
+       uint8   length;                                 /* 12 bytes */
+       uint8   io_apic_id;                             /* the id of this APIC 
*/
+       uint8   reserved;
+       uint32  io_apic_address;                /* phyisical address of I/O 
APIC */
+       uint32  interrupt_base;                 /* global system interrupt base 
*/
+} _PACKED acpi_io_apic;
+
+#endif /* _KERNEL_ARCH_x86_ARCH_ACPI_H */

Other related posts: