//------------------------------------------------------------------- // ioctl.c // // This module implements a character device-driver which lets // an application invoke 'ioctl()' system-calls that will hide // or show the graphics hardware's cursor (for SiS 315 only). // // programmer: ALLAN CRUSE // written on: 19 NOV 2004 -- for Linux kernel version 2.4.26 // revised on: 16 MAR 2005 -- for Linux kernel version 2.6.10 //------------------------------------------------------------------- #include // for init_module() #include // for pci_find_device() #define VENDOR_ID 0x1039 // Silicon Integrated Systems #define DEVICE_ID 0x6325 // SiS 315 Graphics Processor #define HIDE_CURSOR 0 #define SHOW_CURSOR 1 static char modname[] = "ioctl"; static char devname[] = "vram"; static int my_major = 99; static unsigned long mmio_base; static int my_ioctl( struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg ) { unsigned long *cursor_control, *cursor_pos_x, *cursor_pos_y; unsigned long command, pos_x, pos_y; void *vaddr; vaddr = ioremap_nocache( mmio_base + 0x8000, PAGE_SIZE ); cursor_control = vaddr + 0x500; cursor_pos_x = vaddr + 0x50C; cursor_pos_y = vaddr + 0x510; command = *cursor_control; pos_x = *cursor_pos_x; pos_y = *cursor_pos_y; switch ( cmd ) { case HIDE_CURSOR: command &= 0x3FFFFFFF; command |= 0x80000000; break; case SHOW_CURSOR: command &= 0x3FFFFFFF; command |= 0xC0000000; break; } *cursor_control = command; *cursor_pos_x = pos_x; *cursor_pos_y = pos_y; iounmap( vaddr ); return 0; // SUCCESS } static struct file_operations my_fops = { owner: THIS_MODULE, ioctl: my_ioctl, }; int init_module( void ) { struct pci_dev *devp = NULL; printk( "<1>\nInstalling \'%s\' module\n", modname ); printk( " device-file is \'/dev/%s\' ", devname ); printk( "(major=%d) \n", my_major ); devp = pci_find_device( VENDOR_ID, DEVICE_ID, devp ); if ( !devp ) return -ENODEV; mmio_base = pci_resource_start( devp, 1 ); printk( " SiS 315 graphics processor:" ); printk( " mmio_base=%08lX \n", mmio_base ); register_chrdev( my_major, devname, &my_fops ); return 0; // SUCCESS } void cleanup_module( void ) { unregister_chrdev( my_major, devname ); printk( "<1>Removing \'%s\' module\n", modname ); } MODULE_LICENSE("GPL");