2

I'm reading the source code of LDD3 Chapter 9. And there's an example for ISA driver named silly.

The following is initialization for the module. What I don't understand is why there's no call for "request_mem_region()" before invocation for ioremap() in line 282

268 int silly_init(void)
269 {
270     int result = register_chrdev(silly_major, "silly", &silly_fops);
271     if (result < 0) {
272         printk(KERN_INFO "silly: can't get major number\n");
273         return result;
274     }
275     if (silly_major == 0)
276         silly_major = result; /* dynamic */
277     /*
278      * Set up our I/O range.
279      */
280 
281     /* this line appears in silly_init */
282     io_base = ioremap(ISA_BASE, ISA_MAX - ISA_BASE);
283     return 0;
284 }
Sagar Jain
  • 7,475
  • 12
  • 47
  • 83
Qylin
  • 1,501
  • 1
  • 16
  • 26

1 Answers1

4

This particular driver allows accesses to all the memory in the range 0xA0000..0x100000.

If there actually are any devices in this range, then it is likely that some other driver already has reserved some of that memory, so if silly were try to call request_mem_region, it would fail, or it would be necessary to unload that other driver before loading silly.

On a PC, this range contains memory of the graphics card, and the system BIOS:

$ cat /proc/iomem
...
000a0000-000bffff : PCI Bus 0000:00
000c0000-000cedff : Video ROM
000d0000-000dffff : PCI Bus 0000:00
000e4000-000fffff : reserved
  000f0000-000fffff : System ROM
...

Unloading the graphics driver often is not possible (because it's not a module), and would prevent you from seeing what the silly driver does, and the ROM memory ranges are reserved by the kernel itself and cannot be freed.

TL;DR: Not calling request_mem_region is a particular quirk of the silly driver. Any 'real' driver would be required to call it.

CL.
  • 173,858
  • 17
  • 217
  • 259
  • My understanding is request_region/request_mem_region would apply for exclusively access priviledge to I/O ports. On the other hand, ioremap() would mapping the port number to virtual memory address space i.e. to register the port into TLB. Could you please explain what does ioremap() really do? – Qylin Sep 08 '13 at 09:08
  • This is indeed what `ioremap()` does. – CL. Sep 08 '13 at 11:56
  • To add to CL's comment, there is no reason that the same physical address can't be mapped twice causing two virtual addresses to be mapped to the same physical address. In fact, request_mem_region is designed to prevent this under normal circumstances. – Benjamin Leinweber Sep 08 '13 at 15:54