Solved

I/O port accessing

Posted on 2003-12-07
10
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

734 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