For example, video drivers must have the function for drawing a line:
Code: Select all
int DrawLine(int x1, int y1, int x2, int y2, int color);
I've the same problem for other drivers, such as PCI driver.
Code: Select all
int DrawLine(int x1, int y1, int x2, int y2, int color);
I don't understand. I'm using unix interface for device drivers with only open, write, read, close, ioctl. What are you saying?~ wrote:What about passing them the same number of parameters, and let each driver to utilize only those that it knows it needs?
Or, since each driver is different, why not simply have each API call pass the correct number of parameters? Isn't it done like that anyway?
For most of the device drivers that only require one parameter you could just pass it as normal. For device drivers that require more than one parameter you could put all of the information in a structure and pass a pointer to the structure, casting it to whatever the type of that one parameter is. All of your existing device drivers would still work and only the device drivers that thought that they were getting a pointer to a struct would treat it as such.MarkOS wrote:Is this a good method?frank wrote:You could pass a pointer to a struct as that one parameter.
I thinked I can pass the struct with write.
Easiest thing is to pass a single parameter, which is the combination of the 5 parameters:MarkOS wrote: that needs at least 5 parameters. With ioctl I can pass only one parameter. How can I do?
Code: Select all
struct drawline_paremeters {
int x1,y1,x2,y2,color;
};
...
struct drawline_paramaeters dp = { 1, 1, 10, 10, red};
ioctl(graphics_fd, __ioctl_graphics_drawline, &dp);
Code: Select all
NAME
ioctl - control device
SYNOPSIS
#include <sys/ioctl.h>
int ioctl(int d, int request, ...);
DESCRIPTION
The ioctl function manipulates the underlying device parameters of special
files. In particular, many operating characteristics of character special
files (e.g. terminals) may be controlled with ioctl requests. The argu-
ment d must be an open file descriptor.
The second argument is a device-dependent request code. The third argu-
ment is an untyped pointer to memory. It's traditionally char *argp (from
the days before void * was valid C), and will be so named for this discus-
sion.
An ioctl request has encoded in it whether the argument is an in parameter
or out parameter, and the size of the argument argp in bytes. Macros and
defines used in specifying an ioctl request are located in the file
<sys/ioctl.h>.
What's the point of "clean" in the presence of ioctl?mystran wrote:So you can just have it take variable number of arguments kinda like printf, if you want. Passing a struct is potentially a bit cleaner though.
....Candy wrote:What's the point of "clean" in the presence of ioctl?mystran wrote:So you can just have it take variable number of arguments kinda like printf, if you want. Passing a struct is potentially a bit cleaner though.
Why would you want to force many devices that have completely different functionality to use a interface that would not be efficient for them to use? You might just want to widen the conceptual scope and break it into logical 'functionality blocks'.that needs at least 5 parameters. With ioctl I can pass only one parameter. How can I do?
I've the same problem for other drivers, such as PCI driver.
The Linux kernel does not subject all it's drivers to using one interface with five methods such as: open, close, read, write, ioctl.I have some problems about device drivers handling. I use the structure of unix and linux device drivers (functions are open, close, read, write, ioctl). But with this method how can I handle the drivers that wants more than only one parameter?
Code: Select all
static struct pci_driver xl_3c359_driver = {
.name = "3c359",
.id_table = xl_pci_tbl,
.probe = xl_probe,
.remove = __devexit_p(xl_remove_one),
};