devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
To: One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>
Cc: atull <atull@opensource.altera.com>,
	gregkh@linuxfoundation.org, Pavel Machek <pavel@denx.de>,
	hpa@zytor.com, monstr@monstr.eu, michal.simek@xilinx.com,
	rdunlap@infradead.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org, pantelis.antoniou@konsulko.com,
	robh+dt@kernel.org, grant.likely@linaro.org,
	iws@ovro.caltech.edu, linux-doc@vger.kernel.org,
	broonie@kernel.org, philip@balister.org, rubini@gnudd.com,
	s.trumtrar@pengutronix.de, jason@lakedaemon.net,
	kyle.teske@ni.com, nico@linaro.org, balbi@ti.com,
	m.chehab@samsung.com, davidb@codeaurora.org, rob@landley.net,
	davem@davemloft.net, cesarb@cesarb.net, sameo@linux.intel.com,
	akpm@linux-foundation.org, linus.walleij@linaro.org,
	pawel.moll@arm.com, mark.rutland@arm.com,
	ijc+devicetree@hellion.org.uk, galak@codeaurora.org,
	devel@driverdev.osuosl.org, delicious.quinoa@gmail.com,
	dinguyen@opensource.altera.com, yv
Subject: Re: [PATCH v8 2/4] fpga manager: add sysfs interface document
Date: Thu, 15 Jan 2015 14:42:30 -0700	[thread overview]
Message-ID: <20150115214230.GD23247@obsidianresearch.com> (raw)
In-Reply-To: <20150115204502.591bca1d@lxorguk.ukuu.org.uk>

On Thu, Jan 15, 2015 at 08:45:02PM +0000, One Thousand Gnomes wrote:

> > - Hand over to a DT overlay (how does this work?) Lock transfers
> >   from FD to kernel
> 
> That bit isn't stateful so I would actually have expected something in
> the kernel ABI along the lines of 
> 
>            request_fpga(blah)
> 
> which does
> 
>              if in use by user
>                     EBUSY
>              lock it (all user opens will fail)
> 
> and
> 
>             release_fpga(blah)

I am imagining two ways to start a kernel FPGA, the in-kernel method
triggered by a DT node:

  fpga = request_and_lock_fpga(of_get_fpga_controller(dev->of_node))
  fw = request_firmat(of_get_fpga_firmware(dev->of_node));
  fpga_program_fw(fpga, fw);

  for_each_child_of_node(dev->of_node, child)
    .. of_platform_bus_probe(child ... ) ..

  .. somehow fpga and its lock transfer to dev->of_node ..

The problem with this is it assumes the FPGA is ready to go
immediately after fpga_program_fw. There are a few platforms that can
manage this, but many others require at least some kind of startup
sequence - eg wait for clocking PLLs to lock, do low level setup, etc.

For very common cases (like Zynq can have a pretty common setup scheme
for the PL side) the DT binding can guide the kernel to run the right
code, and the code can live in the kernel because it is simple and
broadly useful.

For wild cases I'd like to just punt the setup code to user space. It
is safer and simpler to run that complexity in a user process than in
the kernel.

Maybe there is a better way to handle this, but I have been under the
impression that these days it is frowned on for the kernel to wait for
userspace?

So my idea is to use the user space method to also load a 'kernel'
fpga, the process follows the kernel flow:

   fd = open("/dev/fpga0"); // request_and_lock_fpga

   ioctl(fd,START_PROGRAMMING); // fpga_program_fw
   write(fd,fw,fw_size);
   
   // Arbitary complexity here
   userspace_setup_fpga();

   icotl(fd,BIND_DT_OVERLAY, .. ?? ..) // for_each_child_of_node

This is what the state is about, if the setup fails I expect the
kernel to go and unlock and deprogram the FPGA if fd is closed. Only a
success on BIND_DT_OVERLAY will make the FPGA permanent beyond closing
fd.

Pantelis: I think this explains why a fd and ioctls. configfs, sysfs,
etc lack the FD context to do the cleanup. 

Essentially, I think a running FPGA should always be attached to some
context that is the user - either the user is in-kernel (a DT of_node)
or the user is in userspace (the fd).

The invarient is - if there is no user then the kernel automatically
makes the FPGA deprogrammed.

Having a device that is potentially attached to the CPU bus running
'rouge' is dangerous. We can't realistically deprogram it safely if we
don't know what it is doing. Eg deprogramming in the middle of a DMA
operation between the CPU and FPGA will often crash the entire system.

The only way to provide reasonable safe guards is to have a clear
chain of ownership. When the kernel takes ownership of the FPGA it
also takes ownership of any cleanup required prior to deprogram.

Jason

  parent reply	other threads:[~2015-01-15 21:42 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-06 20:13 [PATCH v8 0/4] FPGA Manager Framework atull
2015-01-06 20:13 ` [PATCH v8 1/4] doc: add bindings document for altera fpga manager atull
2015-01-06 22:05   ` Rob Herring
2015-01-06 22:34     ` atull
2015-01-09 15:50       ` Rob Herring
     [not found]         ` <CAL_Jsq+pn5MW6veUivEL49FLSQxZOWRq0gU9Q6iD5jzurKK3rQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-09 18:58           ` atull
2015-01-06 20:13 ` [PATCH v8 2/4] fpga manager: add sysfs interface document atull
2015-01-07  8:48   ` Pavel Machek
2015-01-09 19:14     ` atull
2015-01-09 20:56       ` Pavel Machek
2015-01-10  8:10         ` Pantelis Antoniou
2015-01-10 15:11           ` Pavel Machek
2015-01-11 16:29             ` atull
2015-01-12  8:45               ` Pavel Machek
2015-01-12 13:48                 ` Michal Simek
2015-01-13  7:28                   ` Pavel Machek
2015-01-13  7:40                     ` Pantelis Antoniou
2015-01-13  7:56                       ` Pavel Machek
2015-01-13 17:27                         ` atull
2015-01-12 16:05               ` Rob Herring
2015-01-12 16:26                 ` Mark Brown
2015-01-12 18:06               ` Jason Gunthorpe
2015-01-13 16:21                 ` One Thousand Gnomes
2015-01-15 21:52                   ` Pavel Machek
2015-01-12 21:01         ` One Thousand Gnomes
2015-01-12 21:43           ` Jason Gunthorpe
2015-01-13 16:28             ` One Thousand Gnomes
2015-01-13 17:26               ` Pantelis Antoniou
2015-01-13 19:44                 ` atull
2015-01-14 15:58                 ` One Thousand Gnomes
2015-01-13 20:00               ` Jason Gunthorpe
2015-01-13 21:37                 ` atull
2015-01-13 22:24                   ` Jason Gunthorpe
2015-01-14 16:06                     ` One Thousand Gnomes
2015-01-14 18:12                       ` Jason Gunthorpe
2015-01-14 19:01                         ` Pantelis Antoniou
2015-01-15 11:36                         ` One Thousand Gnomes
2015-01-15 11:44                           ` Mark Brown
2015-01-15 16:34                     ` atull
2015-01-15 18:47                       ` Jason Gunthorpe
2015-01-15 20:45                         ` One Thousand Gnomes
2015-01-15 20:54                           ` Pantelis Antoniou
2015-01-21 16:01                             ` One Thousand Gnomes
     [not found]                               ` <20150121160151.453ba403-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2015-01-21 16:33                                 ` Pantelis Antoniou
     [not found]                                   ` <D466D9FF-25DA-4765-9469-128733BEBC4D-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
2015-01-21 20:27                                     ` Jason Gunthorpe
2015-01-21 20:32                                       ` Pantelis Antoniou
2015-02-15 22:40                                       ` Pavel Machek
2015-02-17 17:07                                         ` Rob Landley
2015-02-17 19:17                                           ` Pavel Machek
2015-02-19 12:46                                             ` Michal Simek
2015-02-21  6:31                                               ` atull
2015-02-17 18:12                                         ` Jason Gunthorpe
2015-01-15 21:42                           ` Jason Gunthorpe [this message]
2015-01-17 21:11                       ` Pavel Machek
2015-01-06 20:13 ` [PATCH v8 3/4] staging: fpga manager: framework core atull
2015-01-06 20:13 ` [PATCH v8 4/4] staging: fpga manager: add driver for socfpga fpga manager atull
2015-01-10 18:11 ` [PATCH v8 0/4] FPGA Manager Framework Konrad Zapalowicz
2015-01-11 16:08   ` atull
2015-01-11 16:24     ` Konrad Zapalowicz
2015-01-11 19:52       ` Pavel Machek
2015-01-11 20:58         ` Konrad Zapalowicz
2015-01-11 21:31           ` Pavel Machek
2015-01-12 13:50             ` Michal Simek
2015-01-12 14:06         ` Dan Carpenter

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=20150115214230.GD23247@obsidianresearch.com \
    --to=jgunthorpe@obsidianresearch.com \
    --cc=akpm@linux-foundation.org \
    --cc=atull@opensource.altera.com \
    --cc=balbi@ti.com \
    --cc=broonie@kernel.org \
    --cc=cesarb@cesarb.net \
    --cc=davem@davemloft.net \
    --cc=davidb@codeaurora.org \
    --cc=delicious.quinoa@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dinguyen@opensource.altera.com \
    --cc=galak@codeaurora.org \
    --cc=gnomes@lxorguk.ukuu.org.uk \
    --cc=grant.likely@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=iws@ovro.caltech.edu \
    --cc=jason@lakedaemon.net \
    --cc=kyle.teske@ni.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.chehab@samsung.com \
    --cc=mark.rutland@arm.com \
    --cc=michal.simek@xilinx.com \
    --cc=monstr@monstr.eu \
    --cc=nico@linaro.org \
    --cc=pantelis.antoniou@konsulko.com \
    --cc=pavel@denx.de \
    --cc=pawel.moll@arm.com \
    --cc=philip@balister.org \
    --cc=rdunlap@infradead.org \
    --cc=rob@landley.net \
    --cc=robh+dt@kernel.org \
    --cc=rubini@gnudd.com \
    --cc=s.trumtrar@pengutronix.de \
    --cc=sameo@linux.intel.com \
    /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).