Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Mar 2011 19:49:31 +0100
From:      Henrik Brix Andersen <brix@freebsd.org>
To:        freebsd-drivers@freebsd.org
Subject:   Allocating resources to isab children
Message-ID:  <3550EA55-ADDE-40AC-9C22-1FAC441A0BC8@freebsd.org>

next in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--Apple-Mail-8--473975120
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=us-ascii

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@pci0:0:15:0:	class=3D0x060100 card=3D0x20901022 =
chip=3D0x20901022 rev=3D0x03 hdr=3D0x00
    vendor     =3D 'Advanced Micro Devices (AMD)'
    device     =3D 'CS5536 [Geode companion] ISA'
    class      =3D bridge
    subclass   =3D PCI-ISA
    bar   [10] =3D type I/O Port, range 32, base 0x6000, size  8, =
enabled
    bar   [14] =3D type I/O Port, range 32, base 0x6100, size 256, =
enabled
    bar   [18] =3D type I/O Port, range 32, base 0x6200, size 64, =
enabled
    bar   [20] =3D type I/O Port, range 32, base 0x9d00, size 128, =
enabled
    bar   [24] =3D 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) !=3D NULL)
		return;

	if (pci_get_devid(parent) =3D=3D AMD_GEODE_CS5536_DEV_ID) {
		if (device_add_child(parent, driver->name, -1) =3D=3D =
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 =3D 0;
	sc =3D device_get_softc(dev);
	sc->dev =3D dev;

	sc->rid =3D PCIR_BAR(1);
	sc->res =3D bus_alloc_resource_any(dev, SYS_RES_IOPORT, =
&sc->rid,
					 RF_ACTIVE);

	if (sc->res =3D=3D NULL) {
		device_printf(dev, "could not allocate I/O port\n");
		err =3D 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 =3D device_get_softc(dev);
        int err;

	err =3D bus_generic_detach(dev);
	if (sc->res !=3D NULL)
		bus_release_resource(dev, SYS_RES_IOPORT, sc->rid, =
sc->res);

        return (err);
}

static device_method_t test_methods[] =3D {
	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 =3D {
	"test",
	test_methods,
	sizeof(struct test_softc),
};

static devclass_t test_devclass;

DRIVER_MODULE(test, isab, test_driver, test_devclass, 0, 0);

--=20
Henrik Brix Andersen <brix@FreeBSD.org>




--Apple-Mail-8--473975120
content-type: application/pgp-signature; x-mac-type=70674453;
	name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)

iEYEARECAAYFAk17wDwACgkQv+Q4flTiePicZgCgof8J5jeXvHGnCRjYCEYWCE7V
92EAniR3QgxC/6Q5nHdtIr4JxISZo/MP
=V5jy
-----END PGP SIGNATURE-----

--Apple-Mail-8--473975120--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3550EA55-ADDE-40AC-9C22-1FAC441A0BC8>