From owner-freebsd-hackers@freebsd.org Sun Nov 3 04:23:32 2019 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8E4241A5728 for ; Sun, 3 Nov 2019 04:23:32 +0000 (UTC) (envelope-from gonzo@bluezbox.com) Received: from id.bluezbox.com (id.bluezbox.com [45.55.20.155]) (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 475N8g44rCz4cyk for ; Sun, 3 Nov 2019 04:23:31 +0000 (UTC) (envelope-from gonzo@bluezbox.com) Received: from localhost ([127.0.0.1] helo=id.bluezbox.com) by id.bluezbox.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92 (FreeBSD)) (envelope-from ) id 1iR7QA-000D1F-Jl; Sat, 02 Nov 2019 21:23:23 -0700 Received: (from gonzo@localhost) by id.bluezbox.com (8.15.2/8.15.2/Submit) id xA34NLpn050048; Sat, 2 Nov 2019 21:23:21 -0700 (PDT) (envelope-from gonzo@bluezbox.com) X-Authentication-Warning: id.bluezbox.com: gonzo set sender to gonzo@bluezbox.com using -f Date: Sat, 2 Nov 2019 21:23:21 -0700 From: Oleksandr Tymoshenko To: Milan Obuch Cc: freebsd-hackers@freebsd.org, Oliver Pinter Subject: Re: UART driver as kld - how? Message-ID: <20191103042321.GA49790@bluezbox.com> References: <20191027214209.712d62ca@zeta.dino.sk> <20191027232956.28b11772@zeta.dino.sk> <20191028191005.GA89835@bluezbox.com> <20191028201952.20a92307@zeta.dino.sk> <20191102214100.500ba493@zeta.dino.sk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191102214100.500ba493@zeta.dino.sk> X-Operating-System: FreeBSD/11.2-RELEASE-p10 (amd64) User-Agent: Mutt/1.12.1 (2019-06-15) X-Spam-Level: -- X-Spam-Report: Spam detection software, running on the system "id.bluezbox.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see The administrator of that system for details. Content preview: Milan Obuch (freebsd-hackers@dino.sk) wrote: > On Mon, 28 Oct 2019 20:19:52 +0100 > Milan Obuch wrote: > > [ snip ] > > > Hi, > > > > I found uart_dev_snps.c being somewhat n [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Rspamd-Queue-Id: 475N8g44rCz4cyk X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of gonzo@bluezbox.com designates 45.55.20.155 as permitted sender) smtp.mailfrom=gonzo@bluezbox.com X-Spamd-Result: default: False [-3.49 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; R_SPF_ALLOW(-0.20)[+mx]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; HAS_XAW(0.00)[]; DMARC_NA(0.00)[bluezbox.com]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; IP_SCORE(-2.19)[ip: (-8.62), ipnet: 45.55.0.0/19(-4.19), asn: 14061(1.91), country: US(-0.05)]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; SUBJECT_ENDS_QUESTION(1.00)[]; ASN(0.00)[asn:14061, ipnet:45.55.0.0/19, country:US]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Nov 2019 04:23:32 -0000 Milan Obuch (freebsd-hackers@dino.sk) wrote: > On Mon, 28 Oct 2019 20:19:52 +0100 > Milan Obuch wrote: > > [ snip ] > > > Hi, > > > > I found uart_dev_snps.c being somewhat near what I need. I am trying > > to extract necessary bits from this and other files (what you wrote is > > just one bit), it seems our docs are lacking in this area. > > > > Regards, > > Milan > > > > After studying other uart_dev_xxx.c files I am able to create working > skeleton uart driver. I can compile it, kldload, and get some console > output. Right now, I hit another problem - uart framework is not > documented well, at least no man page is found in share/man directory. > > My probe function is similar to that in uart_dev_snps.c file, > simplified, and I need to know what arguments should uart_bus_probe > function be invoked with. In many device drivers there are mostly > zeros, but this does not work for me. > > Currently I am getting error 6, ENXIO, so I am not correctly attaching > my driver to device. Putting some printf here and there, I found test > at line 508, file uart_core.c, fails - sc->sc_class is null. Question > is, now, where and how should this field in this structure be > initialized... > > I am sure I need docs/description for other functions as well, so if > anybody knows where good uart framework description could be found, > please advice. Or if somebody already has good understanding of it and > could help me with my issues, it wil be greatly appreciated. if you follow uart_dev_snsps.c template, the sc_class is set in probe function: uart_class = (struct uart_class *)ofw_bus_search_compatible(dev, compat_data)->ocd_data; if (uart_class == NULL) return (ENXIO); freq = 0; sc = device_get_softc(dev); sc->ns8250.base.sc_class = uart_class; ocd_data is the second element in your compat_data var: static struct ofw_compat_data compat_data[] = { { "snps,dw-apb-uart", (uintptr_t)&uart_snps_class }, { "marvell,armada-38x-uart", (uintptr_t)&uart_snps_class }, { NULL, (uintptr_t)NULL } }; Every uart_dev_ driver has its own softc structure (device-specific data associated with the device instance): struct uart_pl011_softc, struct snps_softc. uart_core operates with uart_softc. Device-specific softc is supposed to have uart_softc variable as the very first member: struct uart_pl011_softc { struct uart_softc base; uint16_t imsc; /* Interrupt mask */ }; This way it can be converted to uart_softc by a pointer cast. Poor man's OOP so to say. In your case, my guess would be: you either do not set the sc_class member var in probe function or your base var is not the first in the struct. -- gonzo