Date: Tue, 23 Aug 2016 09:20:18 -0600 From: Warner Losh <imp@bsdimp.com> To: Ravi Pokala <rpokala@mac.com> Cc: "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>, karu.pruun@gmail.com Subject: Re: problem attaching driver at LPC bus Message-ID: <CANCZdfpzvvsA8JTLiKZAjyWjifFMzJN3KZ76HWW=%2BYnH326w3w@mail.gmail.com> In-Reply-To: <20A27669-0B16-4199-853F-46D84E876AE9@panasas.com> References: <20A27669-0B16-4199-853F-46D84E876AE9@panasas.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Aug 23, 2016 at 9:13 AM, Ravi Pokala <rpokala@mac.com> wrote: > Hi Peeter, > > I wrote a driver for a pair of LPC-attached GPIO controllers last year, s= o 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 in= fo from the parent ISA bridge. In my case, that involved reading and maskin= g various registers, as defined by the chipset specs. I also got the resour= ce size from the specs. For the standalone controller attached to the LPC b= us, I had to do something similar - inb() the address registers, mask accor= dingly, and set up the resource. During their respective probe()s: > > rc =3D bus_set_resource(dev, SYS_RES_IOPORT, sc->gp_nextrid, XXX_= base, > XXX_RESOURCE_BYTES); > if (rc !=3D 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 =3D sc->gp_nextrid; > sc->gp_nextrid++; > > > Then, during attach(): > > rid =3D sc->gp_XXX_ctlr.gpio_ctlr_rid; > /* Allocate resource setup in probe method */ > res =3D bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTI= VE); > if (res =3D=3D 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 =3D 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 indiscrimina= tely, 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfpzvvsA8JTLiKZAjyWjifFMzJN3KZ76HWW=%2BYnH326w3w>