OpenCores
URL https://opencores.org/ocsvn/pci/pci/trunk

Subversion Repositories pci

[/] [pci/] [tags/] [rel_13/] [apps/] [sw/] [driver/] [spartan_drv.c] - Diff between revs 85 and 103

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 85 Rev 103
Line 1... Line 1...
 
 
#define __KERNEL__
 
#define MODULE
 
 
 
#include <linux/module.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/kernel.h>
#include <linux/pci.h>
#include <linux/pci.h>
 
#include <linux/wrapper.h>
 
 
#include <asm/uaccess.h>
#include <asm/uaccess.h>
#include <spartan_kint.h> //IOCTL definitions
#include <spartan_kint.h> //IOCTL definitions
 
 
// define vendor and device ID here - currently this definitions specify reference designs from insight electronic
// define vendor and device ID here - currently this definitions specify reference designs from insight electronic
Line 17... Line 14...
#endif
#endif
#ifdef __VGA__
#ifdef __VGA__
#define OC_PCI_VENDOR 0x1895
#define OC_PCI_VENDOR 0x1895
#define OC_PCI_DEVICE 0x0001
#define OC_PCI_DEVICE 0x0001
#endif
#endif
 
#ifdef __OC_TEST__
 
#define OC_PCI_VENDOR 0x1895
 
#define OC_PCI_DEVICE 0x0001
 
#define __VGA__
 
#endif
 
 
// if someone wants specific major number assigned to spartan board - specify it here 
// if someone wants specific major number assigned to spartan board - specify it here 
// if 0 is used, kernel assigns it automaticaly
// if 0 is used, kernel assigns it automaticaly
#ifdef __SDRAM__
#ifdef __SDRAM__
#define REQUESTED_MAJOR 243
#define REQUESTED_MAJOR 0 
#endif
#endif
 
 
#ifdef __VGA__
#ifdef __VGA__
#define REQUESTED_MAJOR 244
#define REQUESTED_MAJOR 0
#endif
#endif
 
 
// if compiling module for kernel 2.4 - leave this defined
// if compiling module for kernel 2.4 - leave this defined
// for kernel 2.2 - comment this out
// for kernel 2.2 - comment this out
#define KERNEL_VER_24
#define KERNEL_VER_24
Line 48... Line 50...
// memory mapped or IO mapped region definitions
// memory mapped or IO mapped region definitions
#define SPARTAN_MEM_MAPPED 0
#define SPARTAN_MEM_MAPPED 0
#define SPARTAN_IO_MAPPED 1
#define SPARTAN_IO_MAPPED 1
 
 
#ifdef __VGA__
#ifdef __VGA__
 
#ifdef __OC_TEST__
 
    #define VIDEO_SZ (16384)
 
#else
#define VIDEO_SZ (640*480)
#define VIDEO_SZ (640*480)
#endif
#endif
 
#endif
 
 
// structure for holding board information
// structure for holding board information
// (6 base addresses, mapping, page etc.
// (6 base addresses, mapping, page etc.
static struct our_dev
static struct our_dev
{
{
Line 234... Line 240...
                        for(i = 0; i < VIDEO_SZ; i++) {
                        for(i = 0; i < VIDEO_SZ; i++) {
                                get_user(*((char *)(pspartan_dev.video_vbase +  i)), ((char *)(arg + i)));
                                get_user(*((char *)(pspartan_dev.video_vbase +  i)), ((char *)(arg + i)));
                        }
                        }
 
 
                        return 0;
                        return 0;
 
        case SPARTAN_IOC_GET_VIDEO_BUFF:
 
            for(i = 0; i < VIDEO_SZ; i++) {
 
                put_user(*((char *)(pspartan_dev.video_vbase +  i)), ((char *)(arg + i))) ;
 
            }
 
 
 
            return 0 ;
#endif
#endif
                default:
                default:
                        return -EINVAL ;
                        return -EINVAL ;
        }
        }
}
}
Line 307... Line 319...
        unsigned long current_address = pspartan_dev.page_addr + pspartan_dev.base_page_offset + pspartan_dev.offset ;
        unsigned long current_address = pspartan_dev.page_addr + pspartan_dev.base_page_offset + pspartan_dev.offset ;
        unsigned long actual_count ;
        unsigned long actual_count ;
        unsigned long offset = pspartan_dev.offset ;
        unsigned long offset = pspartan_dev.offset ;
        int resource_num = pspartan_dev.current_resource ;
        int resource_num = pspartan_dev.current_resource ;
        int i;
        int i;
        int value;
        unsigned int value;
 
        unsigned int *kern_buf ;
 
        unsigned int *kern_buf_tmp ;
 
 
        unsigned long size   = pspartan_dev.base_size[resource_num] ;
        unsigned long size   = pspartan_dev.base_size[resource_num] ;
        int result ;
        int result ;
 
 
        if (pspartan_dev.current_resource < 0)
        if (pspartan_dev.current_resource < 0)
Line 327... Line 341...
 
 
        // verify range if it is OK to copy from
        // verify range if it is OK to copy from
        if ((result = verify_area(VERIFY_WRITE, buf, actual_count)))
        if ((result = verify_area(VERIFY_WRITE, buf, actual_count)))
                return result ;
                return result ;
 
 
 
    kern_buf = kmalloc(actual_count, GFP_KERNEL | GFP_DMA) ;
 
    kern_buf_tmp = kern_buf ;
 
    if (kern_buf <= 0)
 
        return 0 ;
 
 
 
    memcpy_fromio(kern_buf, current_address, actual_count) ;
        i = actual_count/4;
        i = actual_count/4;
        while(i--) {
        while(i--) {
 
 
                value = readl(current_address);
//              value = readl(current_address); 
                put_user(value, ((int *)buf));
        value = *(kern_buf) ;
 
                put_user(value, ((unsigned int *)buf));
                buf += 4;
                buf += 4;
                current_address += 4;
        ++kern_buf ;
 
//              current_address += 4;
        }
        }
 
 
 
    kfree(kern_buf_tmp);
        pspartan_dev.offset = pspartan_dev.offset + actual_count ;
        pspartan_dev.offset = pspartan_dev.offset + actual_count ;
 
 
        *(offset_out) = pspartan_dev.offset ;
        *(offset_out) = pspartan_dev.offset ;
 
 
        return actual_count ;
        return actual_count ;
Line 354... Line 377...
        int resource_num = pspartan_dev.current_resource ;
        int resource_num = pspartan_dev.current_resource ;
        int i;
        int i;
        int value;
        int value;
        unsigned long size   = pspartan_dev.base_size[resource_num] ;
        unsigned long size   = pspartan_dev.base_size[resource_num] ;
        int result ;
        int result ;
 
    int *kern_buf ;
 
    int *kern_buf_tmp ;
 
 
        if (pspartan_dev.current_resource < 0)
        if (pspartan_dev.current_resource < 0)
                return -ENODEV ;
                return -ENODEV ;
 
 
        if (offset == size)
        if (offset == size)
Line 370... Line 395...
 
 
        // verify range if it is OK to copy from
        // verify range if it is OK to copy from
        if ((result = verify_area(VERIFY_READ, buf, actual_count)))
        if ((result = verify_area(VERIFY_READ, buf, actual_count)))
                return result ;
                return result ;
 
 
 
    kern_buf = kmalloc(actual_count, GFP_KERNEL | GFP_DMA) ;
 
    kern_buf_tmp = kern_buf ;
 
    if (kern_buf <= 0)
 
        return 0 ;
 
 
        i = actual_count/4;
        i = actual_count/4;
        while(i--) {
        while(i--) {
                get_user(value, ((int *)buf));
                get_user(value, ((int *)buf));
                writel(value, current_address);
                //writel(value, current_address);
 
        *kern_buf = value ;
                buf += 4;
                buf += 4;
                current_address += 4;
                //current_address += 4;
 
        ++kern_buf ;
        }
        }
 
 
 
    memcpy_toio(current_address, kern_buf_tmp, actual_count) ;
 
    kfree(kern_buf_tmp) ;
 
 
        pspartan_dev.offset = pspartan_dev.offset + actual_count ;
        pspartan_dev.offset = pspartan_dev.offset + actual_count ;
 
 
        *(offset_out) = pspartan_dev.offset ;
        *(offset_out) = pspartan_dev.offset ;
 
 
        return actual_count ;
        return actual_count ;
Line 595... Line 631...
                printk("<1> spartan device with major number %d unregistered succesfully \n", pspartan_dev.major);
                printk("<1> spartan device with major number %d unregistered succesfully \n", pspartan_dev.major);
                return ;
                return ;
        }
        }
}
}
 
 
 No newline at end of file
 No newline at end of file
 
MODULE_LICENSE("GPL") ;
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.