Solved

I/O port accessing

Posted on 2003-12-07
10
351 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 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