problem attaching driver at LPC bus
Warner Losh
imp at bsdimp.com
Tue Aug 23 15:20:20 UTC 2016
On Tue, Aug 23, 2016 at 9:13 AM, Ravi Pokala <rpokala at mac.com> wrote:
> Hi Peeter,
>
> I wrote a driver for a pair of LPC-attached GPIO controllers last year, so this is (somewhat) in my head. In my case, ACPI didn't actually have the correct information for either controller.
>
> For the controller that was embedded in the chipset, I got the address info from the parent ISA bridge. In my case, that involved reading and masking various registers, as defined by the chipset specs. I also got the resource size from the specs. For the standalone controller attached to the LPC bus, I had to do something similar - inb() the address registers, mask accordingly, and set up the resource. During their respective probe()s:
>
> rc = bus_set_resource(dev, SYS_RES_IOPORT, sc->gp_nextrid, XXX_base,
> XXX_RESOURCE_BYTES);
> if (rc != 0) {
> device_printf(dev, " probe failed to setup resource: %d\n", rc);
> return ENXIO;
> }
> /* Because we needed multiple controllers to be connected to the same
> * devnode, increment to ensure they get their own RID
> */
> sc->gp_XXX_ctlr.gpio_ctlr_rid = sc->gp_nextrid;
> sc->gp_nextrid++;
>
>
> Then, during attach():
>
> rid = sc->gp_XXX_ctlr.gpio_ctlr_rid;
> /* Allocate resource setup in probe method */
> res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
> if (res == NULL) {
> /* Failed to allocate I/O space resource */
> device_printf(dev, "Failed to allocate resource for RID %d\n", rid);
> return ENOMEM;
> }
> sc->gp_XXX_ctlr.gpio_ctlr_res = res;
> device_printf(dev, "Attached: %s @ 0x%08lx\n", cfg->gc_desc, rman_get_start(res));
>
> One thing to note is that I was careful about keeping track of the RIDs. Several of the existing drivers in the tree seem to just use 0 indiscriminately, and it works because they only use one resource.
For ISA drivers, RID is just a number, best thought of as an index.
So incrementing here like you've done is the right call.
Warner
More information about the freebsd-hackers
mailing list