PERFORCE change 123696 for review
Oleksandr Tymoshenko
gonzo at FreeBSD.org
Wed Jul 18 15:47:11 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=123696
Change 123696 by gonzo at gonzo_jeeves on 2007/07/18 15:46:10
o Slight refactoring, style(9)-ify
Affected files ...
.. //depot/projects/mips2/src/sys/mips/mips32/adm5120/admpci.c#2 edit
Differences ...
==== //depot/projects/mips2/src/sys/mips/mips32/adm5120/admpci.c#2 (text+ko) ====
@@ -87,7 +87,7 @@
#include <dev/pci/pcib_private.h>
#include "pcib_if.h"
-#include <mips/mips32/adm5120/include/adm5120reg.h>
+#include <mips/mips32/adm5120/adm5120reg.h>
#ifdef ADMPCI_DEBUG
int admpci_debug = 1;
@@ -114,8 +114,7 @@
struct admpci_softc {
device_t sc_dev;
- bus_space_tag_t sc_pciio;
- bus_space_tag_t sc_pcimem;
+ bus_space_tag_t sc_st;
/* Access to PCI config registers */
bus_space_handle_t sc_addrh;
@@ -129,16 +128,11 @@
uint32_t sc_io;
};
-static int admpci_found = 0;
-
static int
admpci_probe(device_t dev)
{
- if (!admpci_found)
- return (0);
-
- return (ENXIO);
+ return (0);
}
static int
@@ -147,11 +141,8 @@
int busno = 0;
struct admpci_softc *sc = device_get_softc(dev);
- admpci_found = 1;
sc->sc_dev = dev;
sc->sc_busno = busno;
- sc->sc_pciio = MIPS_BUS_SPACE_IO;
- sc->sc_pcimem = MIPS_BUS_SPACE_MEM;
/* Use KSEG1 to access IO ports for it is uncached */
sc->sc_io = MIPS_PHYS_TO_KSEG1(ADM5120_BASE_PCI_IO);
@@ -178,23 +169,22 @@
rman_manage_region(&sc->sc_irq_rman, 1, 31) != 0)
panic("admpci_attach: failed to set up IRQ rman");
- /* XXXMIPS: FIX THIS UGLINES! */
- sc->sc_addrh = (bus_space_handle_t)
- MIPS_PHYS_TO_KSEG1(ADM5120_BASE_PCI_CONFADDR);
- sc->sc_datah =
- MIPS_PHYS_TO_KSEG1(ADM5120_BASE_PCI_CONFDATA);
+ if (bus_space_map(sc->sc_st, ADM5120_BASE_PCI_CONFADDR, 4, 0,
+ &sc->sc_addrh) != 0) {
+ device_printf(sc->sc_dev, "unable to address space\n");
+ panic("bus_space_map failed");
+ }
+
+ if (bus_space_map(sc->sc_st, ADM5120_BASE_PCI_CONFDATA, 4, 0,
+ &sc->sc_datah) != 0) {
+ device_printf(sc->sc_dev, "unable to address space\n");
+ panic("bus_space_map failed");
+ }
device_add_child(dev, "pci", busno);
return (bus_generic_attach(dev));
}
-static void
-admpci_identify(driver_t *drv, device_t parent)
-{
-
- BUS_ADD_CHILD(parent, 0, "pcib", 0);
-}
-
static int
admpci_maxslots(device_t dev)
{
@@ -206,7 +196,7 @@
admpci_make_addr(int bus, int slot, int func, int reg)
{
- return 0x80000000 | (bus << 16) | (slot << 11) | (func << 8) | reg;
+ return (0x80000000 | (bus << 16) | (slot << 11) | (func << 8) | reg);
}
static uint32_t
@@ -229,8 +219,7 @@
bus_space_write_4(sc->sc_io, sc->sc_addrh, 0, addr);
data = bus_space_read_4(sc->sc_io, sc->sc_datah, 0);
- switch(reg % 4)
- {
+ switch (reg % 4) {
case 3:
shift = 24;
break;
@@ -245,15 +234,14 @@
break;
}
- switch(bytes)
- {
+ switch (bytes) {
case 1:
mask = 0xff;
data = (data >> shift) & mask;
break;
case 2:
mask = 0xffff;
- if(reg % 4 == 0)
+ if (reg % 4 == 0)
data = data & mask;
else
data = (data >> 16) & mask;
@@ -266,7 +254,7 @@
}
ADMPCI_DPRINTF("%s: read 0x%x\n", __func__, data);
- return data;
+ return (data);
}
static void
@@ -278,15 +266,13 @@
uint32_t reg_data;
uint32_t shift, mask;
- KASSERT(bytes == 4, ("%s: bytes is allowed to be 4 only", __func__));
ADMPCI_DPRINTF("%s: sc %p tag (%x, %x, %x) reg %d\n", __func__,
(void *)sc, bus, slot, func, reg);
- if(bytes != 4)
- {
+
+ if (bytes != 4) {
reg_data = admpci_read_config(dev, bus, slot, func, reg, 4);
- switch(reg % 4)
- {
+ switch (reg % 4) {
case 3:
shift = 24;
break;
@@ -301,15 +287,14 @@
break;
}
- switch(bytes)
- {
+ switch (bytes) {
case 1:
mask = 0xff;
data = (reg_data & ~ (mask << shift)) | (data << shift);
break;
case 2:
mask = 0xffff;
- if(reg % 4 == 0)
+ if (reg % 4 == 0)
data = (reg_data & ~mask) | data;
else
data = (reg_data & ~ (mask << shift)) |
@@ -335,16 +320,7 @@
static int
admpci_route_interrupt(device_t pcib, device_t dev, int pin)
{
-#if 0
- int bus;
- int device;
- int func;
- /* struct admpci_softc *sc = device_get_softc(pcib); */
- bus = pci_get_bus(dev);
- device = pci_get_slot(dev);
- func = pci_get_function(dev);
- return (0);
-#endif
+ /* TODO: implement */
return (0);
}
@@ -352,12 +328,13 @@
gt_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
{
struct admpci_softc *sc = device_get_softc(dev);
+
switch (which) {
case PCIB_IVAR_BUS:
*result = sc->sc_busno;
return (0);
-
}
+
return (ENOENT);
}
@@ -379,26 +356,23 @@
u_long start, u_long end, u_long count, u_int flags)
{
+ return (NULL);
+#if 0
struct admpci_softc *sc = device_get_softc(bus);
struct resource *rv = NULL;
struct rman *rm;
- bus_space_tag_t bt = 0;
bus_space_handle_t bh = 0;
- return (NULL);
-
switch (type) {
case SYS_RES_IRQ:
rm = &sc->sc_irq_rman;
break;
case SYS_RES_MEMORY:
rm = &sc->sc_mem_rman;
- bt = sc->sc_pcimem;
bh = sc->sc_mem;
break;
case SYS_RES_IOPORT:
rm = &sc->sc_io_rman;
- bt = sc->sc_pciio;
bh = sc->sc_io;
break;
default:
@@ -412,7 +386,7 @@
if (type != SYS_RES_IRQ) {
bh += (rman_get_start(rv));
- rman_set_bustag(rv, bt);
+ rman_set_bustag(rv, sc->sc_st);
rman_set_bushandle(rv, bh);
if (flags & RF_ACTIVE) {
if (bus_activate_resource(child, type, *rid, rv)) {
@@ -422,6 +396,7 @@
}
}
return (rv);
+#endif
}
static int
@@ -475,20 +450,20 @@
admpci_set_icus(sc);
#endif
- return 0;
+ return (0);
}
static int
admpci_teardown_intr(device_t dev, device_t child, struct resource *res,
void *cookie)
{
+
return (intr_event_remove_handler(cookie));
}
static device_method_t admpci_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, admpci_probe),
- DEVMETHOD(device_identify, admpci_identify),
DEVMETHOD(device_attach, admpci_attach),
DEVMETHOD(device_shutdown, bus_generic_shutdown),
DEVMETHOD(device_suspend, bus_generic_suspend),
@@ -522,4 +497,4 @@
static devclass_t admpci_devclass;
-DRIVER_MODULE(admpci, nexus, admpci_driver, admpci_devclass, 0, 0);
+DRIVER_MODULE(admpci, obio, admpci_driver, admpci_devclass, 0, 0);
More information about the p4-projects
mailing list