[Uha-devel] CVS: uha/super/linux Makefile, NONE, 1.1 README, NONE, 1.1 dhahelper.c, NONE, 1.1 dhahelper.h, NONE, 1.1 duha-helper.c, NONE, 1.1 duha-helper.h, NONE, 1.1 test.c, NONE, 1.1
Alex Beregszaszi
alex at mplayerhq.hu
Thu Aug 18 14:54:03 CEST 2005
- Previous message: [Uha-devel] CVS: uha/lib HEADER, NONE, 1.1 Makefile, NONE, 1.1 bswap.h, NONE, 1.1 config.h, NONE, 1.1 config.mak, NONE, 1.1 exported.c, NONE, 1.1 iopl.c, NONE, 1.1 linux_proc.c, NONE, 1.1 mtrr.c, NONE, 1.1 pci.c, NONE, 1.1 pci.db, NONE, 1.1 pci.h, NONE, 1.1 pci_db2c.awk, NONE, 1.1 pci_helper.c, NONE, 1.1 pci_helper.h, NONE, 1.1 ports.c, NONE, 1.1 svgahelper.c, NONE, 1.1 uha.h, NONE, 1.1 uha_test.c, NONE, 1.1
- Next message: [Uha-devel] CVS: uha/super/windows MAKEFILE, NONE, 1.1 SOURCES, NONE, 1.1 dhahelper.c, NONE, 1.1 dhahelper.h, NONE, 1.1 dhasetup.c, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/uha/uha/super/linux
In directory mail:/home/alex/uha/uha/super/linux
Added Files:
Makefile README dhahelper.c dhahelper.h duha-helper.c
duha-helper.h test.c
Log Message:
initial commit
--- NEW FILE: Makefile ---
KERNEL_VERSION = $(shell uname -r)
KERNEL_DIR = /lib/modules/$(KERNEL_VERSION)/build
MDIR = /lib/modules/$(KERNEL_VERSION)/misc
ifeq ($(findstring 2.6.,$(KERNEL_VERSION)),2.6.)
MODULE = dhahelper.ko
obj-m = dhahelper.o
all:
@echo Please ignore warnings about overriding SUBDIRS
$(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules
else
KERNEL_INCLUDES = $(KERNEL_DIR)/include
INCLUDES = -I$(KERNEL_INCLUDES)
CFLAGS = -O2 -Wall -D__KERNEL__ -DMODULE -fomit-frame-pointer -fno-common -fno-strict-aliasing
MODULE = dhahelper.o
all: $(MODULE) test
dhahelper.o: dhahelper.c dhahelper.h
$(CC) $(CFLAGS) $(INCLUDES) -c $(basename $@).c
endif
test: test.c
$(CC) -g -O -Wall $(INCLUDES) -o $@ $@.c
install: $(MODULE)
test -d $(MDIR) || mkdir -p $(MDIR)
install -m 644 $(MODULE) $(MDIR)
depmod -a
if [ ! -c /dev/.devfsd ]; then \
rm -f /dev/dhahelper; \
mknod -m 600 /dev/dhahelper c 252 0; \
fi
nodes:
@echo make nodes is obsolete.
dep:
clean:
rm -f *.o *~ *.mod.* *.ko
distclean: clean
rm -f test
--- NEW FILE: README ---
dhahelper is small driver to provide some kernel function into userspace.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The main reason you need to use dhahelper is for busmastering.
(Btw, lacking of possibility to implement conversion of
virtual addresses into physical in userspace caused
implementing of so-called DRM drivers for Linux from
XFree86 side).
Second goal (still is unfinished) - provide possibility
to control port and physical memory access through
groups and access rights of this driver. (Unix way).
Installation:
~~~~~~~~~~~~~
just type in this directory:
make all install
The device node /dev/dhahelper will be created. The initial
permissions of this node are restrictive. See below for information
on how to make it available to non-root users.
Porting:
~~~~~~~~
This driver was developed only for Linux.
So if someone will port that on other unices
then any patches are gladly accepted.
WARNING:
~~~~~~~~
This driver violates some kernel security rules. To keep this driver
from anonymous access I suggest you create a new group (e.g. dha) for
/dev/dhahelper and set the permissions to 660 (or ug+rw,o-rw). Then
do one of the following:
- add trusted users to group dha.
- make trusted applications SGID to dha.
Good luck!
--- NEW FILE: dhahelper.c ---
/*
Direct Hardware Access kernel helper
(C) 2002 Alex Beregszaszi <alex at naxine.org>
(C) 2002-2003 Nick Kurshev <nickols_k at mail.ru>
(C) 2002-2004 Måns Rullgård <mru at users.sourceforge.net>
Accessing hardware from userspace as USER (no root needed!)
Tested on 2.2.x (2.2.19), 2.4.x (2.4.3,2.4.17) and 2.6.1.
License: GPL
WARNING! THIS MODULE VIOLATES SEVERAL SECURITY LINES! DON'T USE IT
ON PRODUCTION SYSTEMS, ONLY AT HOME, ON A "SINGLE-USER" SYSTEM.
NO WARRANTY!
IF YOU WANT TO USE IT ON PRODUCTION SYSTEMS THEN PLEASE READ 'README'
FILE TO KNOW HOW TO PREVENT ANONYMOUS ACCESS TO THIS MODULE.
[...1200 lines suppressed...]
#else
static void __exit exit_dhahelper(void)
#endif
{
unsigned i;
for(i=0;i<256;i++)
if(dha_irqs[i].handled)
free_irq(i, dha_irqs[i].dev);
unregister_dev();
}
#ifdef EXPORT_NO_SYMBOLS
EXPORT_NO_SYMBOLS;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
module_init(init_dhahelper);
module_exit(exit_dhahelper);
#endif
--- NEW FILE: dhahelper.h ---
/*
Direct Hardware Access kernel helper
(C) 2002 Alex Beregszaszi <alex at naxine.org>
(C) 2002-2003 Nick Kurshev <nickols_k at mail.ru>
*/
#ifndef DHAHELPER_H
#define DHAHELPER_H
#include <linux/ioctl.h>
/* feel free to change */
#define DEFAULT_MAJOR 252 /* 240-254 LOCAL/EXPERIMENTAL USE */
#define API_VERSION 0x30 /* 3.0*/
typedef struct dhahelper_port_s
{
#define PORT_OP_READ 1
#define PORT_OP_WRITE 2
int operation;
int size;
int addr; // FIXME - switch to void* (64bit)
int value;
} dhahelper_port_t;
typedef struct dhahelper_mtrr_s
{
#define MTRR_OP_ADD 1
#define MTRR_OP_DEL 2
int operation;
long start;
long size;
int type;
int privat;
} dhahelper_mtrr_t;
typedef struct dhahelper_pci_config_s
{
#define PCI_OP_READ 0
#define PCI_OP_WRITE 1
int operation;
int bus;
int dev;
int func;
int cmd;
int size;
long ret;
} dhahelper_pci_config_t;
typedef struct dhahelper_vmi_s
{
void * virtaddr;
unsigned long length;
unsigned long *realaddr;
}dhahelper_vmi_t;
typedef struct dhahelper_mem_s
{
void * addr;
unsigned long length;
}dhahelper_mem_t;
typedef struct dhahelper_irq_s
{
unsigned num;
int bus, dev, func;
int ack_region;
unsigned long ack_offset;
unsigned int ack_data;
}dhahelper_irq_t;
typedef struct dhahelper_cpu_flush_s
{
void *va;
unsigned long length;
}dhahelper_cpu_flush_t;
typedef struct dhahelper_pci_device_s
{
int bus,card,func; /* PCI/AGP bus:card:func */
unsigned short vendor,device; /* Card vendor+device ID */
unsigned long base0,base1,base2,baserom; /* Memory and I/O base addresses */
unsigned long base3,base4,base5; /* Memory and I/O base addresses */
unsigned char irq,ipin,gnt,lat; /* assigned IRQ parameters for this card */
}dhahelper_pci_device_t;
#define DHAHELPER_GET_VERSION _IOW('D', 0, int)
#define DHAHELPER_PORT _IOWR('D', 1, dhahelper_port_t)
#define DHAHELPER_MTRR _IOWR('D', 2, dhahelper_mtrr_t)
#define DHAHELPER_PCI_CONFIG _IOWR('D', 3, dhahelper_pci_config_t)
#define DHAHELPER_VIRT_TO_PHYS _IOWR('D', 4, dhahelper_vmi_t)
#define DHAHELPER_VIRT_TO_BUS _IOWR('D', 5, dhahelper_vmi_t)
#define DHAHELPER_ALLOC_PA _IOWR('D', 6, dhahelper_mem_t)
#define DHAHELPER_FREE_PA _IOWR('D', 7, dhahelper_mem_t)
#define DHAHELPER_LOCK_MEM _IOWR('D', 8, dhahelper_mem_t)
#define DHAHELPER_UNLOCK_MEM _IOWR('D', 9, dhahelper_mem_t)
#define DHAHELPER_INSTALL_IRQ _IOWR('D', 10, dhahelper_irq_t)
#define DHAHELPER_ACK_IRQ _IOWR('D', 11, dhahelper_irq_t)
#define DHAHELPER_FREE_IRQ _IOWR('D', 12, dhahelper_irq_t)
#define DHAHELPER_CPU_FLUSH _IOWR('D', 13, dhahelper_cpu_flush_t)
#define DHAHELPER_PCI_FIND _IOWR('D', 14, dhahelper_pci_device_t)
#endif /* DHAHELPER_H */
--- NEW FILE: duha-helper.c ---
/*
Direct Userland Hardware Access kernel helper
(C) 2002-2005 Alex Beregszaszi <alex at fsn.hu>
(C) 2002-2003 Nick Kurshev <nickols_k at mail.ru>
(C) 2002-2004 Måns Rullgård <mru at users.sourceforge.net>
Accessing hardware from userspace as USER (no root needed!)
Tested on 2.2.x (2.2.19), 2.4.x (2.4.3,2.4.17) and 2.6.1.
License: GPL
WARNING! THIS MODULE VIOLATES SEVERAL SECURITY LINES! DON'T USE IT
ON PRODUCTION SYSTEMS, ONLY AT HOME, ON A "SINGLE-USER" SYSTEM.
NO WARRANTY!
IF YOU WANT TO USE IT ON PRODUCTION SYSTEMS THEN PLEASE READ 'README'
FILE TO KNOW HOW TO PREVENT ANONYMOUS ACCESS TO THIS MODULE.
[...1200 lines suppressed...]
#else
static void __exit exit_dhahelper(void)
#endif
{
unsigned i;
for(i=0;i<256;i++)
if(dha_irqs[i].handled)
free_irq(i, dha_irqs[i].dev);
unregister_dev();
}
#ifdef EXPORT_NO_SYMBOLS
EXPORT_NO_SYMBOLS;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
module_init(init_dhahelper);
module_exit(exit_dhahelper);
#endif
--- NEW FILE: duha-helper.h ---
/*
Direct Hardware Access kernel helper
(C) 2002 Alex Beregszaszi <alex at naxine.org>
(C) 2002-2003 Nick Kurshev <nickols_k at mail.ru>
*/
#ifndef DHAHELPER_H
#define DHAHELPER_H
#include <linux/ioctl.h>
/* feel free to change */
#define DEFAULT_MAJOR 252 /* 240-254 LOCAL/EXPERIMENTAL USE */
#define API_VERSION 0x30 /* 3.0*/
typedef struct dhahelper_port_s
{
#define PORT_OP_READ 1
#define PORT_OP_WRITE 2
int operation;
int size;
int addr; // FIXME - switch to void* (64bit)
int value;
} dhahelper_port_t;
typedef struct dhahelper_mtrr_s
{
#define MTRR_OP_ADD 1
#define MTRR_OP_DEL 2
int operation;
long start;
long size;
int type;
int privat;
} dhahelper_mtrr_t;
typedef struct dhahelper_pci_config_s
{
#define PCI_OP_READ 0
#define PCI_OP_WRITE 1
int operation;
int bus;
int dev;
int func;
int cmd;
int size;
long ret;
} dhahelper_pci_config_t;
typedef struct dhahelper_vmi_s
{
void * virtaddr;
unsigned long length;
unsigned long *realaddr;
}dhahelper_vmi_t;
typedef struct dhahelper_mem_s
{
void * addr;
unsigned long length;
}dhahelper_mem_t;
typedef struct dhahelper_irq_s
{
unsigned num;
int bus, dev, func;
int ack_region;
unsigned long ack_offset;
unsigned int ack_data;
}dhahelper_irq_t;
typedef struct dhahelper_cpu_flush_s
{
void *va;
unsigned long length;
}dhahelper_cpu_flush_t;
typedef struct dhahelper_pci_device_s
{
int bus,card,func; /* PCI/AGP bus:card:func */
unsigned short vendor,device; /* Card vendor+device ID */
unsigned long base0,base1,base2,baserom; /* Memory and I/O base addresses */
unsigned long base3,base4,base5; /* Memory and I/O base addresses */
unsigned char irq,ipin,gnt,lat; /* assigned IRQ parameters for this card */
}dhahelper_pci_device_t;
#define DHAHELPER_GET_VERSION _IOW('D', 0, int)
#define DHAHELPER_PORT _IOWR('D', 1, dhahelper_port_t)
#define DHAHELPER_MTRR _IOWR('D', 2, dhahelper_mtrr_t)
#define DHAHELPER_PCI_CONFIG _IOWR('D', 3, dhahelper_pci_config_t)
#define DHAHELPER_VIRT_TO_PHYS _IOWR('D', 4, dhahelper_vmi_t)
#define DHAHELPER_VIRT_TO_BUS _IOWR('D', 5, dhahelper_vmi_t)
#define DHAHELPER_ALLOC_PA _IOWR('D', 6, dhahelper_mem_t)
#define DHAHELPER_FREE_PA _IOWR('D', 7, dhahelper_mem_t)
#define DHAHELPER_LOCK_MEM _IOWR('D', 8, dhahelper_mem_t)
#define DHAHELPER_UNLOCK_MEM _IOWR('D', 9, dhahelper_mem_t)
#define DHAHELPER_INSTALL_IRQ _IOWR('D', 10, dhahelper_irq_t)
#define DHAHELPER_ACK_IRQ _IOWR('D', 11, dhahelper_irq_t)
#define DHAHELPER_FREE_IRQ _IOWR('D', 12, dhahelper_irq_t)
#define DHAHELPER_CPU_FLUSH _IOWR('D', 13, dhahelper_cpu_flush_t)
#define DHAHELPER_PCI_FIND _IOWR('D', 14, dhahelper_pci_device_t)
#endif /* DHAHELPER_H */
--- NEW FILE: test.c ---
#include <string.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdlib.h>
#include "dhahelper.h"
int main(int argc, char *argv[])
{
int fd;
int ret;
fd = open("/dev/dhahelper", O_RDWR);
if(fd < 0){
perror("dev/dhahelper");
exit(1);
}
ioctl(fd, DHAHELPER_GET_VERSION, &ret);
printf("api version: %d\n", ret);
if (ret != API_VERSION)
printf("incompatible api!\n");
{
void *mem;
unsigned long size=256;
mem = mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
printf("allocated to %p\n", mem);
if (argc > 1)
if (mem != 0)
{
int i;
for (i = 0; i < 256; i++)
printf("[%x] ", *(int *)(mem+i));
printf("\n");
}
munmap((void *)mem, size);
}
return(0);
}
- Previous message: [Uha-devel] CVS: uha/lib HEADER, NONE, 1.1 Makefile, NONE, 1.1 bswap.h, NONE, 1.1 config.h, NONE, 1.1 config.mak, NONE, 1.1 exported.c, NONE, 1.1 iopl.c, NONE, 1.1 linux_proc.c, NONE, 1.1 mtrr.c, NONE, 1.1 pci.c, NONE, 1.1 pci.db, NONE, 1.1 pci.h, NONE, 1.1 pci_db2c.awk, NONE, 1.1 pci_helper.c, NONE, 1.1 pci_helper.h, NONE, 1.1 ports.c, NONE, 1.1 svgahelper.c, NONE, 1.1 uha.h, NONE, 1.1 uha_test.c, NONE, 1.1
- Next message: [Uha-devel] CVS: uha/super/windows MAKEFILE, NONE, 1.1 SOURCES, NONE, 1.1 dhahelper.c, NONE, 1.1 dhahelper.h, NONE, 1.1 dhasetup.c, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the uha-devel
mailing list