Allocating resources to isab children
Henrik Brix Andersen
brix at freebsd.org
Sat Mar 12 19:07:44 UTC 2011
Hi,
I am writing a driver for the GPIO part of the AMD CS5536 south bridge (isab0), but have encountered a problem with resource allocation.
The GPIO address (0x6100-0x61FF) is available through PCI BAR 1 as seen in the output from pciconf(8):
isab0 at pci0:0:15:0: class=0x060100 card=0x20901022 chip=0x20901022 rev=0x03 hdr=0x00
vendor = 'Advanced Micro Devices (AMD)'
device = 'CS5536 [Geode companion] ISA'
class = bridge
subclass = PCI-ISA
bar [10] = type I/O Port, range 32, base 0x6000, size 8, enabled
bar [14] = type I/O Port, range 32, base 0x6100, size 256, enabled
bar [18] = type I/O Port, range 32, base 0x6200, size 64, enabled
bar [20] = type I/O Port, range 32, base 0x9d00, size 128, enabled
bar [24] = type I/O Port, range 32, base 0x9c00, size 64, enabled
However, when I try to allocate the I/O port resource in the minimalistic example below, I always get 0x1100-0x1100, not 0x6100-0x61FF?
I have modelled the code after recommendation from John Baldwin in http://lists.freebsd.org/pipermail/freebsd-acpi/2007-August/003964.html but I must be doing something wrong...
Brix
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <machine/bus.h>
#include <sys/rman.h>
#include <machine/resource.h>
#define AMD_GEODE_CS5536_DEV_ID 0x20901022
struct test_softc {
device_t dev;
int rid;
struct resource *res;
};
static void
test_identify(driver_t *driver, device_t parent)
{
if (device_find_child(parent, driver->name, -1) != NULL)
return;
if (pci_get_devid(parent) == AMD_GEODE_CS5536_DEV_ID) {
if (device_add_child(parent, driver->name, -1) == NULL)
device_printf(parent, "could not add child\n");
}
}
static int
test_probe(device_t dev)
{
device_set_desc(dev, "Test driver");
return (BUS_PROBE_DEFAULT);
}
static int
test_attach(device_t dev)
{
struct test_softc *sc;
int err;
err = 0;
sc = device_get_softc(dev);
sc->dev = dev;
sc->rid = PCIR_BAR(1);
sc->res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &sc->rid,
RF_ACTIVE);
if (sc->res == NULL) {
device_printf(dev, "could not allocate I/O port\n");
err = ENXIO;
goto out;
}
/* prints out 0x1100-0x1100 - not 0x6100-0x61FF as expected */
printf("allocated: 0x%lx-0x%lx\n", rman_get_start(sc->res),
rman_get_end(sc->res));
out:
return (err);
}
static int
test_detach(device_t dev)
{
struct test_softc *sc = device_get_softc(dev);
int err;
err = bus_generic_detach(dev);
if (sc->res != NULL)
bus_release_resource(dev, SYS_RES_IOPORT, sc->rid, sc->res);
return (err);
}
static device_method_t test_methods[] = {
DEVMETHOD(device_identify, test_identify),
DEVMETHOD(device_probe, test_probe),
DEVMETHOD(device_attach, test_attach),
DEVMETHOD(device_detach, test_detach),
{ 0, 0 }
};
static driver_t test_driver = {
"test",
test_methods,
sizeof(struct test_softc),
};
static devclass_t test_devclass;
DRIVER_MODULE(test, isab, test_driver, test_devclass, 0, 0);
--
Henrik Brix Andersen <brix at FreeBSD.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 194 bytes
Desc: This is a digitally signed message part
Url : http://lists.freebsd.org/pipermail/freebsd-drivers/attachments/20110312/f88979d1/PGP-0001.pgp
More information about the freebsd-drivers
mailing list