I am learning linux device drivers. I learned about ports. I am confused that are ports in linux a software abstraction or are real hardware ports.
In the below device driver I wrote a code to allocate a port and to write or read.
The port is allocated even if there is no new hardware connected. What can be the reason?
Another problem is that when I write into the port using oub() and when I read from port using inb() then I always get the value 255 irrespective of what I wrote into the port.
#include<linux/init.h>
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/ioport.h>
struct resource *p;
static int start(void)
{
printk("module registered\n");
p=request_region(0x0062, 1, "my_port");
if(p==NULL)
{
printk(KERN_ALERT "port allocation failed\n");
return 0;
}
outb(12, 0x0062);
return 0;
}
static void stop(void)
{
printk("module unregistered\n");
unsigned a;
a=inb(0x0062);
printk("%d\n", a);
release_region(0x0062, 1);
}
module_init(start);
module_exit(stop);
MODULE_LICENSE("GPL");
I allocate the port and write into it while inserting the module and read from it while unregistering the module.
Thanks in advance for any help
Unfortunately, in the course of the years, CPU manufacturers did not agree on a single mechanism for accessing devices' registers. There are therefore two modes, and a single hardware architecture can implement one mode or the other. These two modes are
The book Linux Device Drivers 3rd edition (freely available on-line) illustrates this difference and how to access each kind of I/O from a kernel driver.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With