All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vignesh Raghavendra <vigneshr@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 14/38] spi: Add support for memory-mapped flash
Date: Fri, 18 Oct 2019 14:21:19 +0530	[thread overview]
Message-ID: <91c3a4d7-98b4-d519-ceff-5812a9a9849a@ti.com> (raw)
In-Reply-To: <CAPnjgZ1fahjeWXnmj05V4UKiNLz3O8SqsmYC9pEyZkOU4yj=rQ@mail.gmail.com>

Hi Simon,

On 16/10/19 10:10 PM, Simon Glass wrote:
> Hi Vignesh,
> 
> On Wed, 16 Oct 2019 at 04:28, Vignesh Raghavendra <vigneshr@ti.com> wrote:
>>
>> Hi Simon,
>>
>> On 12/10/19 10:03 AM, Bin Meng wrote:
>>> Hi Simon,
>>>
>>> On Sat, Oct 12, 2019 at 11:08 AM Simon Glass <sjg@chromium.org> wrote:
>>>>
>>>> Hi Bin,
>>>>
>>>> On Wed, 9 Oct 2019 at 07:55, Bin Meng <bmeng.cn@gmail.com> wrote:
>>>>>
>>>>> Hi Simon,
>>>>>
>>>>> On Wed, Sep 25, 2019 at 10:12 PM Simon Glass <sjg@chromium.org> wrote:
>>>>>>
>>>>>> On x86 platforms the SPI flash can be mapped into memory so that the
>>>>>> contents can be read with normal memory accesses.
>>>>>>
>>>>>> Add a new SPI flash method to find the location of the SPI flash in
>>>>>> memory. This differs from the existing device-tree "memory-map" mechanism
>>>>>> in that the location can be discovered at run-time.
>>>>>>
>>
>> Whats is the usecase? Why can't spi_flash_read() be used instead?
>> Flash + Controller driver can underneath take care of using memory
>> mapped mode to read data from flash right while making sure that access
>> is within valid window?
> 
> This used to be implemented but is not supported anymore. I think we
> should wait until the DM SPI flash migration is complete before trying
> again.
> 
> Also it is not just reading. The data is used in-place in some cases,
> so we do want to know the map region.
> 

I am fine with the idea. Just wanted to know the motivation.

>>
>>>>>> Signed-off-by: Simon Glass <sjg@chromium.org>
>>>>>> ---
>>>>>>
>>>>>> Changes in v2: None
>>>>>>
>>>>>>  drivers/mtd/spi/sandbox_direct.c | 11 +++++++++++
>>>>>>  drivers/mtd/spi/sf-uclass.c      | 11 +++++++++++
>>>>>>  include/spi_flash.h              | 27 +++++++++++++++++++++++++++
>>>>>>  test/dm/sf.c                     |  9 +++++++++
>>>>>>  4 files changed, 58 insertions(+)
>>>>>>
>>>>>> diff --git a/drivers/mtd/spi/sandbox_direct.c b/drivers/mtd/spi/sandbox_direct.c
>>>>>> index 43d8907710c..fb515edcb7c 100644
>>>>>> --- a/drivers/mtd/spi/sandbox_direct.c
>>>>>> +++ b/drivers/mtd/spi/sandbox_direct.c
>>>>>> @@ -68,6 +68,16 @@ static int sandbox_direct_get_sw_write_prot(struct udevice *dev)
>>>>>>         return priv->write_prot++ ? 1 : 0;
>>>>>>  }
>>>>>>
>>>>>> +static int sandbox_direct_get_mmap(struct udevice *dev, ulong *map_basep,
>>>>>> +                                  size_t *map_sizep, u32 *offsetp)
>>>>>> +{
>>>>>> +       *map_basep = 0x1000;
>>>>>> +       *map_sizep = 0x2000;
>>>>>> +       *offsetp = 0x100;
>>>>>> +
>>>>>> +       return 0;
>>>>>> +}
>>>>>> +
>>>>>>  static int sandbox_direct_probe(struct udevice *dev)
>>>>>>  {
>>>>>>         struct sandbox_direct_priv *priv = dev_get_priv(dev);
>>>>>> @@ -82,6 +92,7 @@ static struct dm_spi_flash_ops sandbox_direct_ops = {
>>>>>>         .write = sandbox_direct_write,
>>>>>>         .erase = sandbox_direct_erase,
>>>>>>         .get_sw_write_prot = sandbox_direct_get_sw_write_prot,
>>>>>> +       .get_mmap = sandbox_direct_get_mmap,
>>>>>>  };
>>>>>>
>>>>>>  static const struct udevice_id sandbox_direct_ids[] = {
>>>>>> diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c
>>>>>> index 719a2fd23ae..127ec7e7aa6 100644
>>>>>> --- a/drivers/mtd/spi/sf-uclass.c
>>>>>> +++ b/drivers/mtd/spi/sf-uclass.c
>>>>>> @@ -28,6 +28,17 @@ int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len)
>>>>>>         return log_ret(sf_get_ops(dev)->erase(dev, offset, len));
>>>>>>  }
>>>>>>
>>>>>> +int spi_flash_get_mmap(struct udevice *dev, ulong *map_basep, size_t *map_sizep,
>>>>>> +                      u32 *offsetp)
>>>>>> +{
>>>>>> +       struct dm_spi_flash_ops *ops = sf_get_ops(dev);
>>>>>> +
>>>>>> +       if (!ops->get_mmap)
>>>>>> +               return -ENOSYS;
>>>>>> +
>>>>>> +       return ops->get_mmap(dev, map_basep, map_sizep, offsetp);
>>>>>> +}
>>>>>> +
>>>>>>  int spl_flash_get_sw_write_prot(struct udevice *dev)
>>>>>>  {
>>>>>>         struct dm_spi_flash_ops *ops = sf_get_ops(dev);
>>>>>> diff --git a/include/spi_flash.h b/include/spi_flash.h
>>>>>> index 55b4721813a..840189e22c7 100644
>>>>>> --- a/include/spi_flash.h
>>>>>> +++ b/include/spi_flash.h
>>>>>> @@ -47,6 +47,19 @@ struct dm_spi_flash_ops {
>>>>>>          *      other -ve value on error
>>>>>>          */
>>>>>>         int (*get_sw_write_prot)(struct udevice *dev);
>>>>>> +
>>>>>> +       /**
>>>>>> +        * get_mmap() - Get memory-mapped SPI
>>>>>> +        *
>>>>>> +        * @dev:        SPI flash device
>>>>>> +        * @map_basep:  Returns base memory address for mapped SPI
>>>>>> +        * @map_sizep:  Returns size of mapped SPI
>>>>>> +        * @offsetp:    Returns start offset of SPI flash where the map works
>>>>>> +        *      correctly (offsets before this are not visible)
>>>>>> +        * @return 0 if OK, -EFAULT if memory mapping is not available
>>>>>> +        */
>>>>>
>>>>> I feel odd to add such an op to the flash op, as memory address is not
>>>>> determined by the flash itself, but the SPI flash controller. We
>>>>> probably should add the op to the SPI flash controller instead.
>>>>
>>>> So do you think this should be added to UCLASS_SPI?
>>>
>>> Yes, I think so. Jagan, what's your recommendation?
>>>
>>>>
>>>> As it stands we don't actually use that uclass with this SPI flash
>>>> driver - it implements the SPI_FLASH interface directly.
>>>>
>>>> But given that I'm going to try to use the same ich.c driver this
>>>> should be easy enough.
>>>>
>>>> I've just found the weird mem_ops argument within struct dm_spi_ops...oh dear.
>>>>
>>>
>>> The mem_ops was added by Vignesh. I believe that was derived from the
>>> Linux kernel.
> 

spi_mem_ops in U-Boot was added by Miquel while introducing SPI NAND
support in U-Boot, but I extended its usage to SPI NOR devices as well.

> The problem is that it is ops within ops so doesn't follow driver model.

Hmm, why is that so?
ops within ops is not unheard of and is common in kernel as well. This
actually allows to grouping of similar operations into simple structs
and thus improves readability.


--
Regards
Vignesh

  reply	other threads:[~2019-10-18  8:51 UTC|newest]

Thread overview: 132+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-25 14:11 [U-Boot] [PATCH v2 00/38] x86: Various modifications to prepare for FSP2 Simon Glass
2019-09-25 14:11 ` [U-Boot] [PATCH v2 01/38] binman: Pass the toolpath to binman from the main Makefile Simon Glass
2019-10-02 13:55   ` Bin Meng
2019-10-03  2:02     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 02/38] binman: Allow selection of logging verbosity Simon Glass
2019-10-02 13:56   ` Bin Meng
2019-10-03  2:02     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 03/38] dm: gpio: Allow control of GPIO uclass in SPL Simon Glass
2019-10-02 13:56   ` Bin Meng
2019-10-03  2:02     ` Bin Meng
2019-10-04  2:58       ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 04/38] mtd: spi: Add 'struct spi_flash {' to the code Simon Glass
2019-10-02 13:56   ` Bin Meng
2019-10-03  2:02     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 05/38] serial: ns16550: Allow serial to enabled/disabled in SPL Simon Glass
2019-10-02 13:56   ` Bin Meng
2019-10-03  2:02     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 06/38] spl: Correct priority selection for image loaders Simon Glass
2019-09-26 12:32   ` Simon Goldschmidt
2019-09-25 14:11 ` [U-Boot] [PATCH v2 07/38] spl: Avoid checking for Ctrl-C in SPL with print_buffer() Simon Glass
2019-10-02 13:58   ` Bin Meng
2019-10-03  7:38     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 08/38] spl: handoff: Correct Kconfig condition for SPL and TPL Simon Glass
2019-10-02 13:58   ` Bin Meng
2019-10-03  7:38     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 09/38] spl: Add an arch-specific hook for writing to SPL handoff Simon Glass
2019-10-02 13:58   ` Bin Meng
2019-10-03  7:38     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 10/38] spl: Set up the bloblist in board_init_r() Simon Glass
2019-10-02 13:58   ` Bin Meng
2019-10-03  7:38     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 11/38] spl: Add a function to determine the U-Boot phase Simon Glass
2019-10-02 13:58   ` Bin Meng
2019-10-03  7:50     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 12/38] x86: spi: Add a driver for the Intel Fast SPI interface Simon Glass
2019-10-09 13:10   ` Bin Meng
2019-10-19  2:43     ` Simon Glass
2019-10-21  2:34       ` Bin Meng
2019-10-21  3:16         ` Simon Glass
2019-09-25 14:11 ` [U-Boot] [PATCH v2 13/38] spi: sandbox: Add a test driver for sandbox SPI flash Simon Glass
2019-10-09 13:50   ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 14/38] spi: Add support for memory-mapped flash Simon Glass
2019-10-09 13:55   ` Bin Meng
2019-10-12  3:08     ` Simon Glass
2019-10-12  4:33       ` Bin Meng
2019-10-16 10:29         ` Vignesh Raghavendra
2019-10-16 16:40           ` Simon Glass
2019-10-18  8:51             ` Vignesh Raghavendra [this message]
2019-10-18 14:13               ` Simon Glass
2019-10-17 14:28           ` Simon Glass
2019-10-18  2:22             ` Simon Glass
2019-10-18  2:32               ` Bin Meng
2019-10-18 14:14                 ` Simon Glass
2019-10-18 15:38                   ` Bin Meng
2019-10-18 20:37                     ` Simon Glass
2019-10-21  2:29                       ` Bin Meng
2019-10-21  3:14                         ` Simon Glass
2019-10-18  9:48               ` Vignesh Raghavendra
2019-10-18 14:13                 ` Simon Glass
2019-09-25 14:11 ` [U-Boot] [PATCH v2 15/38] x86: sysreset: Allow reset driver to be included in SPL/TPL Simon Glass
2019-10-02 14:06   ` Bin Meng
2019-10-03  7:50     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 16/38] x86: Rename some FSP functions to have an fsp_ prefix Simon Glass
2019-10-02 14:06   ` Bin Meng
2019-10-03  7:57     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 17/38] x86: fsp: Create a common fsp_support.h header Simon Glass
2019-10-02 14:06   ` Bin Meng
2019-10-03  8:32     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 18/38] x86: fsp: Use if() instead of #ifdef Simon Glass
2019-10-03  8:16   ` Bin Meng
2019-10-03  8:23     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 19/38] x86: fsp: Tidy up comment style a little Simon Glass
2019-10-02 14:06   ` Bin Meng
2019-10-03  8:29     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 20/38] x86: fsp: Move common dram functions into a common file Simon Glass
2019-10-02 14:06   ` Bin Meng
2019-10-03  8:35     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 21/38] x86: Move common fsp " Simon Glass
2019-10-02 14:06   ` Bin Meng
2019-10-03  8:44     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 22/38] x86: fsp: Move common support " Simon Glass
2019-10-02 14:06   ` Bin Meng
2019-10-03  8:44     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 23/38] efi: Move inline functions to unconditional part of header Simon Glass
2019-10-02 14:07   ` Bin Meng
2019-10-03  8:44     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 24/38] x86: fsp: Add a few more definitions for FSP2 Simon Glass
2019-10-02 14:07   ` Bin Meng
2019-10-03  8:44     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 25/38] x86: fsp: Add access to variable MRC data Simon Glass
2019-10-02 14:07   ` Bin Meng
2019-10-03  8:44     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 26/38] x86: Move common Intel CPU info code into a function Simon Glass
2019-10-02 14:07   ` Bin Meng
2019-10-03  8:56     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 27/38] x86: Add binman symbols to the image Simon Glass
2019-10-02 14:07   ` Bin Meng
2019-10-03  8:56     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 28/38] x86: pci: Add a function to clear and set PCI config regs Simon Glass
2019-10-02 14:07   ` Bin Meng
2019-10-03  8:56     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 29/38] x86: spl: Use hang() instead of a while() loop Simon Glass
2019-10-02 14:07   ` Bin Meng
2019-10-03  8:56     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 30/38] x86: spl: Reduce priority of the basic SPL image loader Simon Glass
2019-10-02 14:07   ` Bin Meng
2019-10-03  8:57     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 31/38] x86: spl: Move broadwell-specific code out of generic x86 spl Simon Glass
2019-10-02 14:07   ` Bin Meng
2019-10-03  9:09     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 32/38] x86: fsp: Save usable RAM and hob_list in the handoff area Simon Glass
2019-10-02 14:07   ` Bin Meng
2019-10-04  3:06     ` Bin Meng
2019-10-04  3:28       ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 33/38] x86: fsp: Allow the HOBs to be used after relocation Simon Glass
2019-10-04  3:23   ` Bin Meng
2019-10-10 17:06     ` Simon Glass
2019-09-25 14:11 ` [U-Boot] [PATCH v2 34/38] x86: Change condition for using CAR Simon Glass
2019-10-02 14:07   ` Bin Meng
2019-10-04  3:28     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 35/38] x86: Add more comments to the start-up code Simon Glass
2019-10-02 14:07   ` Bin Meng
2019-10-04  3:28     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 36/38] x86: Add support for booting from Fast SPI Simon Glass
2019-10-02 14:08   ` Bin Meng
2019-10-12  2:55     ` Simon Glass
2019-09-25 14:11 ` [U-Boot] [PATCH v2 37/38] x86: Add various MTRR indexes and values Simon Glass
2019-10-02 14:08   ` Bin Meng
2019-10-04  4:05     ` Bin Meng
2019-09-25 14:11 ` [U-Boot] [PATCH v2 38/38] x86: Rename turbo ratio MSR to MSR_TURBO_RATIO_LIMIT Simon Glass
2019-10-02 14:08   ` Bin Meng
2019-10-04  4:05     ` Bin Meng

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=91c3a4d7-98b4-d519-ceff-5812a9a9849a@ti.com \
    --to=vigneshr@ti.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.