UART driver as kld - how?
Oleksandr Tymoshenko
gonzo at bluezbox.com
Mon Oct 28 19:10:16 UTC 2019
Milan Obuch (freebsd-hackers at dino.sk) wrote:
> On Sun, 27 Oct 2019 22:52:10 +0100
> Oliver Pinter <oliver.pinter at hardenedbsd.org> wrote:
>
> > On Sunday, October 27, 2019, Milan Obuch <freebsd-hackers at dino.sk>
> > wrote:
> >
> > > Hi,
> > >
> > > I am trying to create a driver for Xilinx' AXI UART Lite IP core. I
> > > can't find a way to do it as kld module. I started with
> > > uart_dev_cdnc.c, but I can't see how it is hooked into the kernel -
> > > or, better formulated, how can I created kld loadable module. As
> > > Zynq has uart_dev_cdnc driver for its PS UART, all necessary files
> > > are compiled into kernel, but how can I extend those modules tables
> > > to work with new driver too?
> > >
> > > You can ask why I want it this way, if I can put this into kernel...
> > > simply this would make development awkward - every change would mean
> > > recompile everything (or at least relinking kernel) and reboot. With
> > > kld, I can just rebuild the module, reinstall it, unload old/load
> > > new version and test. Other thing is, for any IP core I must first
> > > load hw design into PL part (FPGA bitstream, actually), there is
> > > simply no device without this step performed.
> > >
> > > Did anybody already create something similar? Any help/hint/pointer
> > > appreciated...
> >
> >
> > https://github.com/freebsd/freebsd/tree/master/share/examples/kld
> >
>
> Hi,
>
> my problem is somewhere else - I am able to build kld, load and unload
> it, but in all uart_dev_xxxx.c files I saw there are no attach and
> detach function, so there must be something more to do. On the other
> side, uart_core.o is already present in kernel, but how should I make
> it work with newly loaded module? uart_bus_fdt.o is linked in kernel
> too, and there are attach and detach function, but how can my tables be
> added in list for it?
>From what I see in source code, UART drivers with FDT support are
tied to the UART subsystem using UART_FDT_CLASS_AND_DEVICE macro,
that adds compat data (list of compatible strings for the driver
with pointer to respective uart_class instance) to uart_fdt_class_and_device_set
dataset. This dataset is then traversed by uart_fdt_find_device in
uart_fdt_probe function.
You need:
- Add FDT node to device tree, with unique compatible property value
and "status" property set to "okay"
- In you driver do something like:
static struct ofw_compat_data compat_data[] = {
{"xlnx,axilite", (uintptr_t)&uart_axilite_class},
{NULL, (uintptr_t)NULL},
};
UART_FDT_CLASS_AND_DEVICE(compat_data);
xlnx,axilite in this case is just something I've just made up, you need
to get the value from the vendor's DTS bindings documentation.
--
gonzo
More information about the freebsd-hackers
mailing list