We define IO_APIC_ADDR in <arch/ioapic.h>, let's use it.
[coreboot.git] / src / northbridge / via / cx700 / cx700_lpc.c
index 65275baa81a3734df468cc408436e50ad044535a..77ab97c145d52dd0394144bb47dd8c6fe0cadfa4 100644 (file)
 
 #include <arch/io.h>
 #include <console/console.h>
-
 #include <device/device.h>
 #include <device/pci.h>
 #include <device/pci_ops.h>
 #include <device/pci_ids.h>
-
 #include <pc80/mc146818rtc.h>
 #include <pc80/i8259.h>
 #include <pc80/keyboard.h>
 #include <pc80/isa-dma.h>
-
 #include <cpu/x86/lapic.h>
+#include <arch/ioapic.h>
 #include <stdlib.h>
 
 #define ACPI_IO_BASE   0x400
 #define HPET_ADDR      0xfe800000UL
-#define IOAPIC_ADDR    0xfec00000ULL
-
-#ifdef CONFIG_IOAPIC
-struct ioapicreg {
-       unsigned int reg;
-       unsigned int value_low, value_high;
-};
-
-static struct ioapicreg ioapicregvalues[] = {
-#define ALL            (0xff << 24)
-#define NONE           (0)
-#define DISABLED       (1 << 16)
-#define ENABLED                (0 << 16)
-#define TRIGGER_EDGE   (0 << 15)
-#define TRIGGER_LEVEL  (1 << 15)
-#define POLARITY_HIGH  (0 << 13)
-#define POLARITY_LOW   (1 << 13)
-#define PHYSICAL_DEST  (0 << 11)
-#define LOGICAL_DEST   (1 << 11)
-#define ExtINT         (7 << 8)
-#define NMI            (4 << 8)
-#define SMI            (2 << 8)
-#define INT            (1 << 8)
-       /* IO-APIC virtual wire mode configuration */
-       /* mask, trigger, polarity, destination, delivery, vector */
-       { 0, ENABLED | TRIGGER_EDGE | POLARITY_HIGH | PHYSICAL_DEST | ExtINT, NONE},
-       { 1, DISABLED, NONE},
-       { 2, DISABLED, NONE},
-       { 3, DISABLED, NONE},
-       { 4, DISABLED, NONE},
-       { 5, DISABLED, NONE},
-       { 6, DISABLED, NONE},
-       { 7, DISABLED, NONE},
-       { 8, DISABLED, NONE},
-       { 9, DISABLED, NONE},
-       {10, DISABLED, NONE},
-       {11, DISABLED, NONE},
-       {12, DISABLED, NONE},
-       {13, DISABLED, NONE},
-       {14, DISABLED, NONE},
-       {15, DISABLED, NONE},
-       {16, DISABLED, NONE},
-       {17, DISABLED, NONE},
-       {18, DISABLED, NONE},
-       {19, DISABLED, NONE},
-       {20, DISABLED, NONE},
-       {21, DISABLED, NONE},
-       {22, DISABLED, NONE},
-       {23, DISABLED, NONE},
-};
-
-static void setup_ioapic(void)
-{
-       int i;
-       unsigned long value_low, value_high, val;
-       unsigned long ioapic_base = IOAPIC_ADDR;
-       volatile unsigned long *l;
-       struct ioapicreg *a = ioapicregvalues;
-       unsigned long bsp_lapicid = lapicid();
-
-       l = (unsigned long *)ioapic_base;
-
-       /* Set APIC ADDR */
-       l[0] = 0;
-       val = l[4];
-       l[4] = (val & 0xF0FFFF) | (2 << 24);    // 2 == ID as programmed elsewhere. should be a define? XXX
-
-       /* Set APIC to FSB message bus. */
-       l[0] = 0x3;
-       val = l[4];
-       l[4] = (val & 0xFFFFFE) | 1;
-
-       ioapicregvalues[0].value_high = bsp_lapicid << (56 - 32);
-
-       printk_debug("IOAPIC:  Bootstrap Processor Local APIC ID = %02x\n", bsp_lapicid);
-
-       for (i = 0; i < ARRAY_SIZE(ioapicregvalues); i++, a++) {
-               l[0] = (a->reg * 2) + 0x10;
-               l[4] = a->value_low;
-               value_low = l[4];
-               l[0] = (a->reg * 2) + 0x11;
-               l[4] = a->value_high;
-               value_high = l[4];
-               if ((i == 0) && (value_low == 0xffffffff)) {
-                       printk_warning("IOAPIC is not responding.\n");
-                       return;
-               }
-               printk_debug("IOAPIC: IRQ reg 0x%08x value 0x%08x 0x%08x\n",
-                            a->reg, a->value_low, a->value_high);
-       }
-}
-#endif
 
 static const unsigned char pci_irqs[4] = { 11, 11, 10, 10 };
 
@@ -147,7 +53,7 @@ static unsigned char *pin_to_irq(const unsigned char *pin)
 
 static void pci_routing_fixup(struct device *dev)
 {
-       printk_debug("%s: device is %p\n", __FUNCTION__, dev);
+       printk(BIOS_DEBUG, "%s: device is %p\n", __FUNCTION__, dev);
 
        /* set up PCI IRQ routing */
        pci_write_config8(dev, 0x55, pci_irqs[0] << 4);
@@ -155,17 +61,17 @@ static void pci_routing_fixup(struct device *dev)
        pci_write_config8(dev, 0x57, pci_irqs[3] << 4);
 
        /* Assigning IRQs */
-       printk_debug("Setting up USB interrupts.\n");
+       printk(BIOS_DEBUG, "Setting up USB interrupts.\n");
        pci_assign_irqs(0, 0x10, pin_to_irq(usb_pins));
 
-       printk_debug("Setting up VGA interrupts.\n");
+       printk(BIOS_DEBUG, "Setting up VGA interrupts.\n");
        pci_assign_irqs(1, 0x00, pin_to_irq(vga_pins));
 
-       printk_debug("Setting up PCI slot interrupts.\n");
+       printk(BIOS_DEBUG, "Setting up PCI slot interrupts.\n");
        pci_assign_irqs(2, 0x04, pin_to_irq(slot_pins));
        // more?
 
-       printk_debug("Setting up AC97 interrupts.\n");
+       printk(BIOS_DEBUG, "Setting up AC97 interrupts.\n");
        pci_assign_irqs(0x80, 0x1, pin_to_irq(ac97_pins));
 }
 
@@ -175,7 +81,7 @@ static void pci_routing_fixup(struct device *dev)
  * can't figure out how to do !!!!
  */
 
-void setup_pm(device_t dev)
+static void setup_pm(device_t dev)
 {
        /* Debounce LID and PWRBTN# Inputs for 16ms. */
        pci_write_config8(dev, 0x80, 0x20);
@@ -260,7 +166,7 @@ static void cx700_set_lpc_registers(struct device *dev)
 {
        unsigned char enables;
 
-       printk_debug("VIA CX700 LPC bridge init\n");
+       printk(BIOS_DEBUG, "VIA CX700 LPC bridge init\n");
 
        // enable the internal I/O decode
        enables = pci_read_config8(dev, 0x6C);
@@ -327,9 +233,9 @@ static void cx700_set_lpc_registers(struct device *dev)
 
 }
 
-void cx700_read_resources(device_t dev)
+static void cx700_read_resources(device_t dev)
 {
-       struct resource *resource;
+       struct resource *res;
 
        /* Make sure we call our childrens set/enable functions - these
         * are not called unless this device has a resource to set.
@@ -337,14 +243,19 @@ void cx700_read_resources(device_t dev)
 
        pci_dev_read_resources(dev);
 
-       resource = new_resource(dev, 1);
-       resource->flags |=
-           IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_IO | IORESOURCE_STORED;
-       resource->size = 2;
-       resource->base = 0x2e;
+       res = new_resource(dev, 1);
+       res->base = 0x0UL;
+       res->size = 0x400UL;
+       res->limit = 0xffffUL;
+       res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
+
+       res = new_resource(dev, 3); /* IOAPIC */
+       res->base = IO_APIC_ADDR;
+       res->size = 0x00001000;
+       res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
 }
 
-void cx700_set_resources(device_t dev)
+static void cx700_set_resources(device_t dev)
 {
        struct resource *resource;
        resource = find_resource(dev, 1);
@@ -352,19 +263,19 @@ void cx700_set_resources(device_t dev)
        pci_dev_set_resources(dev);
 }
 
-void cx700_enable_resources(device_t dev)
+static void cx700_enable_resources(device_t dev)
 {
        /* Enable SuperIO decoding */
        pci_dev_enable_resources(dev);
-       enable_childrens_resources(dev);
 }
 
 static void cx700_lpc_init(struct device *dev)
 {
        cx700_set_lpc_registers(dev);
 
-#ifdef CONFIG_IOAPIC
-       setup_ioapic();
+#if CONFIG_IOAPIC
+#define IO_APIC_ID 2
+       setup_ioapic(IO_APIC_ADDR, IO_APIC_ID);
 #endif
 
        /* Initialize interrupts */
@@ -379,7 +290,7 @@ static void cx700_lpc_init(struct device *dev)
        isa_dma_init();
 
        /* Initialize keyboard controller */
-       init_pc_keyboard(0x60, 0x64, 0);
+       pc_keyboard_init(0);
 }
 
 static struct device_operations cx700_lpc_ops = {