Beispiel #1
0
Datei: lfdd.c Projekt: swem/lfdk
static int lfdd_ioctl( struct file *file
                            , unsigned int cmd, unsigned long arg ) {

    struct lfdd_pci_t lfdd_pci_data;
    struct lfdd_mem_t lfdd_mem_data;
    struct lfdd_io_t lfdd_io_data;
    void __user *argp = (void __user *)arg;

    switch( cmd ) {

    
        //
        // PCI Functions
        //
        case LFDD_PCI_READ_256BYTE:

            if( copy_from_user( &lfdd_pci_data, argp, sizeof( struct lfdd_pci_t ) ) ) {

                return -EFAULT;
            }

            memset( lfdd_pci_data.mass_buf, 0, LFDD_MASSBUF_SIZE );
            lfdd_pci_read_256byte( &lfdd_pci_data );

            return copy_to_user( argp, &lfdd_pci_data, sizeof( struct lfdd_pci_t ) );

        case LFDD_PCI_READ_BYTE:
            LFDD_PCI_READ( lfdd_pci_read_byte, lfdd_pci_data );

        case LFDD_PCI_READ_WORD:
            LFDD_PCI_READ( lfdd_pci_read_word, lfdd_pci_data );

        case LFDD_PCI_READ_DWORD:
            LFDD_PCI_READ( lfdd_pci_read_dword, lfdd_pci_data );

        case LFDD_PCI_WRITE_BYTE:
            LFDD_PCI_WRITE( lfdd_pci_write_byte, lfdd_pci_data );

        case LFDD_PCI_WRITE_WORD:
            LFDD_PCI_WRITE( lfdd_pci_write_word, lfdd_pci_data );

        case LFDD_PCI_WRITE_DWORD:
            LFDD_PCI_WRITE( lfdd_pci_write_dword, lfdd_pci_data );        


        //
        // Memory Functions
        //
        case LFDD_MEM_READ_256BYTE:

            if( copy_from_user( &lfdd_mem_data, argp, sizeof( struct lfdd_mem_t ) ) ) {

                return -EFAULT;
            }

            memset( lfdd_mem_data.mass_buf, 0, LFDD_MASSBUF_SIZE );
            lfdd_mem_read_256byte( &lfdd_mem_data );

            return copy_to_user( argp, &lfdd_mem_data, sizeof( struct lfdd_mem_t ) );

        case LFDD_MEM_READ_BYTE:
            LFDD_MEM_READ( lfdd_mem_read_byte, lfdd_mem_data );

        case LFDD_MEM_READ_WORD:
            LFDD_MEM_READ( lfdd_mem_read_word, lfdd_mem_data );

        case LFDD_MEM_READ_DWORD:
            LFDD_MEM_READ( lfdd_mem_read_dword, lfdd_mem_data );

        case LFDD_MEM_WRITE_BYTE:
            LFDD_MEM_WRITE( lfdd_mem_write_byte, lfdd_mem_data );

        case LFDD_MEM_WRITE_WORD:
            LFDD_MEM_WRITE( lfdd_mem_write_word, lfdd_mem_data );

        case LFDD_MEM_WRITE_DWORD:
            LFDD_MEM_WRITE( lfdd_mem_write_dword, lfdd_mem_data );        


        //
        // IO Functions
        //
        case LFDD_IO_READ_256BYTE:

            if( copy_from_user( &lfdd_io_data, argp, sizeof( struct lfdd_io_t ) ) ) {

                return -EFAULT;
            }

            memset( lfdd_io_data.mass_buf, 0, LFDD_MASSBUF_SIZE );
            lfdd_io_read_256byte( &lfdd_io_data );

            return copy_to_user( argp, &lfdd_io_data, sizeof( struct lfdd_io_t ) );

        case LFDD_IO_WRITE_BYTE:
            LFDD_MEM_WRITE( lfdd_io_write_byte, lfdd_io_data );

        case LFDD_IO_READ_BYTE:
            LFDD_MEM_READ( lfdd_io_read_byte, lfdd_io_data );

    }

    return -EINVAL;
}
Beispiel #2
0
static long lfdd_ioctl( struct file *file
                            , unsigned int cmd, unsigned long arg ) {

    struct lfdd_pci_t lfdd_pci_data;
    struct lfdd_mem_t lfdd_mem_data;
    struct lfdd_io_t lfdd_io_data;
    void __user *argp = (void __user *)arg;

	printk( KERN_INFO "C1\n" );

    switch( cmd ) {

    
        //
        // PCI Functions
        //
        case LFDD_PCI_READ_256BYTE:

			printk( KERN_INFO "C3\n" );
            if( copy_from_user( &lfdd_pci_data, argp, sizeof( struct lfdd_pci_t ) ) ) {

				printk( KERN_INFO "C2\n" );
                return -EFAULT;
            }

            memset( lfdd_pci_data.mass_buf, 0, LFDD_MASSBUF_SIZE );
            lfdd_pci_read_256byte( &lfdd_pci_data );

            return copy_to_user( argp, &lfdd_pci_data, sizeof( struct lfdd_pci_t ) );

        case LFDD_PCI_READ_BYTE:
			printk( KERN_INFO "C4\n" );
            LFDD_PCI_READ( lfdd_pci_read_byte, lfdd_pci_data );

        case LFDD_PCI_READ_WORD:
			printk( KERN_INFO "C5\n" );
            LFDD_PCI_READ( lfdd_pci_read_word, lfdd_pci_data );

        case LFDD_PCI_READ_DWORD:
			printk( KERN_INFO "C6\n" );
            LFDD_PCI_READ( lfdd_pci_read_dword, lfdd_pci_data );

        case LFDD_PCI_WRITE_BYTE:
			printk( KERN_INFO "C7\n" );
            LFDD_PCI_WRITE( lfdd_pci_write_byte, lfdd_pci_data );

        case LFDD_PCI_WRITE_WORD:
			printk( KERN_INFO "C8\n" );
            LFDD_PCI_WRITE( lfdd_pci_write_word, lfdd_pci_data );

        case LFDD_PCI_WRITE_DWORD:
			printk( KERN_INFO "C9\n" );
            LFDD_PCI_WRITE( lfdd_pci_write_dword, lfdd_pci_data );        


        //
        // Memory Functions
        //
        case LFDD_MEM_READ_256BYTE:

			printk( KERN_INFO "C10\n" );
            if( copy_from_user( &lfdd_mem_data, argp, sizeof( struct lfdd_mem_t ) ) ) {

				printk( KERN_INFO "C11\n" );
                return -EFAULT;
            }

            memset( lfdd_mem_data.mass_buf, 0, LFDD_MASSBUF_SIZE );
            lfdd_mem_read_256byte( &lfdd_mem_data );

			printk( KERN_INFO "C12\n" );
            return copy_to_user( argp, &lfdd_mem_data, sizeof( struct lfdd_mem_t ) );

        case LFDD_MEM_READ_BYTE:
			printk( KERN_INFO "C13\n" );
            LFDD_MEM_READ( lfdd_mem_read_byte, lfdd_mem_data );

        case LFDD_MEM_READ_WORD:
			printk( KERN_INFO "C14\n" );
            LFDD_MEM_READ( lfdd_mem_read_word, lfdd_mem_data );

        case LFDD_MEM_READ_DWORD:
            LFDD_MEM_READ( lfdd_mem_read_dword, lfdd_mem_data );

        case LFDD_MEM_WRITE_BYTE:
            LFDD_MEM_WRITE( lfdd_mem_write_byte, lfdd_mem_data );

        case LFDD_MEM_WRITE_WORD:
            LFDD_MEM_WRITE( lfdd_mem_write_word, lfdd_mem_data );

        case LFDD_MEM_WRITE_DWORD:
            LFDD_MEM_WRITE( lfdd_mem_write_dword, lfdd_mem_data );        


        //
        // IO Functions
        //
        case LFDD_IO_READ_256BYTE:

			printk( KERN_INFO "C15\n" );
            if( copy_from_user( &lfdd_io_data, argp, sizeof( struct lfdd_io_t ) ) ) {

				printk( KERN_INFO "C16\n" );
                return -EFAULT;
            }

            memset( lfdd_io_data.mass_buf, 0, LFDD_MASSBUF_SIZE );
            lfdd_io_read_256byte( &lfdd_io_data );

            return copy_to_user( argp, &lfdd_io_data, sizeof( struct lfdd_io_t ) );

        case LFDD_IO_WRITE_BYTE:
            LFDD_MEM_WRITE( lfdd_io_write_byte, lfdd_io_data );

        case LFDD_IO_READ_BYTE:
            LFDD_MEM_READ( lfdd_io_read_byte, lfdd_io_data );

    }

	printk( KERN_INFO "C17\n" );
    return -EINVAL;
}