All of lore.kernel.org
 help / color / mirror / Atom feed
* iomem and ioports
@ 2011-02-16  7:45 prabhu
  2011-02-16 11:43 ` Rajat Jain
  0 siblings, 1 reply; 4+ messages in thread
From: prabhu @ 2011-02-16  7:45 UTC (permalink / raw)
  To: kernelnewbies

HI All,

I started to understand output of /proc/oiports and /proc/iomem. I 
confused to relate these two's output. 

Below is the kernel source for Mapping of io-port to io-mem. Could 
anyone please explain below code.

/* We encode the physical PIO addresses (0-0xffff) into the
                                           (0-
 * pointer by offsetting them with a constant (0x10000) and
 * assuming that all the low addresses are always PIO. That means
                                                            means
 * we can do some sanity checks on the low bits, and don't
 * need to just take things for granted.
 */
#define PIO_OFFSET              0x10000UL
#define PIO_MASK                0x0ffffUL
#define PIO_RESERVED            0x40000UL
void __iomem *ioport_map(unsigned long port, unsigned int nr) {
     __iomem
           if (port > PIO_MASK) return NULL;
           return (void __iomem *) (unsigned long) (port + PIO_OFFSET);
                        __iomem
}

Thanks,
Prabhu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110216/27ef056e/attachment.html 

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

* iomem and ioports
  2011-02-16  7:45 iomem and ioports prabhu
@ 2011-02-16 11:43 ` Rajat Jain
  2011-02-16 15:27   ` anish singh
  0 siblings, 1 reply; 4+ messages in thread
From: Rajat Jain @ 2011-02-16 11:43 UTC (permalink / raw)
  To: kernelnewbies


Hi,

This code says that there are 0x10000 possible ioports i.e. in the range (0 - 0xFFFF). To map these into iomemory, simply an address = (0x10000 + ioport num) is used. Thus this code:

>
> if (port > PIO_MASK) return NULL;
>
Checks that the ioport number is within the range of ioports.

> 
> return (void __iomem *) (unsigned long) (port + PIO_OFFSET);
>
And if yes, offsets it by 0x10000 and returns the resulting address that shall be used as iomemory.

Thanks,

Rajat Jain

________________________________________
From: kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies-bounces at kernelnewbies.org] On Behalf Of prabhu
Sent: Wednesday, February 16, 2011 1:15 PM
To: kernelnewbies
Subject: iomem and ioports

HI All,

I started to understand output of /proc/oiports and /proc/iomem. I confused to relate these two's output.? 

Below is the kernel source for Mapping of io-port to io-mem. Could anyone please explain below code.

/* We encode the physical PIO addresses (0-0xffff) into the
?????????????????????????????????????????? (0-
?* pointer by offsetting them with a constant (0x10000) and
?* assuming that all the low addresses are always PIO. That means
??????????????????????????????????????????????????????????? means
?* we can do some sanity checks on the low bits, and don't
?* need to just take things for granted.
?*/
#define PIO_OFFSET????????????? 0x10000UL
#define PIO_MASK??????????????? 0x0ffffUL
#define PIO_RESERVED??????????? 0x40000UL
void __iomem *ioport_map(unsigned long port, unsigned int nr) {
???? __iomem
?????????? if (port > PIO_MASK) return NULL;
?????????? return (void __iomem *) (unsigned long) (port + PIO_OFFSET);
??????????????????????? __iomem
}

Thanks,
Prabhu

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

* iomem and ioports
  2011-02-16 11:43 ` Rajat Jain
@ 2011-02-16 15:27   ` anish singh
  2011-02-17  8:08     ` Rajat Jain
  0 siblings, 1 reply; 4+ messages in thread
From: anish singh @ 2011-02-16 15:27 UTC (permalink / raw)
  To: kernelnewbies

On Wed, Feb 16, 2011 at 5:13 PM, Rajat Jain <rajatjain@juniper.net> wrote:

>
> Hi,
>
> This code says that there are 0x10000 possible ioports i.e. in the range (0
> - 0xFFFF). To map these into iomemory, simply an address = (0x10000 + ioport
> num) is used. Thus this code:
>
> >
> > if (port > PIO_MASK) return NULL;
> >
> Checks that the ioport number is within the range of ioports.
>
> >
> > return (void __iomem *) (unsigned long) (port + PIO_OFFSET);
> >
> And if yes, offsets it by 0x10000 and returns the resulting address that
> shall be used as iomemory.
>
Some places i have seen that directly IO port is typecasted to  (__iomem * )
and used as it is i.e. returned value is given to ioread and iowrite
functions.Kindly explain why in some cases we dont add offset and in some
cases we add??
Is it because in some board we need to memory map the port number and then
read/write and in some boards we don't need to do that as we can directly
access the port using arch specific functions??


>
> Thanks,
>
> Rajat Jain
>
> ________________________________________
> From: kernelnewbies-bounces at kernelnewbies.org [mailto:
> kernelnewbies-bounces at kernelnewbies.org] On Behalf Of prabhu
> Sent: Wednesday, February 16, 2011 1:15 PM
> To: kernelnewbies
> Subject: iomem and ioports
>
> HI All,
>
> I started to understand output of /proc/oiports and /proc/iomem. I confused
> to relate these two's output.
>
> Below is the kernel source for Mapping of io-port to io-mem. Could anyone
> please explain below code.
>
> /* We encode the physical PIO addresses (0-0xffff) into the
>                                            (0-
>  * pointer by offsetting them with a constant (0x10000) and
>  * assuming that all the low addresses are always PIO. That means
>                                                             means
>  * we can do some sanity checks on the low bits, and don't
>  * need to just take things for granted.
>  */
> #define PIO_OFFSET              0x10000UL
> #define PIO_MASK                0x0ffffUL
> #define PIO_RESERVED            0x40000UL
> void __iomem *ioport_map(unsigned long port, unsigned int nr) {
>      __iomem
>            if (port > PIO_MASK) return NULL;
>            return (void __iomem *) (unsigned long) (port + PIO_OFFSET);
>                         __iomem
> }
>
> Thanks,
> Prabhu
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110216/a1f6273f/attachment.html 

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

* iomem and ioports
  2011-02-16 15:27   ` anish singh
@ 2011-02-17  8:08     ` Rajat Jain
  0 siblings, 0 replies; 4+ messages in thread
From: Rajat Jain @ 2011-02-17  8:08 UTC (permalink / raw)
  To: kernelnewbies

Some places i have seen that directly IO port is typecasted to? (__iomem * ) and used as it is i.e. returned value is given to ioread and iowrite functions.Kindly explain why in some cases we dont add?offset and?in some cases we add??
Is it because in some board we need to memory map the port number and then read/write and in some boards we don't need to do that as we can directly access the port using arch specific functions??
?

RAJAT> I would think so.

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

end of thread, other threads:[~2011-02-17  8:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-16  7:45 iomem and ioports prabhu
2011-02-16 11:43 ` Rajat Jain
2011-02-16 15:27   ` anish singh
2011-02-17  8:08     ` Rajat Jain

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.