18 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/errno.h>
22 #include <linux/pci.h>
24 #include <linux/poll.h>
27 #include <linux/sched.h>
28 #include <linux/slab.h>
29 #include <linux/time.h>
34 #include "../vme_bridge.h"
37 static int __init ca91cx42_init(
void);
39 static void ca91cx42_remove(
struct pci_dev *);
40 static void __exit ca91cx42_exit(
void);
54 .id_table = ca91cx42_ids,
55 .probe = ca91cx42_probe,
56 .remove = ca91cx42_remove,
59 static u32 ca91cx42_DMA_irqhandler(
struct ca91cx42_driver *bridge)
66 static u32 ca91cx42_LM_irqhandler(
struct ca91cx42_driver *bridge,
u32 stat)
71 for (i = 0; i < 4; i++) {
72 if (stat & CA91CX42_LINT_LM[i]) {
75 serviced |= CA91CX42_LINT_LM[
i];
83 static u32 ca91cx42_MB_irqhandler(
struct ca91cx42_driver *bridge,
int mbox_mask)
90 static u32 ca91cx42_IACK_irqhandler(
struct ca91cx42_driver *bridge)
97 static u32 ca91cx42_VERR_irqhandler(
struct vme_bridge *ca91cx42_bridge)
100 struct ca91cx42_driver *bridge;
106 if (!(val & 0x00000800)) {
107 dev_err(ca91cx42_bridge->
parent,
"ca91cx42_VERR_irqhandler DMA "
108 "Read Error DGCS=%08X\n", val);
114 static u32 ca91cx42_LERR_irqhandler(
struct vme_bridge *ca91cx42_bridge)
117 struct ca91cx42_driver *bridge;
123 if (!(val & 0x00000800))
124 dev_err(ca91cx42_bridge->
parent,
"ca91cx42_LERR_irqhandler DMA "
125 "Read Error DGCS=%08X\n", val);
131 static u32 ca91cx42_VIRQ_irqhandler(
struct vme_bridge *ca91cx42_bridge,
134 int vec,
i, serviced = 0;
135 struct ca91cx42_driver *bridge;
140 for (i = 7; i > 0; i--) {
141 if (stat & (1 << i)) {
143 CA91CX42_V_STATID[i]) & 0xff;
147 serviced |= (1 <<
i);
158 struct ca91cx42_driver *bridge;
160 ca91cx42_bridge =
ptr;
174 serviced |= ca91cx42_DMA_irqhandler(bridge);
177 serviced |= ca91cx42_LM_irqhandler(bridge, stat);
179 serviced |= ca91cx42_MB_irqhandler(bridge, stat);
181 serviced |= ca91cx42_IACK_irqhandler(bridge);
183 serviced |= ca91cx42_VERR_irqhandler(ca91cx42_bridge);
185 serviced |= ca91cx42_LERR_irqhandler(ca91cx42_bridge);
190 serviced |= ca91cx42_VIRQ_irqhandler(ca91cx42_bridge, stat);
198 static int ca91cx42_irq_init(
struct vme_bridge *ca91cx42_bridge)
202 struct ca91cx42_driver *bridge;
225 dev_err(&pdev->
dev,
"Can't get assigned pci irq vector %02X\n",
245 static void ca91cx42_irq_exit(
struct ca91cx42_driver *bridge,
259 static int ca91cx42_iack_received(
struct ca91cx42_driver *bridge,
int level)
265 if (tmp & (1 << level))
274 static void ca91cx42_irq_set(
struct vme_bridge *ca91cx42_bridge,
int level,
280 struct ca91cx42_driver *bridge;
288 tmp &= ~CA91CX42_LINT_VIRQ[
level];
290 tmp |= CA91CX42_LINT_VIRQ[
level];
294 if ((state == 0) && (sync != 0)) {
302 static int ca91cx42_irq_generate(
struct vme_bridge *ca91cx42_bridge,
int level,
306 struct ca91cx42_driver *bridge;
322 tmp = tmp | (1 << (level + 24));
327 ca91cx42_iack_received(bridge, level));
331 tmp = tmp & ~(1 << (level + 24));
340 unsigned long long vme_base,
unsigned long long size,
344 unsigned int temp_ctl = 0;
345 unsigned int vme_bound, pci_offset;
347 struct ca91cx42_driver *bridge;
349 ca91cx42_bridge = image->
parent;
385 vme_bound = vme_base +
size;
386 pci_offset = pci_base - vme_base;
388 if ((i == 0) || (i == 4))
410 temp_ctl =
ioread32(bridge->
base + CA91CX42_VSI_CTL[i]);
446 unsigned long long *vme_base,
unsigned long long *size,
450 unsigned long long vme_bound, pci_offset;
451 struct ca91cx42_driver *bridge;
453 bridge = image->
parent->driver_priv;
457 if ((i == 0) || (i == 4))
458 granularity = 0x1000;
460 granularity = 0x10000;
465 *vme_base =
ioread32(bridge->
base + CA91CX42_VSI_BS[i]);
466 vme_bound =
ioread32(bridge->
base + CA91CX42_VSI_BD[i]);
467 pci_offset =
ioread32(bridge->
base + CA91CX42_VSI_TO[i]);
469 *pci_base = (
dma_addr_t)vme_base + pci_offset;
506 unsigned long long size)
508 unsigned long long existing_size;
513 ca91cx42_bridge = image->
parent;
526 if (existing_size == (size - 1))
529 if (existing_size != 0) {
541 "memory for resource name\n");
559 "resource for window %d size 0x%lx start 0x%lx\n",
560 image->
number, (
unsigned long)size,
568 dev_err(ca91cx42_bridge->
parent,
"Failed to remap resource\n");
598 unsigned long long vme_base,
unsigned long long size,
u32 aspace,
602 unsigned int i, granularity = 0;
603 unsigned int temp_ctl = 0;
604 unsigned long long pci_bound, vme_offset, pci_base;
606 struct ca91cx42_driver *bridge;
608 ca91cx42_bridge = image->
parent;
614 if ((i == 0) || (i == 4))
615 granularity = 0x1000;
617 granularity = 0x10000;
620 if (vme_base & (granularity - 1)) {
626 if (size & (granularity - 1)) {
633 spin_lock(&image->
lock);
639 retval = ca91cx42_alloc_resource(image, size);
641 spin_unlock(&image->
lock);
642 dev_err(ca91cx42_bridge->
parent,
"Unable to allocate memory "
643 "for resource name\n");
654 pci_bound = pci_base + size;
655 vme_offset = vme_base - pci_base;
658 temp_ctl =
ioread32(bridge->
base + CA91CX42_LSI_CTL[i]);
685 spin_unlock(&image->
lock);
717 spin_unlock(&image->
lock);
725 if (cycle & VME_SUPER)
727 if (cycle & VME_PROG)
743 spin_unlock(&image->
lock);
748 ca91cx42_free_resource(image);
755 int *enabled,
unsigned long long *vme_base,
unsigned long long *size,
759 unsigned long long pci_base, pci_bound, vme_offset;
760 struct ca91cx42_driver *bridge;
762 bridge = image->
parent->driver_priv;
769 vme_offset =
ioread32(bridge->
base + CA91CX42_LSI_TO[i]);
770 pci_bound =
ioread32(bridge->
base + CA91CX42_LSI_BD[i]);
772 *vme_base = pci_base + vme_offset;
773 *size = (
unsigned long long)(pci_bound - pci_base);
842 unsigned long long *vme_base,
unsigned long long *size,
u32 *aspace,
847 spin_lock(&image->
lock);
849 retval = __ca91cx42_master_get(image, enabled, vme_base, size, aspace,
852 spin_unlock(&image->
lock);
862 unsigned int done = 0;
863 unsigned int count32;
868 spin_lock(&image->
lock);
886 if ((count - done) < 2) {
887 *(
u8 *)(buf + done) =
ioread8(addr + done);
896 count32 = (count -
done) & ~0x3;
902 if ((count - done) & 0x2) {
906 if ((count - done) & 0x1) {
907 *(
u8 *)(buf + done) =
ioread8(addr + done);
912 spin_unlock(&image->
lock);
918 void *buf,
size_t count, loff_t offset)
922 unsigned int done = 0;
923 unsigned int count32;
928 spin_lock(&image->
lock);
940 if ((count - done) < 2) {
950 count32 = (count -
done) & ~0x3;
956 if ((count - done) & 0x2) {
960 if ((count - done) & 0x1) {
967 spin_unlock(&image->
lock);
973 unsigned int mask,
unsigned int compare,
unsigned int swap,
979 struct ca91cx42_driver *bridge;
982 bridge = image->
parent->driver_priv;
983 dev = image->
parent->parent;
992 spin_lock(&image->
lock);
997 if (pci_addr & 0x3) {
998 dev_err(dev,
"RMW Address not 4-byte aligned\n");
1022 spin_unlock(&image->
lock);
1039 dev = list->
parent->parent->parent;
1043 if (entry ==
NULL) {
1044 dev_err(dev,
"Failed to allocate memory for dma resource "
1052 dev_err(dev,
"Descriptor not aligned to 16 byte boundary as "
1073 dev_err(dev,
"Unsupported cycle type\n");
1078 if ((vme_attr->
cycle & ~(
VME_SCT | VME_BLT | VME_SUPER | VME_USER |
1079 VME_PROG | VME_DATA)) != 0) {
1081 dev_err(dev,
"Unsupported cycle type\n");
1090 dev_err(dev,
"Cannot perform transfer with this "
1091 "source-destination combination\n");
1097 if (vme_attr->
cycle & VME_BLT)
1101 switch (vme_attr->
dwidth) {
1115 dev_err(dev,
"Invalid data width\n");
1120 switch (vme_attr->
aspace) {
1137 dev_err(dev,
"Invalid address space\n");
1142 if (vme_attr->
cycle & VME_SUPER)
1144 if (vme_attr->
cycle & VME_PROG)
1161 prev->
descriptor.dcpp = desc_ptr & ~CA91CX42_DCPP_M;
1175 static int ca91cx42_dma_busy(
struct vme_bridge *ca91cx42_bridge)
1178 struct ca91cx42_driver *bridge;
1190 static int ca91cx42_dma_list_exec(
struct vme_dma_list *list)
1198 struct ca91cx42_driver *bridge;
1202 bridge = ctrlr->
parent->driver_priv;
1203 dev = ctrlr->
parent->parent;
1207 if (!(list_empty(&ctrlr->
running))) {
1248 ca91cx42_dma_busy(ctrlr->
parent));
1259 dev_err(dev,
"ca91c042: DMA Error. DGCS=%08X\n", val);
1272 static int ca91cx42_dma_list_empty(
struct vme_dma_list *list)
1295 unsigned long long lm_base,
u32 aspace,
u32 cycle)
1297 u32 temp_base, lm_ctl = 0;
1299 struct ca91cx42_driver *bridge;
1302 bridge = lm->
parent->driver_priv;
1303 dev = lm->
parent->parent;
1306 temp_base = (
u32)lm_base;
1307 if (temp_base & 0xffff) {
1308 dev_err(dev,
"Location monitor must be aligned to 64KB "
1316 for (i = 0; i < lm->
monitors; i++) {
1319 dev_err(dev,
"Location monitor callback attached, "
1337 dev_err(dev,
"Invalid address space\n");
1342 if (cycle & VME_SUPER)
1344 if (cycle & VME_USER)
1346 if (cycle & VME_PROG)
1348 if (cycle & VME_DATA)
1363 unsigned long long *lm_base,
u32 *aspace,
u32 *cycle)
1365 u32 lm_ctl, enabled = 0;
1366 struct ca91cx42_driver *bridge;
1368 bridge = lm->
parent->driver_priv;
1405 static int ca91cx42_lm_attach(
struct vme_lm_resource *lm,
int monitor,
1409 struct ca91cx42_driver *bridge;
1412 bridge = lm->
parent->driver_priv;
1413 dev = lm->
parent->parent;
1421 dev_err(dev,
"Location monitor not properly configured\n");
1428 dev_err(dev,
"Existing callback attached\n");
1437 tmp |= CA91CX42_LINT_LM[monitor];
1441 if ((lm_ctl & CA91CX42_LM_CTL_EN) == 0) {
1454 static int ca91cx42_lm_detach(
struct vme_lm_resource *lm,
int monitor)
1457 struct ca91cx42_driver *bridge;
1459 bridge = lm->
parent->driver_priv;
1465 tmp &= ~CA91CX42_LINT_LM[monitor];
1478 tmp &= ~CA91CX42_LM_CTL_EN;
1487 static int ca91cx42_slot_get(
struct vme_bridge *ca91cx42_bridge)
1490 struct ca91cx42_driver *bridge;
1504 static void *ca91cx42_alloc_consistent(
struct device *parent,
size_t size,
1515 static void ca91cx42_free_consistent(
struct device *parent,
size_t size,
1526 static int __init ca91cx42_init(
void)
1528 return pci_register_driver(&ca91cx42_driver);
1539 static int ca91cx42_crcsr_init(
struct vme_bridge *ca91cx42_bridge,
1542 unsigned int crcsr_addr;
1544 struct ca91cx42_driver *bridge;
1548 slot = ca91cx42_slot_get(ca91cx42_bridge);
1554 dev_info(&pdev->
dev,
"CR/CSR Offset: %d\n", slot);
1556 dev_err(&pdev->
dev,
"Slot number is unset, not configuring "
1565 dev_err(&pdev->
dev,
"Failed to allocate memory for CR/CSR "
1572 crcsr_addr = slot * (512 * 1024);
1582 static void ca91cx42_crcsr_exit(
struct vme_bridge *ca91cx42_bridge,
1586 struct ca91cx42_driver *bridge;
1608 struct ca91cx42_driver *ca91cx42_device;
1619 if (ca91cx42_bridge ==
NULL) {
1620 dev_err(&pdev->
dev,
"Failed to allocate memory for device "
1626 ca91cx42_device = kzalloc(
sizeof(
struct ca91cx42_driver),
GFP_KERNEL);
1628 if (ca91cx42_device ==
NULL) {
1629 dev_err(&pdev->
dev,
"Failed to allocate memory for device "
1640 dev_err(&pdev->
dev,
"Unable to enable device\n");
1647 dev_err(&pdev->
dev,
"Unable to reserve resources\n");
1654 if (!ca91cx42_device->
base) {
1655 dev_err(&pdev->
dev,
"Unable to remap CRG region\n");
1663 dev_err(&pdev->
dev,
"PCI_ID check failed\n");
1678 retval = ca91cx42_irq_init(ca91cx42_bridge);
1680 dev_err(&pdev->
dev,
"Chip Initialization failed.\n");
1689 if (master_image ==
NULL) {
1690 dev_err(&pdev->
dev,
"Failed to allocate memory for "
1691 "master resource structure\n");
1695 master_image->
parent = ca91cx42_bridge;
1697 master_image->
locked = 0;
1702 VME_SUPER | VME_USER | VME_PROG |
VME_DATA;
1716 if (slave_image ==
NULL) {
1717 dev_err(&pdev->
dev,
"Failed to allocate memory for "
1718 "slave resource structure\n");
1722 slave_image->
parent = ca91cx42_bridge;
1730 if (i == 0 || i == 4)
1734 VME_SUPER | VME_USER | VME_PROG |
VME_DATA;
1744 if (dma_ctrlr ==
NULL) {
1745 dev_err(&pdev->
dev,
"Failed to allocate memory for "
1746 "dma resource structure\n");
1750 dma_ctrlr->
parent = ca91cx42_bridge;
1756 INIT_LIST_HEAD(&dma_ctrlr->
pending);
1757 INIT_LIST_HEAD(&dma_ctrlr->
running);
1766 dev_err(&pdev->
dev,
"Failed to allocate memory for "
1767 "location monitor resource structure\n");
1771 lm->
parent = ca91cx42_bridge;
1778 ca91cx42_bridge->
slave_get = ca91cx42_slave_get;
1779 ca91cx42_bridge->
slave_set = ca91cx42_slave_set;
1780 ca91cx42_bridge->
master_get = ca91cx42_master_get;
1781 ca91cx42_bridge->
master_set = ca91cx42_master_set;
1782 ca91cx42_bridge->
master_read = ca91cx42_master_read;
1784 ca91cx42_bridge->
master_rmw = ca91cx42_master_rmw;
1788 ca91cx42_bridge->
irq_set = ca91cx42_irq_set;
1790 ca91cx42_bridge->
lm_set = ca91cx42_lm_set;
1791 ca91cx42_bridge->
lm_get = ca91cx42_lm_get;
1792 ca91cx42_bridge->
lm_attach = ca91cx42_lm_attach;
1793 ca91cx42_bridge->
lm_detach = ca91cx42_lm_detach;
1794 ca91cx42_bridge->
slot_get = ca91cx42_slot_get;
1799 dev_info(&pdev->
dev,
"Board is%s the VME system controller\n",
1802 ca91cx42_slot_get(ca91cx42_bridge));
1804 if (ca91cx42_crcsr_init(ca91cx42_bridge, pdev))
1805 dev_err(&pdev->
dev,
"CR/CSR configuration failed.\n");
1812 dev_err(&pdev->
dev,
"Chip Registration failed.\n");
1816 pci_set_drvdata(pdev, ca91cx42_bridge);
1821 ca91cx42_crcsr_exit(ca91cx42_bridge, pdev);
1849 kfree(master_image);
1852 ca91cx42_irq_exit(ca91cx42_device, pdev);
1861 kfree(ca91cx42_device);
1863 kfree(ca91cx42_bridge);
1869 static void ca91cx42_remove(
struct pci_dev *pdev)
1876 struct ca91cx42_driver *bridge;
1877 struct vme_bridge *ca91cx42_bridge = pci_get_drvdata(pdev);
1905 ca91cx42_crcsr_exit(ca91cx42_bridge, pdev);
1933 kfree(master_image);
1936 ca91cx42_irq_exit(bridge, pdev);
1944 kfree(ca91cx42_bridge);
1947 static void __exit ca91cx42_exit(
void)