Solved

I/O port accessing

Posted on 2003-12-07
10
349 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
Industry Leaders: 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to line 1 65
Linux Hanging with disable Error Output 4 95
How to run a Linux Command from a different other than Root in Linux 5 117
Linux Scripting 3 169
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 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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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