From: Greg KH <greg@kroah.com>
To: Luca Ceresoli <luca@lucaceresoli.net>
Cc: kernelnewbies@kernelnewbies.org
Subject: Re: Remote I/O bus
Date: Fri, 4 Oct 2019 16:54:35 +0200 [thread overview]
Message-ID: <20191004145435.GA758347@kroah.com> (raw)
In-Reply-To: <9f619831-f27e-447e-42ea-69227f7a31d0@lucaceresoli.net>
On Fri, Oct 04, 2019 at 04:08:06PM +0200, Luca Ceresoli wrote:
> Hi Greg,
>
> On 04/10/19 15:22, Greg KH wrote:
> > On Fri, Oct 04, 2019 at 01:04:56PM +0200, Luca Ceresoli wrote:
> >> Hi,
> >>
> >> on an embedded system I currently have a standard platform device:
> >>
> >> .-----. data .--------.
> >> | CPU |--------| DEVICE |
> >> '-----' bus '--------'
> >>
> >> The driver is a standard platform driver that uses ioread32() and
> >> iowrite32() to access registers.
> >>
> >> So far, so good.
> >>
> >> Now in a new design I have the same device in an FPGA, external to the
> >> SoC. The external FPGA is not reachable via an I/O bus, but via SPI (or
> >> I2C). A microprocessor in the FPGA acts as a bridge: as an SPI client it
> >> receives register read/write requests from the CPU, forwards them to the
> >> devices on the in-FPGA data bus as a master, then sends back the replies
> >> over SPI.
> >>
> >> SoC <- | -> FPGA
> >>
> >> .-----. data .---------. .--------. data .--------.
> >> | CPU |---------| SPI CTL |-------| BRIDGE |---------| DEVICE |
> >> '-----' bus A '---------' SPI '--------' bus B '--------'
> >>
> >>
> >> What would be a proper way to model this in the Linux kernel?
> >>
> >> Of course I can hack the drivers to hijack them on SPI, but I'm trying
> >> to solve the problem in a better way. IMO "a proper way" implies that
> >> the platform driver does not need to be aware of the existence of the
> >> bridge.
> >>
> >> Note: in the real case there is more than one device to handle.
> >>
> >> At first sight I think this should be modeled with a "bridge" device that:
> >>
> >> * is a SPI device
> >> * implements a "platform bus" where regular platform devices can be
> >> instantiated, similar to a "simple-bus"
> >
> > Yes, make your own "bus", and have the SPI device be your "host
> > controller" in that it bridges the SPI bus to your "FPGA bus".
> >
> > The driver model is set up for this, it should be not that complex to do
> > so. If you have specific questions, just let me know. "Clean" examples
> > of what to do is the greybus code as that's probably one of the newest
> > busses to be added to the kernel.
> >
> >> In device tree terms:
> >>
> >> &amba { /* data bus A in picture */
> >>
> >> spi0: spi@42000000 {
> >> reg = <0x42000000 0x1000>;
> >> #address-cells = <1>;
> >>
> >> io-over-spi-bridge@1 { /* data bus B */
> >> reg = <1>; /* slave select pin 1 */
> >> compatible = "linux,io-over-spi-bridge";
> >> #address-cells = <1>;
> >> #size-cells = <1>;
> >>
> >> mydevice@4000 {
> >> /* 1 kB I/O space at 0x4000 on bus B */
> >> reg = <0x4000 0x1000>;
> >> };
> >> };
> >> };
> >> };
> >>
> >> The io-over-spi driver is supposed to request allocation of a virtual
> >> memory area that:
> >> 1. is as large as the address space on bus B
> >> 2. is __iomem (non cached, etc)
> >> 3. is not mapped on the physical CPU address space (bus A)
> >> 4. page faults at every read/write access, triggering a callback
> >> that starts an SPI transaction, waits for the result and returns
> >
> > I don't think you can map memory to be "on an SPI bus", unless you have
> > support for that in your hardware controller itself. Trying to map
> > memory in this way is odd, just treat the devices out off the bus as
> > "devices that need messages sent to them", and you should be fine. It's
> > not memory-mapped iomemory, so don't think of it that way.
>
> If I got you correctly, this means I cannot reuse the existing device
> drivers unmodified as I was hoping to.
You are switching from a "ioread/write" to "all data goes across an SPI
link". No, you can't reuse the existing drivers, but you can modify
them to abstract out the "read/write data" functions to be transport
agnositic.
> They won't be 'struct platform_device' instances anymore, they will
> become 'struct mybus_device' instances. And as such they won't be
> allowed to call ioread32() / iowrite32(), but will have to call
> mybus_ioread32() and mybus_iowrite32(). Correct?
Yes.
But, if you do it right, the majority of your driver is the logic to
control the hardware, and interact with whatever other subsystem those
devices talk to. Read/Write data and the bus the device talks to should
just be a tiny shim that you can split out into a separate module/file.
Do you have a pointer to your existing code anywhere?
thanks,
greg k-h
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
next prev parent reply other threads:[~2019-10-04 14:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-04 11:04 Remote I/O bus Luca Ceresoli
2019-10-04 13:22 ` Greg KH
2019-10-04 14:08 ` Luca Ceresoli
2019-10-04 14:54 ` Greg KH [this message]
2019-10-04 15:08 ` Luca Ceresoli
2019-10-04 21:51 ` Valdis Klētnieks
2019-10-05 22:29 ` Luca Ceresoli
2019-10-06 0:19 ` Valdis Klētnieks
2019-10-06 9:18 ` Greg KH
2019-10-07 7:48 ` Luca Ceresoli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191004145435.GA758347@kroah.com \
--to=greg@kroah.com \
--cc=kernelnewbies@kernelnewbies.org \
--cc=luca@lucaceresoli.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).