From owner-freebsd-hackers@freebsd.org Tue Aug 23 15:20:20 2016 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 129FFBC3EA3 for ; Tue, 23 Aug 2016 15:20:20 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-it0-x22c.google.com (mail-it0-x22c.google.com [IPv6:2607:f8b0:4001:c0b::22c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D95751468 for ; Tue, 23 Aug 2016 15:20:19 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-it0-x22c.google.com with SMTP id n128so141091967ith.1 for ; Tue, 23 Aug 2016 08:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=f94q9S6SPlBtWs7UcIyfajMLO9SHU35vZY2XfoKv6t4=; b=h+lpFD53gsxn7xCCamS5NHh3FHV1ZEOFVjKE6fUCEWPAWoly+vo+6VrGnwqNlPBl1u lCfC9ThevWPPU7oIpy8b7rpZEQISVGKKXFbucU0o0pOemaGhhwlNAZiujFD72JmVJmgR IPSMwoKQOMeaAWpr0KbFmaUjoXCe9tU4gl91X2AlktrqL6vAoOurLlQ/Kt7YbLD7r8t3 mscIVABEMnvHKI+aIruVMZ6zRVL+6cNEELKYlvh2sEwy1seuYLse1boKieLPcnyLsG5e RDivv9qwmcYYc5sHLx3450CfARIwLhr8Xh0pBru0oDYsxuBxNRc/QoZsh8B3ZUjTHTc+ LG6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-transfer-encoding; bh=f94q9S6SPlBtWs7UcIyfajMLO9SHU35vZY2XfoKv6t4=; b=LdCjbtMdl7/r+tEQviY1CGwdpk76VGtC0OXoIoOWoRqAI0QidqE0NUQIJdO9QsFmBL 3AE3UyQANNJo3uIPF/VP1VBGRFK/Nmigw1671UPy57zw4Z0udHzV0QV/y2iUC6nEsO6D rXCYHHbD1cWx/3mQAQ1Jk7JvUoX1bc+861DKKHRItPISdNs6ZNllLoYz/Mzr4//2jbjh YqnkTlZPlsGq6rnmBzCdAwY6sU5TCRn7ypUPbpm/D5uw2n3EOBeDR8QXqKbpxwm4V8M7 v6P1hDflTMf907UoI7PwakgEDRdPMwocsbQLchc+0mi4deWTuuWXNuMnXjLbehYSI+sO vXzg== X-Gm-Message-State: AEkoousKTTNYQUdFJOfoXlk8SQD6mcwSjR+DdLMAopL+D2mVRmLCigtM9cp6q+uTH6okGL5jvW6Lz7YYH+CFvQ== X-Received: by 10.107.21.134 with SMTP id 128mr29065312iov.59.1471965618978; Tue, 23 Aug 2016 08:20:18 -0700 (PDT) MIME-Version: 1.0 Sender: wlosh@bsdimp.com Received: by 10.36.65.7 with HTTP; Tue, 23 Aug 2016 08:20:18 -0700 (PDT) X-Originating-IP: [69.53.245.200] In-Reply-To: <20A27669-0B16-4199-853F-46D84E876AE9@panasas.com> References: <20A27669-0B16-4199-853F-46D84E876AE9@panasas.com> From: Warner Losh Date: Tue, 23 Aug 2016 09:20:18 -0600 X-Google-Sender-Auth: u06238Fgl_7C8y77XfB79VHDYOA Message-ID: Subject: Re: problem attaching driver at LPC bus To: Ravi Pokala Cc: "freebsd-hackers@freebsd.org" , karu.pruun@gmail.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Aug 2016 15:20:20 -0000 On Tue, Aug 23, 2016 at 9:13 AM, Ravi Pokala 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