16 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/errno.h>
22 #include <linux/pci.h>
23 #include <linux/poll.h>
27 #include <linux/sched.h>
28 #include <linux/slab.h>
29 #include <linux/time.h>
35 #include "../vme_bridge.h"
38 static int __init tsi148_init(
void);
40 static void tsi148_remove(
struct pci_dev *);
41 static void __exit tsi148_exit(
void);
57 .id_table = tsi148_ids,
58 .probe = tsi148_probe,
59 .remove = tsi148_remove,
62 static void reg_join(
unsigned int high,
unsigned int low,
65 *variable = (
unsigned long long)high << 32;
66 *variable |= (
unsigned long long)low;
69 static void reg_split(
unsigned long long variable,
unsigned int *
high,
72 *low = (
unsigned int)variable & 0xFFFFFFFF;
73 *high = (
unsigned int)(variable >> 32);
79 static u32 tsi148_DMA_irqhandler(
struct tsi148_driver *bridge,
99 static u32 tsi148_LM_irqhandler(
struct tsi148_driver *bridge,
u32 stat)
104 for (i = 0; i < 4; i++) {
105 if (stat & TSI148_LCSR_INTS_LMS[i]) {
108 serviced |= TSI148_LCSR_INTC_LMC[
i];
125 struct tsi148_driver *bridge;
129 for (i = 0; i < 4; i++) {
130 if (stat & TSI148_LCSR_INTS_MBS[i]) {
134 serviced |= TSI148_LCSR_INTC_MBC[
i];
144 static u32 tsi148_PERR_irqhandler(
struct vme_bridge *tsi148_bridge)
146 struct tsi148_driver *bridge;
150 dev_err(tsi148_bridge->
parent,
"PCI Exception at address: 0x%08x:%08x, "
151 "attributes: %08x\n",
156 dev_err(tsi148_bridge->
parent,
"PCI-X attribute reg: %08x, PCI-X split "
157 "completion reg: %08x\n",
169 static u32 tsi148_VERR_irqhandler(
struct vme_bridge *tsi148_bridge)
171 unsigned int error_addr_high, error_addr_low;
172 unsigned long long error_addr;
175 struct tsi148_driver *bridge;
183 reg_join(error_addr_high, error_addr_low, &error_addr);
198 "VMEbus Error reporting\n");
200 "0x%llx, attributes: %08x\n", error_addr, error_attrib);
212 static u32 tsi148_IACK_irqhandler(
struct tsi148_driver *bridge)
222 static u32 tsi148_VIRQ_irqhandler(
struct vme_bridge *tsi148_bridge,
225 int vec,
i, serviced = 0;
226 struct tsi148_driver *bridge;
230 for (i = 7; i > 0; i--) {
231 if (stat & (1 << i)) {
237 vec =
ioread8(bridge->
base + TSI148_LCSR_VIACK[i] + 3);
241 serviced |= (1 <<
i);
256 struct tsi148_driver *bridge;
275 serviced |= tsi148_DMA_irqhandler(bridge, stat);
280 serviced |= tsi148_LM_irqhandler(bridge, stat);
285 serviced |= tsi148_MB_irqhandler(tsi148_bridge, stat);
289 serviced |= tsi148_PERR_irqhandler(tsi148_bridge);
293 serviced |= tsi148_VERR_irqhandler(tsi148_bridge);
297 serviced |= tsi148_IACK_irqhandler(bridge);
304 serviced |= tsi148_VIRQ_irqhandler(tsi148_bridge, stat);
312 static int tsi148_irq_init(
struct vme_bridge *tsi148_bridge)
317 struct tsi148_driver *bridge;
334 "vector %02X\n", pdev->
irq);
378 static void tsi148_irq_exit(
struct vme_bridge *tsi148_bridge,
381 struct tsi148_driver *bridge = tsi148_bridge->
driver_priv;
397 static int tsi148_iack_received(
struct tsi148_driver *bridge)
412 static void tsi148_irq_set(
struct vme_bridge *tsi148_bridge,
int level,
417 struct tsi148_driver *bridge;
424 tmp &= ~TSI148_LCSR_INTEN_IRQEN[level - 1];
428 tmp &= ~TSI148_LCSR_INTEO_IRQEO[level - 1];
439 tmp |= TSI148_LCSR_INTEO_IRQEO[level - 1];
443 tmp |= TSI148_LCSR_INTEN_IRQEN[level - 1];
452 static int tsi148_irq_generate(
struct vme_bridge *tsi148_bridge,
int level,
456 struct tsi148_driver *bridge;
471 tmp = tmp | TSI148_LCSR_VICR_IRQL[
level];
476 tsi148_iack_received(bridge));
491 unsigned long long bound;
493 bound = address +
count;
506 if ((vme_err->
address >= address) &&
520 static void tsi148_clear_errors(
struct vme_bridge *tsi148_bridge,
521 u32 aspace,
unsigned long long address,
size_t count)
525 unsigned long long bound;
527 bound = address +
count;
541 if ((vme_err->
address >= address) &&
554 unsigned long long vme_base,
unsigned long long size,
558 unsigned int temp_ctl = 0;
559 unsigned int vme_base_low, vme_base_high;
560 unsigned int vme_bound_low, vme_bound_high;
561 unsigned int pci_offset_low, pci_offset_high;
562 unsigned long long vme_bound, pci_offset;
564 struct tsi148_driver *bridge;
566 tsi148_bridge = image->
parent;
600 reg_split(vme_base, &vme_base_high, &vme_base_low);
607 reg_split(vme_bound, &vme_bound_high, &vme_bound_low);
608 pci_offset = (
unsigned long long)pci_base - vme_base;
609 reg_split(pci_offset, &pci_offset_high, &pci_offset_low);
611 if (vme_base_low & (granularity - 1)) {
612 dev_err(tsi148_bridge->
parent,
"Invalid VME base alignment\n");
615 if (vme_bound_low & (granularity - 1)) {
616 dev_err(tsi148_bridge->
parent,
"Invalid VME bound alignment\n");
619 if (pci_offset_low & (granularity - 1)) {
661 temp_ctl &= ~(0x1F << 7);
704 unsigned long long *vme_base,
unsigned long long *size,
707 unsigned int i, granularity = 0,
ctl = 0;
708 unsigned int vme_base_low, vme_base_high;
709 unsigned int vme_bound_low, vme_bound_high;
710 unsigned int pci_offset_low, pci_offset_high;
711 unsigned long long vme_bound, pci_offset;
712 struct tsi148_driver *bridge;
714 bridge = image->
parent->driver_priv;
736 reg_join(vme_base_high, vme_base_low, vme_base);
737 reg_join(vme_bound_high, vme_bound_low, &vme_bound);
738 reg_join(pci_offset_high, pci_offset_low, &pci_offset);
740 *pci_base = (
dma_addr_t)vme_base + pci_offset;
754 granularity = 0x1000;
758 granularity = 0x10000;
762 granularity = 0x10000;
804 unsigned long long size)
806 unsigned long long existing_size;
811 tsi148_bridge = image->
parent;
819 if ((size != 0) && (existing_size == (size - 1)))
822 if (existing_size != 0) {
838 "memory for resource name\n");
856 "resource for window %d size 0x%lx start 0x%lx\n",
857 image->
number, (
unsigned long)size,
865 dev_err(tsi148_bridge->
parent,
"Failed to remap resource\n");
897 unsigned long long vme_base,
unsigned long long size,
u32 aspace,
902 unsigned int temp_ctl = 0;
903 unsigned int pci_base_low, pci_base_high;
904 unsigned int pci_bound_low, pci_bound_high;
905 unsigned int vme_offset_low, vme_offset_high;
906 unsigned long long pci_bound, vme_offset, pci_base;
908 struct tsi148_driver *bridge;
910 tsi148_bridge = image->
parent;
915 if (vme_base & 0xFFFF) {
922 if ((size == 0) && (enabled != 0)) {
924 "enabled windows\n");
929 spin_lock(&image->
lock);
935 retval = tsi148_alloc_resource(image, size);
937 spin_unlock(&image->
lock);
938 dev_err(tsi148_bridge->
parent,
"Unable to allocate memory for "
954 pci_bound = pci_base + (size - 0x10000);
955 vme_offset = vme_base - pci_base;
959 reg_split(pci_base, &pci_base_high, &pci_base_low);
960 reg_split(pci_bound, &pci_bound_high, &pci_bound_low);
961 reg_split(vme_offset, &vme_offset_high, &vme_offset_low);
963 if (pci_base_low & 0xFFFF) {
964 spin_unlock(&image->
lock);
965 dev_err(tsi148_bridge->
parent,
"Invalid PCI base alignment\n");
969 if (pci_bound_low & 0xFFFF) {
970 spin_unlock(&image->
lock);
971 dev_err(tsi148_bridge->
parent,
"Invalid PCI bound alignment\n");
975 if (vme_offset_low & 0xFFFF) {
976 spin_unlock(&image->
lock);
1007 if (cycle & VME_BLT) {
1011 if (cycle & VME_MBLT) {
1015 if (cycle & VME_2eVME) {
1019 if (cycle & VME_2eSST) {
1023 if (cycle & VME_2eSSTB) {
1025 "Broadcast Select Registers\n");
1040 spin_unlock(&image->
lock);
1077 spin_unlock(&image->
lock);
1084 temp_ctl &= ~(3<<4);
1085 if (cycle & VME_SUPER)
1087 if (cycle & VME_PROG)
1114 spin_unlock(&image->
lock);
1120 tsi148_free_resource(image);
1133 unsigned long long *vme_base,
unsigned long long *size,
u32 *aspace,
1136 unsigned int i,
ctl;
1137 unsigned int pci_base_low, pci_base_high;
1138 unsigned int pci_bound_low, pci_bound_high;
1139 unsigned int vme_offset_low, vme_offset_high;
1141 unsigned long long pci_base, pci_bound, vme_offset;
1142 struct tsi148_driver *bridge;
1144 bridge = image->
parent->driver_priv;
1165 reg_join(pci_base_high, pci_base_low, &pci_base);
1166 reg_join(pci_bound_high, pci_bound_low, &pci_bound);
1167 reg_join(vme_offset_high, vme_offset_low, &vme_offset);
1169 *vme_base = pci_base + vme_offset;
1170 *size = (
unsigned long long)(pci_bound - pci_base) + 0x10000;
1216 *cycle |= VME_2eVME;
1218 *cycle |= VME_2eSST;
1220 *cycle |= VME_2eSSTB;
1243 unsigned long long *vme_base,
unsigned long long *size,
u32 *aspace,
1248 spin_lock(&image->
lock);
1250 retval = __tsi148_master_get(image, enabled, vme_base, size, aspace,
1253 spin_unlock(&image->
lock);
1259 size_t count, loff_t
offset)
1262 unsigned long long vme_base,
size;
1263 u32 aspace, cycle, dwidth;
1267 unsigned int done = 0;
1268 unsigned int count32;
1270 tsi148_bridge = image->
parent;
1272 spin_lock(&image->
lock);
1289 if ((count - done) < 2) {
1290 *(
u8 *)(buf + done) =
ioread8(addr + done);
1299 count32 = (count -
done) & ~0x3;
1305 if ((count - done) & 0x2) {
1309 if ((count - done) & 0x1) {
1310 *(
u8 *)(buf + done) =
ioread8(addr + done);
1320 __tsi148_master_get(image, &enabled, &vme_base, &size, &aspace, &cycle,
1323 vme_err = tsi148_find_error(tsi148_bridge, aspace, vme_base + offset,
1325 if (vme_err !=
NULL) {
1326 dev_err(image->
parent->parent,
"First VME read error detected "
1327 "an at address 0x%llx\n", vme_err->
address);
1330 tsi148_clear_errors(tsi148_bridge, aspace, vme_base + offset,
1335 spin_unlock(&image->
lock);
1342 size_t count, loff_t offset)
1345 unsigned long long vme_base,
size;
1346 u32 aspace, cycle, dwidth;
1348 unsigned int done = 0;
1349 unsigned int count32;
1353 struct tsi148_driver *bridge;
1355 tsi148_bridge = image->
parent;
1359 spin_lock(&image->
lock);
1371 if ((count - done) < 2) {
1381 count32 = (count -
done) & ~0x3;
1387 if ((count - done) & 0x2) {
1391 if ((count - done) & 0x1) {
1417 __tsi148_master_get(image, &enabled, &vme_base, &size, &aspace, &cycle,
1422 vme_err = tsi148_find_error(tsi148_bridge, aspace, vme_base + offset,
1424 if (vme_err !=
NULL) {
1426 " an at address 0x%llx\n", vme_err->
address);
1429 tsi148_clear_errors(tsi148_bridge, aspace, vme_base + offset,
1434 spin_unlock(&image->
lock);
1445 unsigned int mask,
unsigned int compare,
unsigned int swap,
1449 unsigned int pci_addr_high, pci_addr_low;
1452 struct tsi148_driver *bridge;
1454 bridge = image->
parent->driver_priv;
1463 spin_lock(&image->
lock);
1470 reg_join(pci_addr_high, pci_addr_low, &pci_addr);
1471 reg_split(pci_addr + offset, &pci_addr_high, &pci_addr_low);
1493 spin_unlock(&image->
lock);
1524 if (cycle & VME_BLT)
1527 if (cycle & VME_MBLT)
1530 if (cycle & VME_2eVME)
1533 if (cycle & VME_2eSST)
1536 if (cycle & VME_2eSSTB) {
1537 dev_err(dev,
"Currently not setting Broadcast Select "
1551 dev_err(dev,
"Invalid data width\n");
1585 dev_err(dev,
"Invalid address space\n");
1590 if (cycle & VME_SUPER)
1592 if (cycle & VME_PROG)
1600 static int tsi148_dma_set_vme_dest_attributes(
struct device *dev,
__be32 *attr,
1621 if (cycle & VME_SCT)
1624 if (cycle & VME_BLT)
1627 if (cycle & VME_MBLT)
1630 if (cycle & VME_2eVME)
1633 if (cycle & VME_2eSST)
1636 if (cycle & VME_2eSSTB) {
1637 dev_err(dev,
"Currently not setting Broadcast Select "
1651 dev_err(dev,
"Invalid data width\n");
1685 dev_err(dev,
"Invalid address space\n");
1690 if (cycle & VME_SUPER)
1692 if (cycle & VME_PROG)
1709 u32 address_high, address_low,
val;
1716 tsi148_bridge = list->
parent->parent;
1720 if (entry ==
NULL) {
1721 dev_err(tsi148_bridge->
parent,
"Failed to allocate memory for "
1722 "dma resource structure\n");
1728 if ((
unsigned long)&entry->
descriptor & 0x7) {
1729 dev_err(tsi148_bridge->
parent,
"Descriptor not aligned to 8 "
1730 "byte boundary as required: %p\n",
1742 switch (src->
type) {
1762 reg_split((
unsigned long long)pci_attr->
address, &address_high,
1771 reg_split((
unsigned long long)vme_attr->
address, &address_high,
1777 retval = tsi148_dma_set_vme_src_attributes(
1795 switch (dest->
type) {
1799 reg_split((
unsigned long long)pci_attr->
address, &address_high,
1808 reg_split((
unsigned long long)vme_attr->
address, &address_high,
1814 retval = tsi148_dma_set_vme_dest_attributes(
1821 dev_err(tsi148_bridge->
parent,
"Invalid destination type\n");
1842 reg_split((
unsigned long long)entry->
dma_handle, &address_high,
1865 struct tsi148_driver *bridge;
1884 static int tsi148_dma_list_exec(
struct vme_dma_list *list)
1889 u32 bus_addr_high, bus_addr_low;
1892 struct tsi148_driver *bridge;
1896 tsi148_bridge = ctrlr->
parent;
1904 if (!list_empty(&ctrlr->
running)) {
1927 reg_split(entry->
dma_handle, &bus_addr_high, &bus_addr_low);
1942 tsi148_dma_busy(ctrlr->
parent, channel));
1952 dev_err(tsi148_bridge->
parent,
"DMA Error. DSTA=%08X\n", val);
1969 static int tsi148_dma_list_empty(
struct vme_dma_list *list)
1996 static int tsi148_lm_set(
struct vme_lm_resource *
lm,
unsigned long long lm_base,
1999 u32 lm_base_high, lm_base_low, lm_ctl = 0;
2002 struct tsi148_driver *bridge;
2004 tsi148_bridge = lm->
parent;
2011 for (i = 0; i < lm->
monitors; i++) {
2015 "callback attached, can't reset\n");
2040 if (cycle & VME_SUPER)
2042 if (cycle & VME_USER)
2044 if (cycle & VME_PROG)
2046 if (cycle & VME_DATA)
2049 reg_split(lm_base, &lm_base_high, &lm_base_low);
2064 unsigned long long *lm_base,
u32 *aspace,
u32 *cycle)
2066 u32 lm_base_high, lm_base_low, lm_ctl, enabled = 0;
2067 struct tsi148_driver *bridge;
2069 bridge = lm->
parent->driver_priv;
2077 reg_join(lm_base_high, lm_base_low, lm_base);
2119 struct tsi148_driver *bridge;
2121 tsi148_bridge = lm->
parent;
2131 dev_err(tsi148_bridge->
parent,
"Location monitor not properly "
2139 dev_err(tsi148_bridge->
parent,
"Existing callback attached\n");
2148 tmp |= TSI148_LCSR_INTEN_LMEN[monitor];
2152 tmp |= TSI148_LCSR_INTEO_LMEO[monitor];
2156 if ((lm_ctl & TSI148_LCSR_LMAT_EN) == 0) {
2172 struct tsi148_driver *bridge;
2174 bridge = lm->
parent->driver_priv;
2180 lm_en &= ~TSI148_LCSR_INTEN_LMEN[monitor];
2184 tmp &= ~TSI148_LCSR_INTEO_LMEO[monitor];
2197 tmp &= ~TSI148_LCSR_LMAT_EN;
2209 static int tsi148_slot_get(
struct vme_bridge *tsi148_bridge)
2212 struct tsi148_driver *bridge;
2225 static void *tsi148_alloc_consistent(
struct device *parent,
size_t size,
2236 static void tsi148_free_consistent(
struct device *parent,
size_t size,
2247 static int __init tsi148_init(
void)
2249 return pci_register_driver(&tsi148_driver);
2264 static int tsi148_crcsr_init(
struct vme_bridge *tsi148_bridge,
2267 u32 cbar, crat, vstat;
2268 u32 crcsr_bus_high, crcsr_bus_low;
2270 struct tsi148_driver *bridge;
2278 dev_err(tsi148_bridge->
parent,
"Failed to allocate memory for "
2285 reg_split(bridge->
crcsr_bus, &crcsr_bus_high, &crcsr_bus_low);
2294 vstat = tsi148_slot_get(tsi148_bridge);
2296 if (cbar != vstat) {
2316 retval = tsi148_master_set(bridge->
flush_image, 1,
2317 (vstat * 0x80000), 0x80000,
VME_CRCSR, VME_SCT,
2328 static void tsi148_crcsr_exit(
struct vme_bridge *tsi148_bridge,
2332 struct tsi148_driver *bridge;
2355 struct tsi148_driver *tsi148_device;
2365 if (tsi148_bridge ==
NULL) {
2366 dev_err(&pdev->
dev,
"Failed to allocate memory for device "
2372 tsi148_device = kzalloc(
sizeof(
struct tsi148_driver),
GFP_KERNEL);
2373 if (tsi148_device ==
NULL) {
2374 dev_err(&pdev->
dev,
"Failed to allocate memory for device "
2385 dev_err(&pdev->
dev,
"Unable to enable device\n");
2392 dev_err(&pdev->
dev,
"Unable to reserve resources\n");
2399 if (!tsi148_device->
base) {
2400 dev_err(&pdev->
dev,
"Unable to remap CRG region\n");
2408 dev_err(&pdev->
dev,
"CRG region check failed\n");
2424 retval = tsi148_irq_init(tsi148_bridge);
2426 dev_err(&pdev->
dev,
"Chip Initialization failed.\n");
2442 dev_err(&pdev->
dev,
"Failed to allocate memory for "
2443 "flush resource structure\n");
2447 tsi148_device->
flush_image->parent = tsi148_bridge;
2453 tsi148_device->
flush_image->cycle_attr = VME_SCT | VME_BLT |
2454 VME_MBLT | VME_2eVME | VME_2eSST | VME_2eSSTB |
2465 for (i = 0; i < master_num; i++) {
2468 if (master_image ==
NULL) {
2469 dev_err(&pdev->
dev,
"Failed to allocate memory for "
2470 "master resource structure\n");
2474 master_image->
parent = tsi148_bridge;
2476 master_image->
locked = 0;
2480 master_image->
cycle_attr = VME_SCT | VME_BLT | VME_MBLT |
2497 if (slave_image ==
NULL) {
2498 dev_err(&pdev->
dev,
"Failed to allocate memory for "
2499 "slave resource structure\n");
2503 slave_image->
parent = tsi148_bridge;
2510 slave_image->
cycle_attr = VME_SCT | VME_BLT | VME_MBLT |
2523 if (dma_ctrlr ==
NULL) {
2524 dev_err(&pdev->
dev,
"Failed to allocate memory for "
2525 "dma resource structure\n");
2529 dma_ctrlr->
parent = tsi148_bridge;
2537 INIT_LIST_HEAD(&dma_ctrlr->
pending);
2538 INIT_LIST_HEAD(&dma_ctrlr->
running);
2547 dev_err(&pdev->
dev,
"Failed to allocate memory for "
2548 "location monitor resource structure\n");
2552 lm->
parent = tsi148_bridge;
2559 tsi148_bridge->
slave_get = tsi148_slave_get;
2560 tsi148_bridge->
slave_set = tsi148_slave_set;
2561 tsi148_bridge->
master_get = tsi148_master_get;
2562 tsi148_bridge->
master_set = tsi148_master_set;
2565 tsi148_bridge->
master_rmw = tsi148_master_rmw;
2569 tsi148_bridge->
irq_set = tsi148_irq_set;
2571 tsi148_bridge->
lm_set = tsi148_lm_set;
2572 tsi148_bridge->
lm_get = tsi148_lm_get;
2573 tsi148_bridge->
lm_attach = tsi148_lm_attach;
2574 tsi148_bridge->
lm_detach = tsi148_lm_detach;
2575 tsi148_bridge->
slot_get = tsi148_slot_get;
2580 dev_info(&pdev->
dev,
"Board is%s the VME system controller\n",
2583 dev_info(&pdev->
dev,
"VME geographical address is %d\n",
2586 dev_info(&pdev->
dev,
"VME geographical address is set to %d\n",
2589 dev_info(&pdev->
dev,
"VME Write and flush and error check is %s\n",
2590 err_chk ?
"enabled" :
"disabled");
2592 if (tsi148_crcsr_init(tsi148_bridge, pdev)) {
2593 dev_err(&pdev->
dev,
"CR/CSR configuration failed.\n");
2599 dev_err(&pdev->
dev,
"Chip Registration failed.\n");
2603 pci_set_drvdata(pdev, tsi148_bridge);
2614 tsi148_crcsr_exit(tsi148_bridge, pdev);
2643 kfree(master_image);
2646 tsi148_irq_exit(tsi148_bridge, pdev);
2655 kfree(tsi148_device);
2657 kfree(tsi148_bridge);
2663 static void tsi148_remove(
struct pci_dev *pdev)
2671 struct tsi148_driver *bridge;
2672 struct vme_bridge *tsi148_bridge = pci_get_drvdata(pdev);
2677 dev_dbg(&pdev->
dev,
"Driver is being unloaded.\n");
2682 for (i = 0; i < 8; i++) {
2718 tsi148_irq_exit(tsi148_bridge, pdev);
2722 tsi148_crcsr_exit(tsi148_bridge, pdev);
2743 kfree(master_image);
2754 kfree(tsi148_bridge);
2757 static void __exit tsi148_exit(
void)