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

Subversion Repositories pci

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /pci/tags/working_demo/apps/sw/driver
    from Rev 8 to Rev 154
    Reverse comparison

Rev 8 → Rev 154

/fb/spartan_fb.o Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
fb/spartan_fb.o Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: fb/spartan_fb.c =================================================================== --- fb/spartan_fb.c (nonexistent) +++ fb/spartan_fb.c (revision 154) @@ -0,0 +1,774 @@ +/* + * framebuffer driver for VBE 2.0 compliant graphic boards + * + * switching to graphics mode happens at boot time (while + * running in real mode, see arch/i386/video.S). + * + * (c) 1998 Gerd Knorr + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include
spartan_drv-2.2.o Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: slide.c =================================================================== --- slide.c (nonexistent) +++ slide.c (revision 154) @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int main() +{ + int result ; + int fd ; + int i = 0; + char buff[640*480] ; + int palette[256] ; + int c; + unsigned long value ; + + fd = open("/dev/spartan", O_RDWR) ; + + if (fd < 0) { + printf("Error: Opening device /dev/spartan\n"); + return fd ; + } + + while (i < 54) { + c = getchar(); + if (c == EOF) + error("Early end-of-file."); + if ((i == 0) && (c != 0x42)) + error("Not BMP format."); + if ((i == 1) && (c != 0x4d)) + error("Not BMP format."); + if ((i == 2) && (c != 0x38)) + error("Not 8-bit BMP format."); + if ((i == 10) && (c != 0x36)) + error("Not limited to 64 colors (6 bits)."); + if ((i == 11) && (c != 0x01)) + error("Not limited to 64 colors (6 bits)."); + if ((i == 18) && (c != 0x80)) + error("Not 640 pixels horizontal resolution."); + if ((i == 19) && (c != 0x02)) + error("Not 640 pixels horizontal resolution."); + if ((i == 22) && (c != 0xe0)) + error("Not 480 pixels vertical resolution."); + if ((i == 23) && (c != 0x01)) + error("Not 480 pixels vertical resolution."); + i++; + } + + // activate resource 2 + value = 0x00000002 ; + result = ioctl(fd, SPARTAN_IOC_CURRESSET, value) ; + + /* Set palette */ + lseek(fd, SPARTAN_CRT_PALETTE_BASE, 0); + + while (i < 310) { + if (c == EOF) + error("Early end-of-file."); + + palette[(i - 54)/4] = ((getchar() >> 4) << 12) | ((getchar() >> 4) << 8) | ((getchar() >> 4) << 4); + +printf("%.4x\n", palette[(i - 54)/4]); + getchar(); + i+=4; + } + + while (i < 307510) { + buff[sizeof(buff) - (i - 310)] = (char)getchar(); + i++; + } + + if(write(fd, palette, 0x400) != 0x400) { + printf("Error writing device /dev/spartan\n"); + return -1; + } + + ioctl(fd, SPARTAN_IOC_SET_VIDEO_BUFF, buff) ; + + close(fd); + return 0; +} + Index: spartan_drv-2.4.o =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: spartan_drv-2.4.o =================================================================== --- spartan_drv-2.4.o (nonexistent) +++ spartan_drv-2.4.o (revision 154)
spartan_drv-2.4.o Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: spartan_kint.h =================================================================== --- spartan_kint.h (nonexistent) +++ spartan_kint.h (revision 154) @@ -0,0 +1,31 @@ +#include + +#define SPARTAN_IOC_NUM 'S' +#define SPARTAN_IOC_MAX_NUM 10 + +#define SPARTAN_IOC_CURRESGET _IO(SPARTAN_IOC_NUM, 1) // read current resource - (0 = none) +#define SPARTAN_IOC_CURRESSET _IO(SPARTAN_IOC_NUM, 2) // set current resource +#define SPARTAN_IOC_CURBASE _IOR(SPARTAN_IOC_NUM, 3, base) // read current resource base address +#define SPARTAN_IOC_CURBASEMAP _IOR(SPARTAN_IOC_NUM, 4, base) // read current resource remaped base address ( 0 - not remaped) +#define SPARTAN_IOC_CURBASESIZE _IOR(SPARTAN_IOC_NUM, 5, base_size)// read current resource size +#define SPARTAN_IOC_NUMOFRES _IO(SPARTAN_IOC_NUM, 6) // read number of found resources +#define SPARTAN_IOC_VIDEO_BASE _IOR(SPARTAN_IOC_NUM, 7, base) // read video buffer phyisical base address +#define SPARTAN_IOC_VIDEO_VBASE _IOR(SPARTAN_IOC_NUM, 8, base) // read video buffer virtual base address +#define SPARTAN_IOC_VIDEO_SIZE _IOR(SPARTAN_IOC_NUM, 9, base_size) // read video buffer size +#define SPARTAN_IOC_SET_VIDEO_BUFF _IO(SPARTAN_IOC_NUM, 10) + + +#define SPARTAN_P_IMG_CTRL1_ADDR 0x110 +#define SPARTAN_P_BA1_ADDR 0x114 +#define SPARTAN_P_AM1_ADDR 0x118 +#define SPARTAN_P_TA1_ADDR 0x11c + + +#define SPARTAN_W_IMG_CTRL1_ADDR 0x184 +#define SPARTAN_W_BA1_ADDR 0x188 +#define SPARTAN_W_AM1_ADDR 0x18C +#define SPARTAN_W_TA1_ADDR 0x190 + +#define SPARTAN_CRT_CTRL 0x000 +#define SPARTAN_CRT_ADD 0x004 +#define SPARTAN_CRT_PALETTE_BASE 0x400 Index: spartan_drv.c =================================================================== --- spartan_drv.c (nonexistent) +++ spartan_drv.c (revision 154) @@ -0,0 +1,598 @@ + +#define __KERNEL__ +#define MODULE + +#include +#include +#include +#include + +#include +#include //IOCTL definitions + +// define vendor and device ID here - currently this definitions specify reference designs from insight electronic +#ifdef __SDRAM__ +#define OC_PCI_VENDOR 0x1597 +#define OC_PCI_DEVICE 0x0300 +#endif +#ifdef __VGA__ +#define OC_PCI_VENDOR 0x2321 +#define OC_PCI_DEVICE 0x0001 +#endif + +// if someone wants specific major number assigned to spartan board - specify it here +// if 0 is used, kernel assigns it automaticaly +#ifdef __SDRAM__ +#define REQUESTED_MAJOR 243 +#endif + +#ifdef __VGA__ +#define REQUESTED_MAJOR 244 +#endif + +// if compiling module for kernel 2.4 - leave this defined +// for kernel 2.2 - comment this out +#define KERNEL_VER_24 + +#ifndef SEEK_SET + #define SEEK_SET 0 + #define SEEK_CUR 1 + #define SEEK_END 2 +#endif + +// io.h needed just for kernel 2.2 +#ifndef KERNEL_VER_24 + #include +#endif + +// memory mapped or IO mapped region definitions +#define SPARTAN_MEM_MAPPED 0 +#define SPARTAN_IO_MAPPED 1 + +#ifdef __VGA__ +#define VIDEO_SZ (640*480) +#endif + +// structure for holding board information +// (6 base addresses, mapping, page etc. +static struct our_dev +{ + int major ; + u32 bases[6] ; + u8 num_of_bases ; + u32 base_size[6] ; + u32 offset ; + u32 page_addr ; + u32 base_page_offset ; + int current_resource ; + int base_map[6] ; + u32 video_base ; + u32 video_vbase ; + u32 video_size ; + struct pci_dev *ppci_spartan_dev ; +} pspartan_dev ; + +// function prototypes +int spartan_open(struct inode *inode, struct file *filp); + +int spartan_release(struct inode *inode, struct file *filp); + +ssize_t spartan_read(struct file *filp, char *buf, size_t count, loff_t *offset ) ; +ssize_t spartan_write(struct file *filp, const char *buf, size_t count, loff_t *offset) ; +int spartan_ioctl(struct inode *pnode, struct file *filp, unsigned int cmd, unsigned long arg) ; +loff_t spartan_seek(struct file *filp, loff_t offset, int what) ; + +// file operations structure - different for kernels 2.2 and 2.4 +static struct file_operations *pspartan_fops ; +static struct file_operations spartan_fops = { + #ifdef KERNEL_VER_24 + NULL, + #endif + spartan_seek, + spartan_read, + spartan_write, + NULL, + NULL, + spartan_ioctl, + NULL, + spartan_open, + NULL, + spartan_release, +} ; + +int open_mem_mapped(void) ; + +// seek file operation function +loff_t spartan_seek(struct file *filp, loff_t offset, int origin) +{ + loff_t requested_offset ; + int resource_num = pspartan_dev.current_resource ; + + switch (origin) + { + case SEEK_CUR:requested_offset = pspartan_dev.offset + offset ; break ; + case SEEK_END:requested_offset = pspartan_dev.base_size[resource_num] + offset ; break ; + default:requested_offset = offset ; break ; + } + + if ((requested_offset < 0) || (requested_offset > pspartan_dev.base_size[resource_num])) + return -EFAULT ; + + pspartan_dev.offset = requested_offset ; + + return requested_offset ; +} + +// ioctl for device +// currently just a few operations are supported here - defined in spartan_kint.h header +int spartan_ioctl(struct inode *pnode, struct file *filp, unsigned int cmd, unsigned long arg) +{ + int error = 0; + int size = _IOC_SIZE(cmd) ; + unsigned long base ; + unsigned long base_size ; + int i; + + if (_IOC_TYPE(cmd) != SPARTAN_IOC_NUM) return -EINVAL ; + if (_IOC_NR(cmd) > SPARTAN_IOC_MAX_NUM) return -EINVAL ; + + // Writes through pointers not allowed - writes only through argument + if (_IOC_DIR(cmd) & _IOC_WRITE) return -EINVAL ; + else if (_IOC_DIR(cmd) & _IOC_READ) + error = verify_area(VERIFY_WRITE, (void *) arg, size) ; + + if (error) + return error ; + + switch (cmd){ + case SPARTAN_IOC_CURRESGET: + // current resource - they start at 1 + return (pspartan_dev.current_resource + 1) ; + case SPARTAN_IOC_CURRESSET: + // check if resource is in a range of implemented resources + if (arg < 0 ) + return -EINVAL ; + + // unmap previous resource if it was mapped + if (pspartan_dev.current_resource >= 0) + { + iounmap((void *)pspartan_dev.page_addr) ; + } + + if (arg == 0) + { + // previous resource unmaped - that's all + pspartan_dev.current_resource = -1 ; + return 0 ; + } + + if (pspartan_dev.num_of_bases < arg) + return -ENODEV ; + + // IO mapped not supported yet + if (pspartan_dev.base_map[arg] == SPARTAN_IO_MAPPED) + { + // set current resource to none, since it was unmapped + pspartan_dev.current_resource = -1 ; + return -ENODEV ; + } + pspartan_dev.current_resource= (int)(arg-1) ; + // remap new resource + if ( (error = open_mem_mapped()) ) + { + pspartan_dev.current_resource = -1 ; + return error ; + } + return 0 ; + case SPARTAN_IOC_CURBASE: + // check if any resource is currently activated + if (pspartan_dev.current_resource>=0) + base = pspartan_dev.bases[pspartan_dev.current_resource] ; + else + base = 0x00000000 ; + + *(unsigned long *)arg = base ; + return 0 ; + case SPARTAN_IOC_CURBASEMAP: + // check if any resource is currently activated + if (pspartan_dev.current_resource>=0) + base = pspartan_dev.page_addr ; + else + base = 0x00000000 ; + + *(unsigned long *)arg = base ; + + return 0 ; + case SPARTAN_IOC_CURBASESIZE: + // check if any resource is currently activated + if (pspartan_dev.current_resource>=0) + base_size = pspartan_dev.base_size[pspartan_dev.current_resource] ; + else + base_size = 0x00000000 ; + + *(unsigned long *)arg = base_size ; + return 0 ; + case SPARTAN_IOC_NUMOFRES: + return (pspartan_dev.num_of_bases) ; +#ifdef __VGA__ + case SPARTAN_IOC_VIDEO_BASE: + *((unsigned long *)arg) = pspartan_dev.video_base; + put_user(pspartan_dev.video_base, ((unsigned long *)arg)); + return 0 ; + + case SPARTAN_IOC_VIDEO_VBASE: + *(unsigned long *)arg = pspartan_dev.video_vbase; + put_user(pspartan_dev.video_vbase, ((unsigned long *)arg)); + return 0 ; + + case SPARTAN_IOC_VIDEO_SIZE: + *(unsigned long *)arg = pspartan_dev.video_size; + put_user(pspartan_dev.video_size, ((unsigned long *)arg)); + return 0; + + case SPARTAN_IOC_SET_VIDEO_BUFF: + for(i = 0; i < VIDEO_SZ; i++) { + get_user(*((char *)(pspartan_dev.video_vbase + i)), ((char *)(arg + i))); + } + + return 0; +#endif + default: + return -EINVAL ; + } +} + +// helper function for memory remaping +int open_mem_mapped(void) +{ + int resource_num = pspartan_dev.current_resource ; + unsigned long num_of_pages = 0 ; + unsigned long base = pspartan_dev.bases[resource_num] ; + unsigned long size = pspartan_dev.base_size[resource_num] ; + + if (!(num_of_pages = (unsigned long)(size/PAGE_SIZE))) ; + num_of_pages++ ; + + pspartan_dev.base_page_offset = base & ~PAGE_MASK ; + + if ((pspartan_dev.base_page_offset + size) < (num_of_pages*PAGE_SIZE)) + num_of_pages++ ; + + // remap memory mapped space + pspartan_dev.page_addr = (unsigned long)ioremap(base & PAGE_MASK, num_of_pages * PAGE_SIZE) ; + + if (pspartan_dev.page_addr == 0x00000000) + return -ENOMEM ; + + return 0 ; +} + +// add io mapped resource handler here +int open_io_mapped( void ) +{ + return 0 ; +} + +// open file operation function +int spartan_open(struct inode *inode, struct file *filp) +{ + if (MOD_IN_USE) + return -EBUSY ; + + pspartan_fops = &spartan_fops ; + filp->f_op = pspartan_fops ; + pspartan_dev.offset = 0 ; + pspartan_dev.current_resource = -1 ; + MOD_INC_USE_COUNT ; + return 0 ; +} + +// release - called by close on file descriptor +int spartan_release(struct inode *inode, struct file *filp) +{ + // unmap any remaped pages + if (pspartan_dev.current_resource >= 0) + iounmap((void *)pspartan_dev.page_addr) ; + + pspartan_dev.current_resource = -1 ; + + MOD_DEC_USE_COUNT ; + return 0 ; +} + +// memory mapped resource read function +ssize_t spartan_read(struct file *filp, char *buf, size_t count, loff_t *offset_out ) +{ + + unsigned long current_address = pspartan_dev.page_addr + pspartan_dev.base_page_offset + pspartan_dev.offset ; + unsigned long actual_count ; + unsigned long offset = pspartan_dev.offset ; + int resource_num = pspartan_dev.current_resource ; + int i; + int value; + + unsigned long size = pspartan_dev.base_size[resource_num] ; + int result ; + + if (pspartan_dev.current_resource < 0) + return -ENODEV ; + + if (offset == size) + return 0 ; + + if ( (offset + count) > size ) + actual_count = size - offset ; + else + actual_count = count ; + + // verify range if it is OK to copy from + if ((result = verify_area(VERIFY_WRITE, buf, actual_count))) + return result ; + + i = actual_count/4; + while(i--) { + + value = readl(current_address); + put_user(value, ((int *)buf)); + buf += 4; + current_address += 4; + } + + pspartan_dev.offset = pspartan_dev.offset + actual_count ; + + *(offset_out) = pspartan_dev.offset ; + + return actual_count ; + } + +// memory mapped resource write function +ssize_t spartan_write(struct file *filp, const char *buf, size_t count, loff_t *offset_out) +{ + unsigned long current_address = pspartan_dev.page_addr + pspartan_dev.base_page_offset + pspartan_dev.offset ; + unsigned long actual_count ; + unsigned long offset = pspartan_dev.offset ; + int resource_num = pspartan_dev.current_resource ; + int i; + int value; + unsigned long size = pspartan_dev.base_size[resource_num] ; + int result ; + + if (pspartan_dev.current_resource < 0) + return -ENODEV ; + + if (offset == size) + return 0 ; + + if ( (offset + count) > size ) + actual_count = size - offset ; + else + actual_count = count ; + + // verify range if it is OK to copy from + if ((result = verify_area(VERIFY_READ, buf, actual_count))) + return result ; + + i = actual_count/4; + while(i--) { + get_user(value, ((int *)buf)); + writel(value, current_address); + buf += 4; + current_address += 4; + } + pspartan_dev.offset = pspartan_dev.offset + actual_count ; + + *(offset_out) = pspartan_dev.offset ; + + return actual_count ; +} + +// initialization function - different for 2.2 and 2.4 kernel because of different pci_dev structure +int init_module(void) +{ + int result ; + u32 base_address ; + unsigned long size ; + unsigned short num_of_bases ; + u16 wvalue ; + struct pci_dev *ppci_spartan_dev = NULL ; + struct resource spartan_resource ; + struct page *page; + int sz ; + + if(!pci_present()) + { + printk("<1> Kernel reports no PCI bus support!\n " ); + return -ENODEV; + } + + if((ppci_spartan_dev = pci_find_device(OC_PCI_VENDOR, OC_PCI_DEVICE, ppci_spartan_dev))==NULL ) + { + printk("<1> Device not found!\n " ); + return -ENODEV ; + } + + pspartan_dev.ppci_spartan_dev = ppci_spartan_dev ; + +#ifdef KERNEL_VER_24 + //printk("<1> Board found at address 0x%08X\n", ppci_spartan_dev->resource[0].start) ; + // copy implemented base addresses to private structure + + spartan_resource = ppci_spartan_dev->resource[0] ; + base_address = spartan_resource.start ; + printk("<1> First base address register found at %08X \n ", base_address ); + num_of_bases = 0 ; + while ((base_address != 0x00000000) && (num_of_bases < 6)) + { + pspartan_dev.bases[num_of_bases] = spartan_resource.start ; + pspartan_dev.base_size[num_of_bases] = spartan_resource.end - spartan_resource.start + 1 ; + // check if resource is IO mapped + if (spartan_resource.flags & IORESOURCE_IO) + pspartan_dev.base_map[num_of_bases] = SPARTAN_IO_MAPPED ; + else + pspartan_dev.base_map[num_of_bases] = SPARTAN_MEM_MAPPED ; + + num_of_bases++ ; + spartan_resource = ppci_spartan_dev->resource[num_of_bases] ; + base_address = spartan_resource.start ; + } + + result = pci_read_config_word(ppci_spartan_dev, PCI_COMMAND, &wvalue) ; + if (result < 0) + { + printk("<1> Read from command register failed! \n " ); + return result ; + } + + result = pci_write_config_word(ppci_spartan_dev, PCI_COMMAND, wvalue | PCI_COMMAND_MEMORY | PCI_COMMAND_IO) ; + + if (result < 0) + { + printk("<1>Write to command register failed! \n " ); + return result ; + } + +#else + + printk("<1> Board found at address 0x%08X\n", ppci_spartan_dev->base_address[0]); + + // now go through base addresses of development board + // and see what size they are - first disable devices response + result = pci_read_config_word(ppci_spartan_dev, PCI_COMMAND, &wvalue) ; + if (result < 0) + { + printk("<1> Read from command register failed! \n " ); + return result ; + } + + // write masked config value back to command register to + // disable devices response! mask value + result = pci_write_config_word(ppci_spartan_dev, PCI_COMMAND, wvalue & ~PCI_COMMAND_IO & ~PCI_COMMAND_MEMORY) ; + + if (result < 0) + { + printk("<1>Write to command register failed! \n " ); + return result ; + } + + // write to base address registers and read back until all 0s are read + base_address = ppci_spartan_dev->base_address[0] ; + num_of_bases = 0 ; + while ((base_address != 0x00000000) && (num_of_bases < 6)) + { + // copy non-zero base address to private structure + pspartan_dev.bases[num_of_bases] = ppci_spartan_dev->base_address[num_of_bases] ; + + // write to current register + result = pci_write_config_dword(ppci_spartan_dev, PCI_BASE_ADDRESS_0 + (num_of_bases * 4), 0xFFFFFFFF) ; + + if (result < 0) + { + printk("<1>Write to BAR%d failed! \n ", num_of_bases); + return result ; + } + + result = pci_read_config_dword(ppci_spartan_dev, PCI_BASE_ADDRESS_0 + (num_of_bases * 4), &base_address) ; + if (result < 0) + { + printk("<1>Read from BAR%d failed! \n ", num_of_bases); + return result ; + } + + // calculate size of this base address register's range + size = 0xFFFFFFFF - base_address ; + + // store size in structure + pspartan_dev.base_size[num_of_bases] = size + 1; + + // set base address back to original value + base_address = pspartan_dev.bases[num_of_bases] ; + + // now write original base address back to this register + result = pci_write_config_dword(ppci_spartan_dev, PCI_BASE_ADDRESS_0 + (num_of_bases * 4), base_address) ; + + if (result < 0) + { + printk("<1>Write to BAR%d failed! \n ", num_of_bases); + return result ; + } + num_of_bases++ ; + // read new base address + base_address = ppci_spartan_dev->base_address[num_of_bases] ; + + } + // write original value back to command register! + result = pci_write_config_word(ppci_spartan_dev, PCI_COMMAND, wvalue) ; + + if (result < 0) + { + printk("<1>Write to command register failed! \n " ); + return result ; + } +#endif + if (num_of_bases < 1) + printk("<1>No implemented base address registers found! \n ") ; + + pspartan_dev.current_resource = - 1 ; + + // store number of bases in structure + pspartan_dev.num_of_bases = num_of_bases ; + + // display information about all base addresses found in this procedure + for (num_of_bases = 0; num_of_bases < pspartan_dev.num_of_bases; num_of_bases++) + { + printk("<1>BAR%d range from %08X to %08X \n ", num_of_bases, pspartan_dev.bases[num_of_bases], pspartan_dev.bases[num_of_bases] + pspartan_dev.base_size[num_of_bases]); + } +#ifdef __VGA__ + for (sz = 0, size = PAGE_SIZE; size < VIDEO_SZ; sz++, size <<= 1); + pspartan_dev.video_vbase = __get_free_pages(GFP_KERNEL, sz); + + if (pspartan_dev.video_vbase == 0) { + printk(KERN_ERR "spartan: abort, cannot allocate video memory\n"); + return -EIO; + } + + pspartan_dev.video_size = PAGE_SIZE * (1 << sz); + pspartan_dev.video_base = virt_to_bus(pspartan_dev.video_vbase); + + for (page = virt_to_page(pspartan_dev.video_vbase); page <= virt_to_page(pspartan_dev.video_vbase + pspartan_dev.video_size - 1); page++) + mem_map_reserve(page); + + printk(KERN_INFO "spartan: framebuffer at 0x%lx (phy 0x%lx), mapped to 0x%p, size %dk\n", + pspartan_dev.video_base, virt_to_phys(pspartan_dev.video_vbase), pspartan_dev.video_vbase, pspartan_dev.video_size/1024); +#endif + + result = register_chrdev(REQUESTED_MAJOR, "spartan", &spartan_fops) ; + if (result < 0) + { + printk(KERN_WARNING "spartan: can't get major number %d\n",REQUESTED_MAJOR) ; + return result ; + } + + printk("<1> Major number for spartan is %d \n", result ); + pspartan_dev.major = result ; + + return 0 ; +} + +// celanup - unregister device +void cleanup_module(void) +{ + int result ; + int size, sz; + +#ifdef __VGA__ + for (sz = 0, size = PAGE_SIZE; size < VIDEO_SZ; sz++, size <<= 1); + free_pages(pspartan_dev.video_vbase, sz); +#endif + result = unregister_chrdev(pspartan_dev.major, "spartan") ; + if (result < 0) + { + printk("<1> spartan device with major number %d unregistration failed \n", pspartan_dev.major); + return ; + } + else + { + printk("<1> spartan device with major number %d unregistered succesfully \n", pspartan_dev.major); + return ; + } +} Index: sdram_test =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: sdram_test =================================================================== --- sdram_test (nonexistent) +++ sdram_test (revision 154)
sdram_test Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: sdram_test.c =================================================================== --- sdram_test.c (nonexistent) +++ sdram_test.c (revision 154) @@ -0,0 +1,120 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int main() +{ + int result ; + int fd ; + unsigned long *buf ; + unsigned long value ; + unsigned long base ; + unsigned long base_size ; + + fd = open("/dev/spartan", O_RDWR) ; + + if (fd < 0) + return fd ; + + buf = (void *)malloc(4) ; + + if (buf == NULL) + return -1 ; + + // probe driver + result = ioctl(fd, SPARTAN_IOC_CURRESGET) ; + + if (result > 0) + printf("Driver reports enabled resource although it was not enabled through ioctl yet\n!") ; + + result = ioctl(fd, SPARTAN_IOC_NUMOFRES) ; + if (result != 2) + printf("SDRAM reference design implements 2 BARs, driver reported %d!\n", result) ; + + result = ioctl(fd, SPARTAN_IOC_CURBASE, &base) ; + if (base) + printf("Driver reports base address resource selected although it was not yet initialized!\n") ; + + result = ioctl(fd, SPARTAN_IOC_CURBASEMAP, &base) ; + + if (base) + printf("Driver reports base address remaped although it was not yet initialized!\n") ; + + result = ioctl(fd, SPARTAN_IOC_CURBASESIZE, &base_size) ; + if (base_size) + printf("Driver reports base address range non-zero although it was not yet initialized!\n") ; + + // activate resource 1 + value = 0x00000001 ; + result = ioctl(fd, SPARTAN_IOC_CURRESSET, value) ; + + if (result) + printf("Driver reported failure to intialize resource 1 !\n") ; + + // activate resource 2 + value = 0x00000002 ; + result = ioctl(fd, SPARTAN_IOC_CURRESSET, value) ; + + if (result) + printf("Driver reported failure to intialize resource 2!\n") ; + + // check if ioctl returns any meaningful values! + result = ioctl(fd, SPARTAN_IOC_CURRESGET) ; + + if (result != 2) + printf("Resource 2 was enabled, driver reports resurce %d active!\n", result) ; + + result = ioctl(fd, SPARTAN_IOC_CURBASE, &base) ; + if (!base) + printf("Driver should report non-zero base address when resource is selected!\n") ; + else + printf("Driver reports SDRAM at address %X\n", base) ; + + result = ioctl(fd, SPARTAN_IOC_CURBASEMAP, &base) ; + + if (!base) + printf("Driver reports zero page base address although resource 2 is supposed to be enabled!\n") ; + else + printf("Driver reports SDRAM at remaped address %X\n", base) ; + + result = ioctl(fd, SPARTAN_IOC_CURBASESIZE, &base_size) ; + if (!base_size) + printf("Driver reports zero base address range although resource is supposed to be enabled\n") ; + else + printf("Driver reports SDRAM size %li\n", base_size) ; + + value = 0x00000001 ; + *(buf) = value ; + while ((result = write(fd, buf, 4)) > 0) + { + value = value + 1 ; + *(buf) = value ; + } + + printf("%li writes succesfull!\n", value-1) ; + + // go back to start of image + value = lseek(fd, 0, 0) ; + if (result != 0) + { + printf("Seek didn't reset offset to 0i\n") ; + return -1 ; + } + value = 0x00000001 ; + while ((result = read(fd, buf, 4)) > 0) + { + if (value != *buf) + printf("Expected value was %X, actually read value was %X\n", value, *buf) ; + + value = value + 1 ; + } + + printf("%li reads done!\n", value-1) ; + close(fd) ; + return result ; +} Index: README.txt =================================================================== --- README.txt (nonexistent) +++ README.txt (revision 154) @@ -0,0 +1,20 @@ +Files provided in this directory are intended for +PCI development purposes. Kernel interface provides +some basic functionality for accessing PCI memory mapped +resources on single device. Modules have been tested +on Linux kernels 2.2 and 2.4, inserted with modutils version 2.4.6-1 for i386 +IO resources as well as interrupts or DMA (mastership) +are not supported by this interface yet - they will probably be when +PCI bridge development is finished. +sdram_test.c source and binary is a little program that tests driver response +with Insight's Spartan-II PCI development kit with SDRAM reference design +loaded. + +I have compiled modules with +gcc -D__KERNEL__ -DMODULE -c -O and it worked fine - if it doesn't for you, don't ask me why, because I'm not Linux guru + +I have inserted modules with +insmod -f spartan_drv-2.*.o and it also worked, nonetheless insmod was complaining about versions + +Have fun, + Miha Dolenc \ No newline at end of file Index: Makefile =================================================================== --- Makefile (nonexistent) +++ Makefile (revision 154) @@ -0,0 +1,6 @@ +spartan_fb.o: spartan_drv.c + gcc -D__KERNEL__ -DMODULE -D__VGA__ -I. -c -O2 -o spspartan_fb.o spartan_drv.c + +slide: slide.c + gcc -O2 -I. -o slide slide.c +

powered by: WebSVN 2.1.0

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