Solved

I/O port accessing

Posted on 2003-12-07
10
348 Views
Last Modified: 2010-04-22
Hi,

I am a beginner at writing Linux dev drivers. I am facing problem while trying to compile and install the below simple module. The error is, "inb","outb" and
"--check_region" can't be resolved.

The code is

#define __KERNEL__
#define MODULE
#include <linux/module.h>
#include <linux/ioport.h>
#include<linux/config.h>
int init_module()
{
    check_region(0x23c, 0x04);
    outb((unsigned char)"a", 0x23c));
    printk("<1> The data at port is %d",inb(0x23c));
    return 1;
}

void cleanup_module()
{

}

I am using gcc -O to compile. and insmod to install the module using the object code. Please remember that I am a beginner and would appreciate an explaination as detailed as possible. All I am trying to do is get familiar with the idea of reading and writing from IOPorts. If you can provide some information on this, it will be much appreciated. I eventually want to learn how to write a device driver in Linux and I am using O'reilley publications' "Linux Device Drivers" and it is not particularly helpful for rank beginners.

Thanks,
Gautam
0
Comment
Question by:gautam_venkatesh
  • 4
  • 2
  • 2
10 Comments
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 20 total points
ID: 9891880
If the book is not too helpful, try the "Linux Kernel Module Programming Guide" at http://www.tldp.org/LDP/lkmpg/

In your case, you have to also add a line
#include <asm/io.h>

You should also return 0 from your init_module function: Anything but 0 will report flag an error.

0
 

Author Comment

by:gautam_venkatesh
ID: 9896516
Thanks for the response.
Why do I get undefined reference to __check_region?

0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 9896686
This worked for me. Which kernel version are you using? If I remember correctly, the use of check_region is discouraged, but it should still be in your header files. It should be declared in ioport.h. I'm not at my Linux box, so I cannot verify this.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:gautam_venkatesh
ID: 9904541
I am using kernel version 2.4.2. If check_region usage is discouraged, what is the alternative that I could use?
Can you provide a code snippet as well.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 9904980
Not right now (I'm not at my Linux machine). Do you have to use a kernel that old? I'm using 2.4.20, and it does handle check_region correctly.
0
 
LVL 1

Expert Comment

by:chikucoder
ID: 9971278
Hi Gautham

First of all ,I don't understand the reason for using the check_region () call ,Basically it is done to check ports are available to transreceiver bits,I mean used to serial,parallel or etc...

go to this link that will provide u the port address that u interact with.
http://www.xml.com/ldd/chapter/book/ch02.html

check_region(port,range)
If this call succeds it means ports are free
then u got to go for request region before
request_region(port,range,device name);

But if u want to right pseudo driver,Basic driver check region is not required i guess,This explianation may help u

cheers
chiku :)
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 9971534
The reason for check_region is to see if a different driver already has allocated the ports. Older kernels did not provide a return value for request_region(), therefore it was necessary to check first (because request_region was not able to flag an error).

I have to admit that I have not done any driver development with 2.4, so I'm not up do date on the changes in regards to check_region().
0
 
LVL 1

Expert Comment

by:chikucoder
ID: 9989683
If u have some more doubts post it

cheers
chiku
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question