diff --git a/bus/bonito.c b/bus/bonito.c
new file mode 100644
index 000000000..a7a530de1
--- /dev/null
+++ b/bus/bonito.c
@@ -0,0 +1,90 @@
+/* bonito.c - PCI bonito interface. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see .
+ */
+
+#include
+#include
+
+static grub_uint32_t base_win[GRUB_MACHINE_PCI_NUM_WIN];
+static const grub_size_t sizes_win[GRUB_MACHINE_PCI_NUM_WIN] =
+ {GRUB_MACHINE_PCI_WIN1_SIZE, GRUB_MACHINE_PCI_WIN_SIZE,
+ GRUB_MACHINE_PCI_WIN_SIZE};
+/* Usage counters. */
+static int usage_win[GRUB_MACHINE_PCI_NUM_WIN];
+static grub_addr_t addr_win[GRUB_MACHINE_PCI_NUM_WIN] =
+ {GRUB_MACHINE_PCI_WIN1_ADDR, GRUB_MACHINE_PCI_WIN2_ADDR,
+ GRUB_MACHINE_PCI_WIN3_ADDR};
+
+static inline void
+write_bases (void)
+{
+ int i;
+ grub_uint32_t reg = 0;
+ for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++)
+ reg |= (((base_win[i] >> GRUB_MACHINE_PCI_WIN_SHIFT)
+ & GRUB_MACHINE_PCI_WIN_MASK)
+ >> (i * GRUB_MACHINE_PCI_WIN_MASK_SIZE));
+ GRUB_MACHINE_PCI_IO_CTRL_REG = reg;
+}
+
+void *
+grub_pci_device_map_range (grub_pci_device_t dev __attribute__ ((unused)),
+ grub_addr_t base, grub_size_t size)
+{
+ int i;
+ grub_addr_t newbase;
+
+ /* First try already used registers. */
+ for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++)
+ if (usage_win[i] && base_win[i] <= base
+ && base_win[i] + sizes_win[i] > base + size)
+ {
+ usage_win[i]++;
+ return (void *)
+ (addr_win[i] | (base & GRUB_MACHINE_PCI_WIN_OFFSET_MASK));
+ }
+ /* Map new register. */
+ newbase = base & ~GRUB_MACHINE_PCI_WIN_OFFSET_MASK;
+ for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++)
+ if (!usage_win[i] && newbase <= base
+ && newbase + sizes_win[i] > base + size)
+ {
+ usage_win[i]++;
+ base_win[i] = newbase;
+ write_bases ();
+ return (void *)
+ (addr_win[i] | (base & GRUB_MACHINE_PCI_WIN_OFFSET_MASK));
+ }
+ grub_fatal ("Out of PCI windows.");
+}
+
+void
+grub_pci_device_unmap_range (grub_pci_device_t dev __attribute__ ((unused)),
+ void *mem __attribute__ ((unused)),
+ grub_size_t size __attribute__ ((unused)))
+{
+ int i;
+ for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++)
+ if (usage_win[i] && addr_win[i]
+ == (((grub_addr_t) mem) & ~GRUB_MACHINE_PCI_WIN_OFFSET_MASK))
+ {
+ usage_win[i]--;
+ return;
+ }
+ grub_fatal ("Tried to unmap not mapped region");
+}
diff --git a/conf/mips.rmk b/conf/mips.rmk
index f63e9bafc..19ed78237 100644
--- a/conf/mips.rmk
+++ b/conf/mips.rmk
@@ -142,12 +142,6 @@ ata_mod_SOURCES = disk/ata.c
ata_mod_CFLAGS = $(COMMON_CFLAGS)
ata_mod_LDFLAGS = $(COMMON_LDFLAGS)
-# For pci.mod.
-pkglib_MODULES += pci.mod
-pci_mod_SOURCES = bus/pci.c
-pci_mod_CFLAGS = $(COMMON_CFLAGS)
-pci_mod_LDFLAGS = $(COMMON_LDFLAGS)
-
# For lspci.mod
pkglib_MODULES += lspci.mod
lspci_mod_SOURCES = commands/lspci.c
diff --git a/include/grub/mips/io.h b/include/grub/mips/io.h
index b86452c0a..dee76bde5 100644
--- a/include/grub/mips/io.h
+++ b/include/grub/mips/io.h
@@ -26,37 +26,37 @@ typedef grub_addr_t grub_port_t;
static __inline unsigned char
grub_inb (grub_port_t port)
{
- return *(grub_uint8_t *) port;
+ return *(volatile grub_uint8_t *) port;
}
static __inline unsigned short int
grub_inw (grub_port_t port)
{
- return *(grub_uint16_t *) port;
+ return *(volatile grub_uint16_t *) port;
}
static __inline unsigned int
grub_inl (grub_port_t port)
{
- return *(grub_uint32_t *) port;
+ return *(volatile grub_uint32_t *) port;
}
static __inline void
grub_outb (unsigned char value, grub_port_t port)
{
- *(grub_uint8_t *) port = value;
+ *(volatile grub_uint8_t *) port = value;
}
static __inline void
grub_outw (unsigned short int value, grub_port_t port)
{
- *(grub_uint16_t *) port = value;
+ *(volatile grub_uint16_t *) port = value;
}
static __inline void
grub_outl (unsigned int value, grub_port_t port)
{
- *(grub_uint32_t *) port = value;
+ *(volatile grub_uint32_t *) port = value;
}
#endif /* _SYS_IO_H */
diff --git a/include/grub/mips/yeeloong/pci.h b/include/grub/mips/yeeloong/pci.h
index fd6718c63..9970d6ee0 100644
--- a/include/grub/mips/yeeloong/pci.h
+++ b/include/grub/mips/yeeloong/pci.h
@@ -22,50 +22,80 @@
#include
#include
-#define GRUB_MACHINE_PCI_IOSPACE 0xbfe80000
-#define GRUB_MACHINE_PCI_CONTROL_REG (*(grub_uint32_t *) 0xbfe00118)
+#define GRUB_MACHINE_PCI_CONFSPACE 0xbfe80000
+#define GRUB_MACHINE_PCI_CONF_CTRL_REG (*(volatile grub_uint32_t *) 0xbfe00118)
+#define GRUB_MACHINE_PCI_IO_CTRL_REG (*(volatile grub_uint32_t *) 0xbfe00110)
+#define GRUB_MACHINE_PCI_WIN_MASK_SIZE 6
+#define GRUB_MACHINE_PCI_WIN_MASK ((1 << GRUB_MACHINE_PCI_WIN_MASK_SIZE) - 1)
+/* We have 3 PCI windows. */
+#define GRUB_MACHINE_PCI_NUM_WIN 3
+/* Each window is 64MiB. */
+#define GRUB_MACHINE_PCI_WIN_SHIFT 26
+#define GRUB_MACHINE_PCI_WIN_OFFSET_MASK ((1 << GRUB_MACHINE_PCI_WIN_SHIFT) - 1)
+
+#define GRUB_MACHINE_PCI_WIN_SIZE 0x04000000
+/* Graphical acceleration takes 1 MiB away. */
+#define GRUB_MACHINE_PCI_WIN1_SIZE 0x03f00000
+
+#define GRUB_MACHINE_PCI_WIN1_ADDR 0xb0000000
+#define GRUB_MACHINE_PCI_WIN2_ADDR 0xb4000000
+#define GRUB_MACHINE_PCI_WIN3_ADDR 0xb8000000
static inline grub_uint32_t
grub_pci_read (grub_pci_address_t addr)
{
- GRUB_MACHINE_PCI_CONTROL_REG = addr >> 16;
- return *(grub_uint32_t *) (GRUB_MACHINE_PCI_IOSPACE | (addr & 0xffff));
+ GRUB_MACHINE_PCI_CONF_CTRL_REG = addr >> 16;
+ return *(volatile grub_uint32_t *) (GRUB_MACHINE_PCI_CONFSPACE
+ | (addr & 0xffff));
}
static inline grub_uint16_t
grub_pci_read_word (grub_pci_address_t addr)
{
- GRUB_MACHINE_PCI_CONTROL_REG = addr >> 16;
- return *(grub_uint16_t *) (GRUB_MACHINE_PCI_IOSPACE | (addr & 0xffff));
+ GRUB_MACHINE_PCI_CONF_CTRL_REG = addr >> 16;
+ return *(volatile grub_uint16_t *) (GRUB_MACHINE_PCI_CONFSPACE
+ | (addr & 0xffff));
}
static inline grub_uint8_t
grub_pci_read_byte (grub_pci_address_t addr)
{
- GRUB_MACHINE_PCI_CONTROL_REG = addr >> 16;
- return *(grub_uint8_t *) (GRUB_MACHINE_PCI_IOSPACE | (addr & 0xffff));
+ GRUB_MACHINE_PCI_CONF_CTRL_REG = addr >> 16;
+ return *(volatile grub_uint8_t *) (GRUB_MACHINE_PCI_CONFSPACE
+ | (addr & 0xffff));
}
static inline void
grub_pci_write (grub_pci_address_t addr, grub_uint32_t data)
{
- GRUB_MACHINE_PCI_CONTROL_REG = addr >> 16;
- *(grub_uint32_t *) (GRUB_MACHINE_PCI_IOSPACE | (addr & 0xffff)) = data;
+ GRUB_MACHINE_PCI_CONF_CTRL_REG = addr >> 16;
+ *(volatile grub_uint32_t *) (GRUB_MACHINE_PCI_CONFSPACE
+ | (addr & 0xffff)) = data;
}
static inline void
grub_pci_write_word (grub_pci_address_t addr, grub_uint16_t data)
{
- GRUB_MACHINE_PCI_CONTROL_REG = addr >> 16;
- *(grub_uint16_t *) (GRUB_MACHINE_PCI_IOSPACE | (addr & 0xffff)) = data;
+ GRUB_MACHINE_PCI_CONF_CTRL_REG = addr >> 16;
+ *(volatile grub_uint16_t *) (GRUB_MACHINE_PCI_CONFSPACE
+ | (addr & 0xffff)) = data;
}
static inline void
grub_pci_write_byte (grub_pci_address_t addr, grub_uint8_t data)
{
- GRUB_MACHINE_PCI_CONTROL_REG = addr >> 16;
- *(grub_uint8_t *) (GRUB_MACHINE_PCI_IOSPACE | (addr & 0xffff)) = data;
+ GRUB_MACHINE_PCI_CONF_CTRL_REG = addr >> 16;
+ *(volatile grub_uint8_t *) (GRUB_MACHINE_PCI_CONFSPACE
+ | (addr & 0xffff)) = data;
}
+void *
+grub_pci_device_map_range (grub_pci_device_t dev __attribute__ ((unused)),
+ grub_addr_t base, grub_size_t size);
+void
+grub_pci_device_unmap_range (grub_pci_device_t dev __attribute__ ((unused)),
+ void *mem,
+ grub_size_t size __attribute__ ((unused)));
+
#endif /* GRUB_MACHINE_PCI_H */