On Wed, Feb 16, 2011 at 5:13 PM, Rajat Jain <rajatjain@xxxxxxxxxxx> 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:
Checks that the ioport number is within the range of ioports.
>
> if (port > PIO_MASK) return NULL;
>
And if yes, offsets it by 0x10000 and returns the resulting address that shall be used as iomemory.
>
> return (void __iomem *) (unsigned long) (port + PIO_OFFSET);
>
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@xxxxxxxxxxxxxxxxx [mailto:kernelnewbies-bounces@xxxxxxxxxxxxxxxxx] 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@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@xxxxxxxxxxxxxxxxx http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies