Solved

I/O port accessing

Posted on 2003-12-07
10
346 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
Comment Utility
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
Comment Utility
Thanks for the response.
Why do I get undefined reference to __check_region?

0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
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
 

Author Comment

by:gautam_venkatesh
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
If u have some more doubts post it

cheers
chiku
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now