From owner-freebsd-hackers@freebsd.org Sun Sep 9 09:23:07 2018 Return-Path: Delivered-To: freebsd-hackers@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 E9A8F108FE80 for ; Sun, 9 Sep 2018 09:23:06 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 688D38CF09 for ; Sun, 9 Sep 2018 09:23:06 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id w899Mtqo033323 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 9 Sep 2018 12:22:58 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua w899Mtqo033323 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id w899MtZA033322; Sun, 9 Sep 2018 12:22:55 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 9 Sep 2018 12:22:55 +0300 From: Konstantin Belousov To: Yuri Pankov Cc: freebsd-hackers Subject: Re: acpi, pci, spibus -- tying it all together Message-ID: <20180909092255.GM3161@kib.kiev.ua> References: <30e41db8-a56d-e916-0490-7e184063a811@yuripv.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <30e41db8-a56d-e916-0490-7e184063a811@yuripv.net> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Sep 2018 09:23:07 -0000 On Sun, Sep 09, 2018 at 10:25:44AM +0300, Yuri Pankov wrote: > I have modified intelspi to attach to SPI master (Sunrise Point-H Serial > IO SPI) located on pci bus, and on attach I have the spibus0 and spibus1 > buses added. > > As spibus is not self-enumerating, the only way to find the slave device > I need is via acpi bus probe, that works, but I don't see a way to make > it a child of spibus1 (where it's located). > > In ACPI terms it looks like the below (from DSDT): > > ... > \_SB_.PCI0.SPI0 "Device (SPI0)" > \_SB_.PCI0.SPI1 "Device (SPI1)" > ... > Scope (SPI1) { > Device (SPIT) { > ...here comes all the data we need, > including the ACPI ID we can probe... > } > } > ... > > I hope that made at least some sense. And the question is if there any > existing way of tying it all together, and adding that slave device to > the spibus1 (which only knows about hinted children at the moment)? I had very similar situation where I wrote NVDIMM driver. The suggestion I got was to implement DEVICE_IDENTIFY() method. It gets the driver_t and the parent bus device_t arguments. In the method, you create children' device_t, iterating over the ACPI enumerated entries. Practically, you would use acpica AcpiWalkNamespace(ACPI_TYPE_DEVICE, ...) function and call BUS_ADD_CHILD() when needed. Set the ACPI handle for the created child. [Get the Intel' ACPICA reference manual to understand the KPI]. Then probe does nothing, and attach verifies against the handle. You can see that in https://kib.kiev.ua/kib/nvdimm.7.patch nvdimm_identify(), nvdimm_foreach_acpi(), and nvdimm_create_dev().