> I've got an ISA card at the address 0xD0000. I want to access it from a
> user program. As I can't read physical memory from it, I prepared
> (copied :-) ) a module which makes the way through. I know LILO needs to
> know that it shouldn't map the card's memory area, but can't remember
Not at all.
> how to do it.
> I'd like to know this, or any other (simpler) way to access the card
> from the user program.
Here is a sample program (under 2.2.14) also tailored from an existing module.
Gabor
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/malloc.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif
/***********************************************************/
struct fx2_struct {
unsigned char *memstart; /* physical address */
unsigned long flags;
# define FX2_F(minor) fx2_table[(minor)].flags
# define FX2_EXIST 0x0001
# define FX2_BUSY 0x0002
# define FX2_BUSY_BIT_POS 1
};
#define FX2_MAJOR 124
#define FX2_BASEADD ((unsigned char*)0xD0000) /* Phys. address is D?000 */
#define FX2_WINDOWSIZE 0x4000
#define FX2_TESTADDR 0x0003
#define FX2_NO 4
#define FX2_CMD_GO 0
#define FX2_CMD_RESET 1
struct fx2_struct fx2_table[FX2_NO] =
{
[0 ... FX2_NO-1] = { NULL, 0 }
};
/***********************************************************/
static void fx2_reset(unsigned int minor, int on)
{
unsigned char *addr = fx2_table[minor].memstart + FX2_TESTADDR;
unsigned char c=1;
if (on) readb(addr); /* reset pulled down */
else writeb(c,addr); /* reset line released */
}
static ssize_t fx2_read(struct file *file, char *buf,
size_t length, loff_t *ppos)
{
unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
unsigned long p = *ppos;
if (p >= FX2_WINDOWSIZE) return 0;
if (length > FX2_WINDOWSIZE-p) length = FX2_WINDOWSIZE - p;
if (copy_to_user(buf, phys_to_virt(fx2_table[minor].memstart + *ppos),
length))
return -EFAULT;
*ppos += length;
return length;
}
static ssize_t fx2_write(struct file *file, const char *buf,
size_t length, loff_t *ppos)
{
unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
unsigned long p= *ppos;
if (p >= FX2_WINDOWSIZE) return 0;
if (length > FX2_WINDOWSIZE-p) length = FX2_WINDOWSIZE - p;
if (copy_from_user(phys_to_virt(fx2_table[minor].memstart + *ppos),
buf, length))
return -EFAULT;
*ppos += length;
return length;
}
static int fx2_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
unsigned int minor = MINOR(inode->i_rdev);
switch (cmd) {
case FX2_CMD_GO:
fx2_reset(minor,0); /* start CPU */
break;
case FX2_CMD_RESET:
fx2_reset(minor,1); /* reset CPU */
break;
}
return 0;
}
static int fx2_open(struct inode *inode, struct file *file)
{
unsigned int minor = MINOR(inode->i_rdev);
if (minor >= FX2_NO) return -ENXIO;
if ((FX2_F(minor) & FX2_EXIST) == 0) return -ENXIO;
if (test_and_set_bit(FX2_BUSY_BIT_POS, &FX2_F(minor))) return -EBUSY;
MOD_INC_USE_COUNT;
return 0;
}
static int fx2_release(struct inode *inode, struct file *file)
{
unsigned int minor = MINOR(inode->i_rdev);
MOD_DEC_USE_COUNT;
FX2_F(minor) &= ~FX2_BUSY;
return 0;
}
static struct file_operations fx2_fops = {
NULL,
fx2_read,
fx2_write,
NULL, /* fx2_readdir */
NULL, /* fx2_poll */
fx2_ioctl,
NULL, /* fx2_mmap */
fx2_open,
NULL, /* flush */
fx2_release
};
/* Initialize the module */
int init_module()
{
unsigned char c, *addr;
int i;
int count = 0;
for (i=0; i<FX2_NO; i++) {
fx2_table[i].memstart = FX2_BASEADD + FX2_WINDOWSIZE*i;
addr=fx2_table[i].memstart + FX2_TESTADDR;
c=readb(addr);
writeb((0xff&~c), addr);
if (readb(addr) == (0xff&~c)) {
FX2_F(i) |= FX2_EXIST;
printk("fx2: card %i found at 0x%p\n",
i,fx2_table[i].memstart);
count++;
}
writeb(c, addr);
}
if (count == 0) {
printk(KERN_INFO "fx2: no card found\n");
return -ENODEV;
}
else if (register_chrdev(FX2_MAJOR, "fx2", &fx2_fops)) {
printk("fx2: unable to get major %d\n", FX2_MAJOR);
return -EIO;
}
return 0;
}
/* Cleanup - undid whatever init_module did */
void cleanup_module()
{
unregister_chrdev(FX2_MAJOR, "fx2");
}
--- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
----
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/