All of lore.kernel.org
 help / color / mirror / Atom feed
* Appropriate method of io remapping a single memory location?
@ 2015-05-05 10:18 maitysanchayan at gmail.com
  2015-05-05 12:25 ` Carlo Caione
  0 siblings, 1 reply; 5+ messages in thread
From: maitysanchayan at gmail.com @ 2015-05-05 10:18 UTC (permalink / raw)
  To: kernelnewbies

Hello,

I am adding a small piece of code to expose SoC specific information 
while following the below information, for a Cortex A5 platform.

https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-soc

For the SoC device attribute revision, I need to access a location 0x80 
for reading the ROM revision information. I am kinda stuck at trying to 
find the appropriate way to read this location.

The devm_ioremap* functions take a device pointer which I can manage but 
they also need a struct resource argument and devm_ioremap requries a 
resource_size_t as well. Having only a specific location to read, 
without having any struct resource what would be the appropriate way to 
get this information.

- Sanchayan.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Appropriate method of io remapping a single memory location?
  2015-05-05 10:18 Appropriate method of io remapping a single memory location? maitysanchayan at gmail.com
@ 2015-05-05 12:25 ` Carlo Caione
  2015-05-05 13:29   ` maitysanchayan at gmail.com
  0 siblings, 1 reply; 5+ messages in thread
From: Carlo Caione @ 2015-05-05 12:25 UTC (permalink / raw)
  To: kernelnewbies

On Tue, May 5, 2015 at 12:18 PM,  <maitysanchayan@gmail.com> wrote:
> Hello,
>
> I am adding a small piece of code to expose SoC specific information
> while following the below information, for a Cortex A5 platform.
>
> https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-soc
>
> For the SoC device attribute revision, I need to access a location 0x80
> for reading the ROM revision information. I am kinda stuck at trying to
> find the appropriate way to read this location.
>
> The devm_ioremap* functions take a device pointer which I can manage but
> they also need a struct resource argument and devm_ioremap requries a
> resource_size_t as well. Having only a specific location to read,
> without having any struct resource what would be the appropriate way to
> get this information.

If the register / memory location is only used for that specific
purpose then using something like reg = <0x00000080 0x4> in the DT
node is perfectly fine. But if the register is part of a larger device
you can use a syscon device to represent that.

-- 
Carlo Caione

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Appropriate method of io remapping a single memory location?
  2015-05-05 12:25 ` Carlo Caione
@ 2015-05-05 13:29   ` maitysanchayan at gmail.com
  2015-05-06  7:03     ` Carlo Caione
  0 siblings, 1 reply; 5+ messages in thread
From: maitysanchayan at gmail.com @ 2015-05-05 13:29 UTC (permalink / raw)
  To: kernelnewbies

Hello Carlo,

On 15-05-05 14:25:25, Carlo Caione wrote:
> On Tue, May 5, 2015 at 12:18 PM,  <maitysanchayan@gmail.com> wrote:
> > Hello,
> >
> > I am adding a small piece of code to expose SoC specific information
> > while following the below information, for a Cortex A5 platform.
> >
> > https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-soc
> >
> > For the SoC device attribute revision, I need to access a location 0x80
> > for reading the ROM revision information. I am kinda stuck at trying to
> > find the appropriate way to read this location.
> >
> > The devm_ioremap* functions take a device pointer which I can manage but
> > they also need a struct resource argument and devm_ioremap requries a
> > resource_size_t as well. Having only a specific location to read,
> > without having any struct resource what would be the appropriate way to
> > get this information.
> 
> If the register / memory location is only used for that specific
> purpose then using something like reg = <0x00000080 0x4> in the DT
> node is perfectly fine. But if the register is part of a larger device
> you can use a syscon device to represent that.

Thanks for the reply. Hmm... I did not think of a DT entry as it is a 
single location and not part of any particular peripheral. Not even 
mentioned in the memory map.

I tried grepping for ioremap functions instead of devm ones and saw one 
instance and I wrote mine like this

	rom_rev = ioremap(ROM_REVISION_REGISTER, SZ_1);
	if (rom_rev)
		soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%08x",
						readl(rom_rev));

Is something like this valid? Or use of devm_* functions is 
recommeneded? Since this ioremap is gonna be called from a function 
which is bound to the .init_machine entry of DT_MACHINE_START any harm 
in doing this ioremap directly or the DT method would be recommended?

Perhaps the side effect would be the stale mapping lying aroung even 
once the .init section is reclaimed?

> 
> -- 
> Carlo Caione

Thanks & Regards,
Sanchayan Maity.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Appropriate method of io remapping a single memory location?
  2015-05-05 13:29   ` maitysanchayan at gmail.com
@ 2015-05-06  7:03     ` Carlo Caione
  2015-05-07  7:53       ` maitysanchayan at gmail.com
  0 siblings, 1 reply; 5+ messages in thread
From: Carlo Caione @ 2015-05-06  7:03 UTC (permalink / raw)
  To: kernelnewbies

On Tue, May 5, 2015 at 3:29 PM,  <maitysanchayan@gmail.com> wrote:
> Thanks for the reply. Hmm... I did not think of a DT entry as it is a
> single location and not part of any particular peripheral. Not even
> mentioned in the memory map.

That's why I suggested to use a syscon device.

> I tried grepping for ioremap functions instead of devm ones and saw one
> instance and I wrote mine like this
>
>         rom_rev = ioremap(ROM_REVISION_REGISTER, SZ_1);
>         if (rom_rev)
>                 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%08x",
>                                                 readl(rom_rev));
>
> Is something like this valid? Or use of devm_* functions is
> recommeneded? Since this ioremap is gonna be called from a function
> which is bound to the .init_machine entry of DT_MACHINE_START any harm
> in doing this ioremap directly or the DT method would be recommended?

I guess that DT is always recommended. I would use something like
of_find_compatible_node() + of_iomap() on the syscon device for that
(after of_platform_populate()).
Probably you could use also directly the physical location or a
iotable but it is definitely uglier IMO.

-- 
Carlo Caione

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Appropriate method of io remapping a single memory location?
  2015-05-06  7:03     ` Carlo Caione
@ 2015-05-07  7:53       ` maitysanchayan at gmail.com
  0 siblings, 0 replies; 5+ messages in thread
From: maitysanchayan at gmail.com @ 2015-05-07  7:53 UTC (permalink / raw)
  To: kernelnewbies

Hello Carlo,

On 15-05-06 09:03:32, Carlo Caione wrote:
> On Tue, May 5, 2015 at 3:29 PM,  <maitysanchayan@gmail.com> wrote:
> > Thanks for the reply. Hmm... I did not think of a DT entry as it is a
> > single location and not part of any particular peripheral. Not even
> > mentioned in the memory map.
> 
> That's why I suggested to use a syscon device.
> 
> > I tried grepping for ioremap functions instead of devm ones and saw one
> > instance and I wrote mine like this
> >
> >         rom_rev = ioremap(ROM_REVISION_REGISTER, SZ_1);
> >         if (rom_rev)
> >                 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%08x",
> >                                                 readl(rom_rev));
> >
> > Is something like this valid? Or use of devm_* functions is
> > recommeneded? Since this ioremap is gonna be called from a function
> > which is bound to the .init_machine entry of DT_MACHINE_START any harm
> > in doing this ioremap directly or the DT method would be recommended?
> 
> I guess that DT is always recommended. I would use something like
> of_find_compatible_node() + of_iomap() on the syscon device for that
> (after of_platform_populate()).
> Probably you could use also directly the physical location or a
> iotable but it is definitely uglier IMO.

Thanks for the suggestion :). I will implement accordingly.

> 
> -- 
> Carlo Caione

Regards,
Sanchayan.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-05-07  7:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-05 10:18 Appropriate method of io remapping a single memory location? maitysanchayan at gmail.com
2015-05-05 12:25 ` Carlo Caione
2015-05-05 13:29   ` maitysanchayan at gmail.com
2015-05-06  7:03     ` Carlo Caione
2015-05-07  7:53       ` maitysanchayan at gmail.com

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.