memory mapped IO in kernel mode



I'm working on a device driver for a 2.4 kernel and I'm having a heck of a
hard time.... I've never written a kernel module before, so it's an
uphill struggle. By way of background, I am working with Linux Device
Drivers, 2nd ed.... And I have a similar driver written for x86
architecture that I am using as a guide.

The hardware is controlled via memory mapped registers at 0x11e0104 -
0x11e0107. From what I've ben able to gather, I need to ioremap this and
use the handle returned by ioremap for readb and readw...

But... I am thoroughly confused by the kernel mode memory addressing and
how it pertains to the ARM architecture.

My init function is this:

#define TSDIO24region 0x11e00104
#define TSDIO24length 4


static char *mem_virt_addr;


int init_TSgpio(void)
{
int result;

printk("<1>Hello world.\n");

if (check_mem_region(TSDIO24region, TSDIO24length)) {
printk("TSgpio: memory already in use\n"); return -EBUSY;
}
request_mem_region(TSDIO24region, TSDIO24length, "TSDIO24gpio");

if( (result = register_chrdev(TSDIO24major, "TSDIO24",
&tsdio24_fops)) < 0) {
printk(KERN_WARNING "tsdio24: can't get major
%d\n",TSDIO24major);
return result;
}
mem_virt_addr = ioremap(TSDIO24region, TSDIO24length); return 0;
}


and my read function is this:

static ssize_t tsdio24_read(struct file *file, char *buf, size_t, length,
loff_t *ppos) {
printk("0x%02x %02x %02x %02x\n",
readb(mem_virt_addr),
readb(mem_virt_addr+1),
readb(mem_virt_addr+2),
readb(mem_virt_addr+3));
return 0;
}


While the read function does in fact spit out 4 bytes on `cat /dev/mydev`,
they appear to be unrelated to the memory location I want. I did try this
with page-aligned ioremap; AFAICT I got the same (wrong) memory area.

I am completely confused by the various 'adjustments' to the memory
addresses that I read about... Should I subtract 0x80000000 from the
above before I ioremap? Does ioremap have to be page aligned? What *are*
the arguments to ioremap? It doesn't seem to be documented anywhere in any
detail.

So... How does one do memory mapped IO on an ARM platform in kernel mode?

The driver, BTW, is fairly simple - it will implement IRQs for GPIO pins.
I was expecting a struggle over the IRQ code, but this has stumped me
early.... :-(

TIA,

--Yan

--
o__
,>/'_ o__
(_)\(_) ,>/'_ o__
Yan Seiner, PE (_)\(_) ,>/'_ o__
Certified Personal Trainer (_)\(_) ,>/'_ o__
Licensed Professional Engineer (_)\(_) ,>/'_
Who says engineers have to be pencil necked geeks? (_)\(_)

.



Relevant Pages

  • Re: 1352 NUL bytes at the end of a page? (was Re: Assertion `s && s->tree failed: The sag
    ... > usbcore: registered new driver usbfs ... (I just pulled that key at random out of the kernel repository; ... That ought to do a nice test of the CPU, memory, disk, and kernel sans ... I don't see how it could be an in-flight corruption. ...
    (Linux-Kernel)
  • Network buffer hang was Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
    ... >> with a normal memory access. ... These bug doesn't cause kernel hangs, ... > network stacks allocates 4KB buffers to store this little messages. ... This means even when a driver doesn't do the rx_copybreak ...
    (Linux-Kernel)
  • Re: Memory allocation problem with 2.6.22 after suspend/resume cycle
    ... after a suspend and resume cycle, the kernel will try to free ... I do however not agree with Andrew's conclusion, as the memory is not ... Can you try another version of the ATI driver? ... Are you 100% sure that your 32-bit kernel configuration reflects the 64-bit ...
    (Linux-Kernel)
  • Re: [Lhms-devel] [PATCH 0/7] Fragmentation Avoidance V19
    ... > free RAM is at 90%, still I cannot remove that piece of faulty RAM, fix ... Until we have some kind of kernel ... Another example might be a somewhat errant device driver which has ... implement these APIs it is not compatible with memory hotplug. ...
    (Linux-Kernel)
  • ioremap reposted
    ... check a phsical memory, I should so a ioremap to get the memory mapped. ... who know if that block of memory is hanled by another driver ... So the question is, if I can ioremap again, does it harm? ...
    (comp.os.linux.embedded)