I am trying to use the ARM watchdog thorough kernel space. I have a watchdog driver which is statically built and deployed in the kernel. The memory remapped by the driver is seen in /proc/iomem.
cat /proc/iomem | grep wdt
ff567000-ff567018 : /wdt@ff567000
The driver has remapped the address starting from 0xff567000 to a virtual address in the kernel.
Now I wrote a module to ioremap the same address and write to it.
static int __init wdt_init(void)
{
int ret;
wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
if (!wdev)
return -ENOMEM;
mutex_init(&wdev->lock);
printk(KERN_INFO "before mapping %p.\n", wdev->base);
wdev->base = ioremap (0xff567000, 0x18);
if (!wdev->base)
{
ret = -ENOMEM;
goto fail;
}
printk(KERN_INFO "wdt base address successfully mapped to %p.\n", wdev->base);
wdt_start(wdev);
wdt_get_timeout (wdev);
wdt_set_timeout (wdev, 30);
wdt_get_timeout (wdev);
while (1)
{
wdt_ping(wdev);
}
return 0;
fail:
printk(KERN_INFO "failed to map wdt base address\n");
return ret;
}
The output seen after inserting the module is:
root@bdk:/opt# insmod test_ioremap.ko
[ 1770.862628] before mapping (null).
[ 1770.867477] VXR10 wdt base address successfully mapped to f0988000.
Further I am able to read and write to the watchdog registers successfully.
Please tell me, Will this mapping have any effect on the normal working of the driver ?
Thanks for all your help in advance.
Simply making another mapping on device "memory" should cause no issues on ARM. But multiple drivers accessing/manipulating the same device memory will probably cause device malfunction and/or unpredictable behavior. Well-behaved drivers (e.g. the original watchdog driver) call request_mem_region() before ioremap(), which would completely avoid this issue that you raise.
Russell King, the ARM Linux guru mentions "On ARM, we (probably) have a lot of cases where ioremap() is used multiple times for the same physical address space." Regardless, the preferred practice is only one mapping.