sono 5 years ago
parent
commit
7e61093eb6
  1. 1
      .gitignore
  2. 64
      usdpci.c

1
.gitignore

@ -5,3 +5,4 @@ test
*.mod
*.mod.*
*.o
*.cmd

64
usdpci.c

@ -23,7 +23,7 @@
#define DMA_ADDR_OFFSET 32
#define PRINT(A) printk(KERN_ALERT ">>>>> #A %x\n", A);
MODULE_AUTHOR("Talaie");
MODULE_AUTHOR("h4ndh"); //hediyehloo based on Talaee works
MODULE_LICENSE("Dual BSD/GPL");
static struct pci_device_id pcie_ids[] =
@ -62,14 +62,14 @@ unsigned long mmap_buffersize = 4 * 1024; //4KB
/*************************************************************************************************/
static int __init pcie_init(void);
static int pcie_init(void);
static int chrdev_init(void);
static int usd_open(struct inode *inode, struct file *flip);
static int usd_mmap(struct file *filp, struct vm_area_struct *vma);
static unsigned int usd_poll (struct file *filp, poll_table *wait);
static int __init pcie_probe (struct pci_dev *dev, const struct pci_device_id *id);
static int pcie_probe (struct pci_dev *dev, const struct pci_device_id *id);
static void pcie_remove(struct pci_dev *dev);
static void __exit pcie_exit(void);
static void pcie_exit(void);
/*************************************************************************************************/
static dev_t chrdev;
@ -91,7 +91,7 @@ struct file_operations chrdev_fops =
/*************************************************************************************************/
static struct pci_driver pci_driver =
{
.name = "usdpci",
.name = CLASS_NAME,
.id_table = pcie_ids,
.probe = pcie_probe,
.remove = __exit_p(pcie_remove),
@ -135,7 +135,6 @@ static int chrdev_init(void)
struct device *device = NULL;
res = alloc_chrdev_region(&chrdev, 0, 1, DEV_NAME);
if(res < 0)
{
return -1;
@ -143,7 +142,6 @@ static int chrdev_init(void)
cdev_init(&cdev, &chrdev_fops);
res = cdev_add(&cdev, chrdev, 1);
if (res)
{
unregister_chrdev_region(chrdev, 1);
@ -151,7 +149,7 @@ static int chrdev_init(void)
}
class = class_create(THIS_MODULE, CLASS_NAME);
device = device_create(class, NULL, 0, NULL, NODE_0_NAME);
device = device_create(class, NULL, chrdev, NULL, NODE_0_NAME);
return 0;
}
@ -177,10 +175,33 @@ static unsigned int usd_poll (struct file *filp, poll_table *wait)
/*************************************************************************************************/
static int __init pcie_probe (struct pci_dev *dev, const struct pci_device_id *id)
{
bar0_ptr = pci_iomap(dev, 0, bar0_size);
u8* bar0_data = (u8*)bar0_ptr;
int rc = 0;
rc = pci_enable_device(dev);
if(rc)
{
PRINT_ALERT("driver pci_enable_device() failed");
goto probe_fail_enable;
}
if(!(pci_resource_flags(dev, 0) & IORESOURCE_MEM))
{
printk(KERN_ERR "USDriver PCIe driver incorrect BAR configuration\n" );
rc = 1;
goto probe_fail;
}
bar0_addr = pci_resource_start(dev, 0);
rc = pci_request_region(dev, 0, "bar0");
if(rc)
{
PRINT_ALERT("driver pci_request_regions bar0 failed");
goto probe_fail;
}
bar0_ptr = pci_iomap(dev, 0, bar0_size);
u32* bar0_data = (u32*)bar0_ptr;
if(bar0_data == 0)
{
PRINT_ALERT("driver failed to map BAR 0");
@ -188,8 +209,23 @@ static int __init pcie_probe (struct pci_dev *dev, const struct pci_device_id *i
goto probe_fail_release_region;
}
if(!(pci_resource_flags(dev, 1) & IORESOURCE_MEM))
{
printk(KERN_ERR "USDriver PCIe driver incorrect BAR configuration\n" );
rc = 1;
goto probe_fail;
}
bar1_addr = pci_resource_start(dev, 1);
rc = pci_request_region(dev, 1, "bar1");
if(rc)
{
PRINT_ALERT("driver pci_request_regions bar1 failed");
goto probe_fail;
}
bar1_ptr = pci_iomap(dev, 1, bar1_size);
u8* bar1_data = (u8*)bar1_ptr;
u32* bar1_data = (u32*)bar1_ptr;
if(bar1_data == 0)
{
@ -200,6 +236,12 @@ static int __init pcie_probe (struct pci_dev *dev, const struct pci_device_id *i
pci_set_master(dev);
printk(KERN_ALERT "-----------------------------------\n");
printk(KERN_ALERT "BAR0 reg 0 = 0x%x\n", *bar0_data);
*bar1_data = 0x12345678;
printk(KERN_ALERT "BAR1 reg 0 = 0x%x\n", ioread32(bar1_data));
printk(KERN_ALERT "-----------------------------------\n");
return 0;
probe_fail_release_region:

Loading…
Cancel
Save