Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Aug 2016 08:13:53 -0700
From:      Ravi Pokala <rpokala@mac.com>
To:        "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>, karu.pruun@gmail.com
Subject:   Re: problem attaching driver at LPC bus
Message-ID:  <20A27669-0B16-4199-853F-46D84E876AE9@panasas.com>

next in thread | raw e-mail | index | archive | help
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.

Hope that helps,

Ravi (rpokala@)

-----Original Message-----
Reply-To: "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>
Date: Mon, 22 Aug 2016 16:51:03 +0300
From: "karu.pruun" <karu.pruun@gmail.com>
To: freebsd-hackers@freebsd.org	
Subject: problem attaching driver at LPC bus
Message-ID:	
	<CADdF=MJY4OGEXJCo60NoxTZAVkN74TpyLTUYWpbcG4XnPm1aEg@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

> Hello
> 
> I am trying to write a small driver for a device (gmux) attached to the LPC
> bus, but am stuck with allocation of I/O ports. The device shows as
> follows:
> 
> ---
> devinfo -rv | grep GMUX:
> 
> unknown pnpinfo _HID=APP000B _UID=0 at handle=\_SB_.PCI0.LPCB.GMUX
> ---
> 
> I took cue from sys/dev/acpica/acpi_ec.c. Probing works fine with
> ACPI_ID_PROBE in analogy to acpi_ec.c:
> 
> --- ---
> sys/dev/acpica/acpi_ec.c:
> ---
> 
> acpi_ec_probe(. . .)
> {
>     . . .
> 
>     ACPI_ID_PROBE(device_get_parent(dev), dev, ec_ids)
> 
>     . . .
> }
> --- ---
> 
> Then attach() calls bus_alloc_resource():
> 
> --- ---
> sys/dev/acpica/acpi_ec.c:
> ---
> 
> acpi_ec_attach(. . .)
> {
>     struct resource *res;
>     . . .
> 
>     res = bus_alloc_resource_any(sc->ec_dev, SYS_RES_IOPORT,
> &sc->ec_data_rid, RF_ACTIVE);
> 
>     . . .
> }
> --- ---
> 
> But this fails for my driver, res is always NULL. I looked up acpi tables
> (acpidump -td), the IO resources for GMUX are there:
> 
> --- ---
>     Scope (\_SB.PCI0.LPCB)
>     {
>         Device (GMUX)
>         {
>             Name (_HID, EisaId ("APP000B"))  // _HID: Hardware ID
>             Name (_CID, "gmux")  // _CID: Compatible ID
>             Name (_STA, 0x0B)  // _STA: Status
>             Name (_CRS, ResourceTemplate ()  // _CRS: Current Resource
> Settings
>             {
>                 IO (Decode16,
>                     0x0700,             // Range Minimum
>                     0x07FF,             // Range Maximum
>                     0x01,               // Alignment
>                     0xFF,               // Length
>                     )
>             })
> --- ---
> 
> Could someone explain where I have gone wrong?
> 
> Thank you
> 
> Peeter





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20A27669-0B16-4199-853F-46D84E876AE9>