From owner-freebsd-current@freebsd.org Mon Dec 10 18:26:42 2018 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7562E132F9F9 for ; Mon, 10 Dec 2018 18:26:42 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DDFA486EFD for ; Mon, 10 Dec 2018 18:26:41 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from John-Baldwins-MacBook-Pro-2.local (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id B57BF10B476; Mon, 10 Dec 2018 13:26:39 -0500 (EST) Subject: Re: Composite PCI devices in FreeBSD (mfd in Linux) To: Anthony Jenkins , FreeBSD CURRENT References: Cc: Gleb Popov <6yearold@gmail.com> From: John Baldwin Openpgp: preference=signencrypt Autocrypt: addr=jhb@FreeBSD.org; keydata= xsDiBETQ+XcRBADMFybiq69u+fJRy/0wzqTNS8jFfWaBTs5/OfcV7wWezVmf9sgwn8TW0Dk0 c9MBl0pz+H01dA2ZSGZ5fXlmFIsee1WEzqeJzpiwd/pejPgSzXB9ijbLHZ2/E0jhGBcVy5Yo /Tw5+U/+laeYKu2xb0XPvM0zMNls1ah5OnP9a6Ql6wCgupaoMySb7DXm2LHD1Z9jTsHcAQMD /1jzh2BoHriy/Q2s4KzzjVp/mQO5DSm2z14BvbQRcXU48oAosHA1u3Wrov6LfPY+0U1tG47X 1BGfnQH+rNAaH0livoSBQ0IPI/8WfIW7ub4qV6HYwWKVqkDkqwcpmGNDbz3gfaDht6nsie5Z pcuCcul4M9CW7Md6zzyvktjnbz61BADGDCopfZC4of0Z3Ka0u8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8AJ9j1dWVQWxw/YdTbEyrRKOY8YZN wwCfafMAg8QvmOWnHx3wl8WslCaXaE8= Message-ID: Date: Mon, 10 Dec 2018 10:26:38 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.4.3 (mail.baldwin.cx); Mon, 10 Dec 2018 13:26:40 -0500 (EST) X-Virus-Scanned: clamav-milter 0.99.2 at mail.baldwin.cx X-Virus-Status: Clean X-Rspamd-Queue-Id: DDFA486EFD X-Spamd-Result: default: False [-2.99 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.99)[-0.992,0]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Dec 2018 18:26:42 -0000 On 12/10/18 9:00 AM, Anthony Jenkins wrote: > Hi all, > > I'm trying to port an Intel PCI I2C controller from Linux to FreeBSD.  > Linux represents this device as an MFD (multi-function device), meaning > it has these "sub-devices" that can be handed off to other drivers to > actually attach devices to the system.  The Linux "super" PCI device is > the intel-lpss-pci.c, and the "sub" device is i2c-designware-platdrv.c, > which represents the DesignWare driver's "platform" attachment to the > Linux system.  FreeBSD also has a DesignWare I2C controller driver, > ig4(4), but it only has PCI and ACPI bus attachment implementations. > > I have a port of the Linux intel-lpss driver to FreeBSD, but now I'm > trying to figure out the best way to give FreeBSD's ig4(4) driver access > to my lpss(4) device.  I'm thinking I could add an ig4_lpss.c describing > the "attachment" of an ig4(4) to an lpss(4).  Its probe() method would > scan the "lpss" devclass for devices, and its attach() method would > attach itself as a child to the lpss device and "grab" the portion of > PCI memory and the IRQ that the lpss PCI device got. > > Is this the "FreeBSD Way (TM)" of handling this type of device?  If not, > can you recommend an existing FreeBSD driver I can model my code after? > If my approach is acceptable, how do I fully describe the ig4(4) > device's attachment to the system?  Is simply making it a child of > lpss(4) sufficient?  It's "kind of" a PCI device (it is controlled via > access to a PCI memory region and an IRQ), but it's a sub-device of an > actual PCI device (lpss(4)) attached to PCI. > How would my ig4_lpss attachment get information from the lpss(4) driver > about what it probed? There are some existing PCI drivers that act as "virtual" busses that attach child devices. For example, vga_pci.c can have drm, agp, and acpi_video child devices. There are also some SMBus drivers that are also PCI-ISA bridges and thus create separate child devices. For a virtual bus like this, you need to figure out how your child devices will be enumerated. A simple way is to let child devices use an identify routine that looks at each parent device and decides if a child device for that driver makes sense. It can then add a child device in the identify routine. To handle things like resources, you want to have bus_*_resource methods that let your child device use the normal bus_* functions to allocate resources. At the simplest end you don't need to permit any sharing of BARs among multiple children so you can just proxy the requests in the "real" PCI driver. (vga_pci.c does this) If you need the BARs to be shared you have a couple of options such as just using a refcount on the BAR resource but letting multiple devices allocate the same BAR. If you want to enforce exclusivity (once a device allocates part of a BAR then other children shouldn't be permitted to do so), then you will need a more complicated solution. Hopefully that gives you a starting point? -- John Baldwin