2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2003-2006 Silicon Graphics, Inc. All Rights Reserved.
9 #include <linux/types.h>
10 #include <linux/interrupt.h>
11 #include <linux/pci.h>
12 #include <asm/sn/sn_sal.h>
13 #include <asm/sn/addrs.h>
14 #include <asm/sn/io.h>
15 #include <asm/sn/pcidev.h>
16 #include <asm/sn/pcibus_provider_defs.h>
17 #include <asm/sn/tioce_provider.h>
18 #include <asm/sn/sn2/sn_hwperf.h>
23 * WAR for SGI PV 944642. For revA TIOCE, need to use the following recipe
24 * (taken from the above PV) before and after accessing tioce internal MMR's
25 * to avoid tioce lockups.
27 * The recipe as taken from the PV:
29 * if(mmr address < 0x45000) {
30 * if(mmr address == 0 or 0x80)
31 * mmr wrt or read address 0xc0
32 * else if(mmr address == 0x148 or 0x200)
33 * mmr wrt or read address 0x28
35 * mmr wrt or read address 0x158
37 * do desired mmr access (rd or wrt)
39 * if(mmr address == 0x100)
40 * mmr wrt or read address 0x38
41 * mmr wrt or read address 0xb050
43 * do desired mmr access
45 * According to hw, we can use reads instead of writes to the above addres
47 * Note this WAR can only to be used for accessing internal MMR's in the
48 * TIOCE Coretalk Address Range 0x0 - 0x07ff_ffff. This includes the
49 * "Local CE Registers and Memories" and "PCI Compatible Config Space" address
50 * spaces from table 2-1 of the "CE Programmer's Reference Overview" document.
52 * All registers defined in struct tioce will meet that criteria.
56 tioce_mmr_war_pre(struct tioce_kernel *kern, void *mmr_addr)
61 if (kern->ce_common->ce_rev != TIOCE_REV_A)
64 mmr_base = kern->ce_common->ce_pcibus.bs_base;
65 mmr_offset = (u64)mmr_addr - mmr_base;
67 if (mmr_offset < 0x45000) {
70 if (mmr_offset == 0 || mmr_offset == 0x80)
71 mmr_war_offset = 0xc0;
72 else if (mmr_offset == 0x148 || mmr_offset == 0x200)
73 mmr_war_offset = 0x28;
75 mmr_war_offset = 0x158;
77 readq_relaxed((void __iomem *)(mmr_base + mmr_war_offset));
82 tioce_mmr_war_post(struct tioce_kernel *kern, void *mmr_addr)
87 if (kern->ce_common->ce_rev != TIOCE_REV_A)
90 mmr_base = kern->ce_common->ce_pcibus.bs_base;
91 mmr_offset = (u64)mmr_addr - mmr_base;
93 if (mmr_offset < 0x45000) {
94 if (mmr_offset == 0x100)
95 readq_relaxed((void __iomem *)(mmr_base + 0x38));
96 readq_relaxed((void __iomem *)(mmr_base + 0xb050));
100 /* load mmr contents into a variable */
101 #define tioce_mmr_load(kern, mmrp, varp) do {\
102 tioce_mmr_war_pre(kern, mmrp); \
103 *(varp) = readq_relaxed(mmrp); \
104 tioce_mmr_war_post(kern, mmrp); \
107 /* store variable contents into mmr */
108 #define tioce_mmr_store(kern, mmrp, varp) do {\
109 tioce_mmr_war_pre(kern, mmrp); \
110 writeq(*varp, mmrp); \
111 tioce_mmr_war_post(kern, mmrp); \
114 /* store immediate value into mmr */
115 #define tioce_mmr_storei(kern, mmrp, val) do {\
116 tioce_mmr_war_pre(kern, mmrp); \
118 tioce_mmr_war_post(kern, mmrp); \
121 /* set bits (immediate value) into mmr */
122 #define tioce_mmr_seti(kern, mmrp, bits) do {\
124 tioce_mmr_load(kern, mmrp, &tmp); \
126 tioce_mmr_store(kern, mmrp, &tmp); \
129 /* clear bits (immediate value) into mmr */
130 #define tioce_mmr_clri(kern, mmrp, bits) do { \
132 tioce_mmr_load(kern, mmrp, &tmp); \
134 tioce_mmr_store(kern, mmrp, &tmp); \
138 * Bus address ranges for the 5 flavors of TIOCE DMA
141 #define TIOCE_D64_MIN 0x8000000000000000UL
142 #define TIOCE_D64_MAX 0xffffffffffffffffUL
143 #define TIOCE_D64_ADDR(a) ((a) >= TIOCE_D64_MIN)
145 #define TIOCE_D32_MIN 0x0000000080000000UL
146 #define TIOCE_D32_MAX 0x00000000ffffffffUL
147 #define TIOCE_D32_ADDR(a) ((a) >= TIOCE_D32_MIN && (a) <= TIOCE_D32_MAX)
149 #define TIOCE_M32_MIN 0x0000000000000000UL
150 #define TIOCE_M32_MAX 0x000000007fffffffUL
151 #define TIOCE_M32_ADDR(a) ((a) >= TIOCE_M32_MIN && (a) <= TIOCE_M32_MAX)
153 #define TIOCE_M40_MIN 0x0000004000000000UL
154 #define TIOCE_M40_MAX 0x0000007fffffffffUL
155 #define TIOCE_M40_ADDR(a) ((a) >= TIOCE_M40_MIN && (a) <= TIOCE_M40_MAX)
157 #define TIOCE_M40S_MIN 0x0000008000000000UL
158 #define TIOCE_M40S_MAX 0x000000ffffffffffUL
159 #define TIOCE_M40S_ADDR(a) ((a) >= TIOCE_M40S_MIN && (a) <= TIOCE_M40S_MAX)
162 * ATE manipulation macros.
165 #define ATE_PAGESHIFT(ps) (__ffs(ps))
166 #define ATE_PAGEMASK(ps) ((ps)-1)
168 #define ATE_PAGE(x, ps) ((x) >> ATE_PAGESHIFT(ps))
169 #define ATE_NPAGES(start, len, pagesize) \
170 (ATE_PAGE((start)+(len)-1, pagesize) - ATE_PAGE(start, pagesize) + 1)
172 #define ATE_VALID(ate) ((ate) & (1UL << 63))
173 #define ATE_MAKE(addr, ps, msi) \
174 (((addr) & ~ATE_PAGEMASK(ps)) | (1UL << 63) | ((msi)?(1UL << 62):0))
177 * Flavors of ate-based mapping supported by tioce_alloc_map()
180 #define TIOCE_ATE_M32 1
181 #define TIOCE_ATE_M40 2
182 #define TIOCE_ATE_M40S 3
184 #define KB(x) ((u64)(x) << 10)
185 #define MB(x) ((u64)(x) << 20)
186 #define GB(x) ((u64)(x) << 30)
189 * tioce_dma_d64 - create a DMA mapping using 64-bit direct mode
190 * @ct_addr: system coretalk address
192 * Map @ct_addr into 64-bit CE bus space. No device context is necessary
193 * and no CE mapping are consumed.
195 * Bits 53:0 come from the coretalk address. The remaining bits are set as
198 * 63 - must be 1 to indicate d64 mode to CE hardware
199 * 62 - barrier bit ... controlled with tioce_dma_barrier()
200 * 61 - msi bit ... specified through dma_flags
201 * 60:54 - reserved, MBZ
204 tioce_dma_d64(unsigned long ct_addr, int dma_flags)
208 bus_addr = ct_addr | (1UL << 63);
209 if (dma_flags & SN_DMA_MSI)
210 bus_addr |= (1UL << 61);
216 * pcidev_to_tioce - return misc ce related pointers given a pci_dev
217 * @pci_dev: pci device context
218 * @base: ptr to store struct tioce_mmr * for the CE holding this device
219 * @kernel: ptr to store struct tioce_kernel * for the CE holding this device
220 * @port: ptr to store the CE port number that this device is on
222 * Return pointers to various CE-related structures for the CE upstream of
226 pcidev_to_tioce(struct pci_dev *pdev, struct tioce **base,
227 struct tioce_kernel **kernel, int *port)
229 struct pcidev_info *pcidev_info;
230 struct tioce_common *ce_common;
231 struct tioce_kernel *ce_kernel;
233 pcidev_info = SN_PCIDEV_INFO(pdev);
234 ce_common = (struct tioce_common *)pcidev_info->pdi_pcibus_info;
235 ce_kernel = (struct tioce_kernel *)ce_common->ce_kernel_private;
238 *base = (struct tioce *)ce_common->ce_pcibus.bs_base;
243 * we use port as a zero-based value internally, even though the
244 * documentation is 1-based.
248 (pdev->bus->number < ce_kernel->ce_port1_secondary) ? 0 : 1;
252 * tioce_alloc_map - Given a coretalk address, map it to pcie bus address
253 * space using one of the various ATE-based address modes.
254 * @ce_kern: tioce context
255 * @type: map mode to use
256 * @port: 0-based port that the requesting device is downstream of
257 * @ct_addr: the coretalk address to map
258 * @len: number of bytes to map
260 * Given the addressing type, set up various paramaters that define the
261 * ATE pool to use. Search for a contiguous block of entries to cover the
262 * length, and if enough resources exist, fill in the ATE's and construct a
263 * tioce_dmamap struct to track the mapping.
266 tioce_alloc_map(struct tioce_kernel *ce_kern, int type, int port,
267 u64 ct_addr, int len, int dma_flags)
276 int msi_capable, msi_wanted;
280 struct tioce *ce_mmr;
282 struct tioce_dmamap *map;
284 ce_mmr = (struct tioce *)ce_kern->ce_common->ce_pcibus.bs_base;
289 * The first 64 entries of the ate3240 pool are dedicated to
290 * super-page (TIOCE_ATE_M40S) mode.
293 entries = TIOCE_NUM_M3240_ATES - 64;
294 ate_shadow = ce_kern->ce_ate3240_shadow;
295 ate_reg = ce_mmr->ce_ure_ate3240;
296 pagesize = ce_kern->ce_ate3240_pagesize;
297 bus_base = TIOCE_M32_MIN;
302 entries = TIOCE_NUM_M40_ATES;
303 ate_shadow = ce_kern->ce_ate40_shadow;
304 ate_reg = ce_mmr->ce_ure_ate40;
306 bus_base = TIOCE_M40_MIN;
311 * ate3240 entries 0-31 are dedicated to port1 super-page
312 * mappings. ate3240 entries 32-63 are dedicated to port2.
316 ate_shadow = ce_kern->ce_ate3240_shadow;
317 ate_reg = ce_mmr->ce_ure_ate3240;
319 bus_base = TIOCE_M40S_MIN;
326 msi_wanted = dma_flags & SN_DMA_MSI;
327 if (msi_wanted && !msi_capable)
330 nates = ATE_NPAGES(ct_addr, len, pagesize);
334 last = first + entries - nates;
335 for (i = first; i <= last; i++) {
336 if (ATE_VALID(ate_shadow[i]))
339 for (j = i; j < i + nates; j++)
340 if (ATE_VALID(ate_shadow[j]))
350 map = kzalloc(sizeof(struct tioce_dmamap), GFP_ATOMIC);
355 for (j = 0; j < nates; j++) {
358 ate = ATE_MAKE(addr, pagesize, msi_wanted);
359 ate_shadow[i + j] = ate;
360 tioce_mmr_storei(ce_kern, &ate_reg[i + j], ate);
365 map->nbytes = nates * pagesize;
366 map->ct_start = ct_addr & ~ATE_PAGEMASK(pagesize);
367 map->pci_start = bus_base + (i * pagesize);
368 map->ate_hw = &ate_reg[i];
369 map->ate_shadow = &ate_shadow[i];
370 map->ate_count = nates;
372 list_add(&map->ce_dmamap_list, &ce_kern->ce_dmamap_list);
374 return (map->pci_start + (ct_addr - map->ct_start));
378 * tioce_dma_d32 - create a DMA mapping using 32-bit direct mode
379 * @pdev: linux pci_dev representing the function
380 * @paddr: system physical address
382 * Map @paddr into 32-bit bus space of the CE associated with @pcidev_info.
385 tioce_dma_d32(struct pci_dev *pdev, u64 ct_addr, int dma_flags)
389 struct tioce *ce_mmr;
390 struct tioce_kernel *ce_kern;
395 if (dma_flags & SN_DMA_MSI)
398 ct_upper = ct_addr & ~0x3fffffffUL;
399 ct_lower = ct_addr & 0x3fffffffUL;
401 pcidev_to_tioce(pdev, &ce_mmr, &ce_kern, &port);
403 if (ce_kern->ce_port[port].dirmap_refcnt == 0) {
406 ce_kern->ce_port[port].dirmap_shadow = ct_upper;
407 tioce_mmr_storei(ce_kern, &ce_mmr->ce_ure_dir_map[port],
409 tmp = ce_mmr->ce_ure_dir_map[port];
412 dma_ok = (ce_kern->ce_port[port].dirmap_shadow == ct_upper);
415 ce_kern->ce_port[port].dirmap_refcnt++;
416 bus_addr = TIOCE_D32_MIN + ct_lower;
424 * tioce_dma_barrier - swizzle a TIOCE bus address to include or exclude
426 * @bus_addr: bus address to swizzle
428 * Given a TIOCE bus address, set the appropriate bit to indicate barrier
432 tioce_dma_barrier(u64 bus_addr, int on)
436 /* barrier not supported in M40/M40S mode */
437 if (TIOCE_M40_ADDR(bus_addr) || TIOCE_M40S_ADDR(bus_addr))
440 if (TIOCE_D64_ADDR(bus_addr))
441 barrier_bit = (1UL << 62);
442 else /* must be m32 or d32 */
443 barrier_bit = (1UL << 30);
445 return (on) ? (bus_addr | barrier_bit) : (bus_addr & ~barrier_bit);
449 * tioce_dma_unmap - release CE mapping resources
450 * @pdev: linux pci_dev representing the function
451 * @bus_addr: bus address returned by an earlier tioce_dma_map
452 * @dir: mapping direction (unused)
454 * Locate mapping resources associated with @bus_addr and release them.
455 * For mappings created using the direct modes there are no resources
459 tioce_dma_unmap(struct pci_dev *pdev, dma_addr_t bus_addr, int dir)
463 struct tioce_kernel *ce_kern;
464 struct tioce *ce_mmr;
467 bus_addr = tioce_dma_barrier(bus_addr, 0);
468 pcidev_to_tioce(pdev, &ce_mmr, &ce_kern, &port);
470 /* nothing to do for D64 */
472 if (TIOCE_D64_ADDR(bus_addr))
475 spin_lock_irqsave(&ce_kern->ce_lock, flags);
477 if (TIOCE_D32_ADDR(bus_addr)) {
478 if (--ce_kern->ce_port[port].dirmap_refcnt == 0) {
479 ce_kern->ce_port[port].dirmap_shadow = 0;
480 tioce_mmr_storei(ce_kern, &ce_mmr->ce_ure_dir_map[port],
484 struct tioce_dmamap *map;
486 list_for_each_entry(map, &ce_kern->ce_dmamap_list,
490 last = map->pci_start + map->nbytes - 1;
491 if (bus_addr >= map->pci_start && bus_addr <= last)
495 if (&map->ce_dmamap_list == &ce_kern->ce_dmamap_list) {
497 "%s: %s - no map found for bus_addr 0x%lx\n",
498 __FUNCTION__, pci_name(pdev), bus_addr);
499 } else if (--map->refcnt == 0) {
500 for (i = 0; i < map->ate_count; i++) {
501 map->ate_shadow[i] = 0;
502 tioce_mmr_storei(ce_kern, &map->ate_hw[i], 0);
505 list_del(&map->ce_dmamap_list);
510 spin_unlock_irqrestore(&ce_kern->ce_lock, flags);
514 * tioce_do_dma_map - map pages for PCI DMA
515 * @pdev: linux pci_dev representing the function
516 * @paddr: host physical address to map
517 * @byte_count: bytes to map
519 * This is the main wrapper for mapping host physical pages to CE PCI space.
520 * The mapping mode used is based on the device's dma_mask.
523 tioce_do_dma_map(struct pci_dev *pdev, u64 paddr, size_t byte_count,
524 int barrier, int dma_flags)
529 struct tioce_kernel *ce_kern;
530 struct tioce_dmamap *map;
534 dma_mask = (barrier) ? pdev->dev.coherent_dma_mask : pdev->dma_mask;
536 /* cards must be able to address at least 31 bits */
537 if (dma_mask < 0x7fffffffUL)
540 if (SN_DMA_ADDRTYPE(dma_flags) == SN_DMA_ADDR_PHYS)
541 ct_addr = PHYS_TO_TIODMA(paddr);
546 * If the device can generate 64 bit addresses, create a D64 map.
548 if (dma_mask == ~0UL) {
549 mapaddr = tioce_dma_d64(ct_addr, dma_flags);
554 pcidev_to_tioce(pdev, NULL, &ce_kern, &port);
556 spin_lock_irqsave(&ce_kern->ce_lock, flags);
559 * D64 didn't work ... See if we have an existing map that covers
560 * this address range. Must account for devices dma_mask here since
561 * an existing map might have been done in a mode using more pci
562 * address bits than this device can support.
564 list_for_each_entry(map, &ce_kern->ce_dmamap_list, ce_dmamap_list) {
567 last = map->ct_start + map->nbytes - 1;
568 if (ct_addr >= map->ct_start &&
569 ct_addr + byte_count - 1 <= last &&
570 map->pci_start <= dma_mask) {
572 mapaddr = map->pci_start + (ct_addr - map->ct_start);
578 * If we don't have a map yet, and the card can generate 40
579 * bit addresses, try the M40/M40S modes. Note these modes do not
580 * support a barrier bit, so if we need a consistent map these
583 if (!mapaddr && !barrier && dma_mask >= 0xffffffffffUL) {
585 * We have two options for 40-bit mappings: 16GB "super" ATE's
586 * and 64MB "regular" ATE's. We'll try both if needed for a
587 * given mapping but which one we try first depends on the
588 * size. For requests >64MB, prefer to use a super page with
589 * regular as the fallback. Otherwise, try in the reverse order.
592 if (byte_count > MB(64)) {
593 mapaddr = tioce_alloc_map(ce_kern, TIOCE_ATE_M40S,
594 port, ct_addr, byte_count,
598 tioce_alloc_map(ce_kern, TIOCE_ATE_M40, -1,
602 mapaddr = tioce_alloc_map(ce_kern, TIOCE_ATE_M40, -1,
607 tioce_alloc_map(ce_kern, TIOCE_ATE_M40S,
608 port, ct_addr, byte_count,
614 * 32-bit direct is the next mode to try
616 if (!mapaddr && dma_mask >= 0xffffffffUL)
617 mapaddr = tioce_dma_d32(pdev, ct_addr, dma_flags);
620 * Last resort, try 32-bit ATE-based map.
624 tioce_alloc_map(ce_kern, TIOCE_ATE_M32, -1, ct_addr,
625 byte_count, dma_flags);
627 spin_unlock_irqrestore(&ce_kern->ce_lock, flags);
630 if (mapaddr && barrier)
631 mapaddr = tioce_dma_barrier(mapaddr, 1);
637 * tioce_dma - standard pci dma map interface
638 * @pdev: pci device requesting the map
639 * @paddr: system physical address to map into pci space
640 * @byte_count: # bytes to map
642 * Simply call tioce_do_dma_map() to create a map with the barrier bit clear
646 tioce_dma(struct pci_dev *pdev, u64 paddr, size_t byte_count, int dma_flags)
648 return tioce_do_dma_map(pdev, paddr, byte_count, 0, dma_flags);
652 * tioce_dma_consistent - consistent pci dma map interface
653 * @pdev: pci device requesting the map
654 * @paddr: system physical address to map into pci space
655 * @byte_count: # bytes to map
657 * Simply call tioce_do_dma_map() to create a map with the barrier bit set
660 tioce_dma_consistent(struct pci_dev *pdev, u64 paddr, size_t byte_count, int dma_flags)
662 return tioce_do_dma_map(pdev, paddr, byte_count, 1, dma_flags);
666 * tioce_error_intr_handler - SGI TIO CE error interrupt handler
668 * @arg: pointer to tioce_common struct for the given CE
670 * Handle a CE error interrupt. Simply a wrapper around a SAL call which
671 * defers processing to the SGI prom.
672 */ static irqreturn_t
673 tioce_error_intr_handler(int irq, void *arg)
675 struct tioce_common *soft = arg;
676 struct ia64_sal_retval ret_stuff;
677 ret_stuff.status = 0;
680 SAL_CALL_NOLOCK(ret_stuff, (u64) SN_SAL_IOIF_ERROR_INTERRUPT,
681 soft->ce_pcibus.bs_persist_segment,
682 soft->ce_pcibus.bs_persist_busnum, 0, 0, 0, 0, 0);
685 panic("tioce_error_intr_handler: Fatal TIOCE error");
691 * tioce_reserve_m32 - reserve M32 ate's for the indicated address range
692 * @tioce_kernel: TIOCE context to reserve ate's for
693 * @base: starting bus address to reserve
694 * @limit: last bus address to reserve
696 * If base/limit falls within the range of bus space mapped through the
697 * M32 space, reserve the resources corresponding to the range.
700 tioce_reserve_m32(struct tioce_kernel *ce_kern, u64 base, u64 limit)
702 int ate_index, last_ate, ps;
703 struct tioce *ce_mmr;
705 ce_mmr = (struct tioce *)ce_kern->ce_common->ce_pcibus.bs_base;
706 ps = ce_kern->ce_ate3240_pagesize;
707 ate_index = ATE_PAGE(base, ps);
708 last_ate = ate_index + ATE_NPAGES(base, limit-base+1, ps) - 1;
713 if (last_ate >= TIOCE_NUM_M3240_ATES)
714 last_ate = TIOCE_NUM_M3240_ATES - 1;
716 while (ate_index <= last_ate) {
719 ate = ATE_MAKE(0xdeadbeef, ps, 0);
720 ce_kern->ce_ate3240_shadow[ate_index] = ate;
721 tioce_mmr_storei(ce_kern, &ce_mmr->ce_ure_ate3240[ate_index],
728 * tioce_kern_init - init kernel structures related to a given TIOCE
729 * @tioce_common: ptr to a cached tioce_common struct that originated in prom
731 static struct tioce_kernel *
732 tioce_kern_init(struct tioce_common *tioce_common)
738 unsigned int seg, bus;
739 struct tioce *tioce_mmr;
740 struct tioce_kernel *tioce_kern;
742 tioce_kern = kzalloc(sizeof(struct tioce_kernel), GFP_KERNEL);
747 tioce_kern->ce_common = tioce_common;
748 spin_lock_init(&tioce_kern->ce_lock);
749 INIT_LIST_HEAD(&tioce_kern->ce_dmamap_list);
750 tioce_common->ce_kernel_private = (u64) tioce_kern;
753 * Determine the secondary bus number of the port2 logical PPB.
754 * This is used to decide whether a given pci device resides on
755 * port1 or port2. Note: We don't have enough plumbing set up
756 * here to use pci_read_config_xxx() so use the raw_pci_ops vector.
759 seg = tioce_common->ce_pcibus.bs_persist_segment;
760 bus = tioce_common->ce_pcibus.bs_persist_busnum;
762 raw_pci_ops->read(seg, bus, PCI_DEVFN(2, 0), PCI_SECONDARY_BUS, 1,&tmp);
763 tioce_kern->ce_port1_secondary = (u8) tmp;
766 * Set PMU pagesize to the largest size available, and zero out
770 tioce_mmr = (struct tioce *)tioce_common->ce_pcibus.bs_base;
771 tioce_mmr_clri(tioce_kern, &tioce_mmr->ce_ure_page_map,
772 CE_URE_PAGESIZE_MASK);
773 tioce_mmr_seti(tioce_kern, &tioce_mmr->ce_ure_page_map,
774 CE_URE_256K_PAGESIZE);
775 ps = tioce_kern->ce_ate3240_pagesize = KB(256);
777 for (i = 0; i < TIOCE_NUM_M40_ATES; i++) {
778 tioce_kern->ce_ate40_shadow[i] = 0;
779 tioce_mmr_storei(tioce_kern, &tioce_mmr->ce_ure_ate40[i], 0);
782 for (i = 0; i < TIOCE_NUM_M3240_ATES; i++) {
783 tioce_kern->ce_ate3240_shadow[i] = 0;
784 tioce_mmr_storei(tioce_kern, &tioce_mmr->ce_ure_ate3240[i], 0);
788 * Reserve ATE's corresponding to reserved address ranges. These
791 * Memory space covered by each PPB mem base/limit register
792 * Memory space covered by each PPB prefetch base/limit register
794 * These bus ranges are for pio (downstream) traffic only, and so
795 * cannot be used for DMA.
798 for (dev = 1; dev <= 2; dev++) {
803 raw_pci_ops->read(seg, bus, PCI_DEVFN(dev, 0),
804 PCI_MEMORY_BASE, 2, &tmp);
805 base = (u64)tmp << 16;
807 raw_pci_ops->read(seg, bus, PCI_DEVFN(dev, 0),
808 PCI_MEMORY_LIMIT, 2, &tmp);
809 limit = (u64)tmp << 16;
813 tioce_reserve_m32(tioce_kern, base, limit);
816 * prefetch mem base/limit. The tioce ppb's have 64-bit
817 * decoders, so read the upper portions w/o checking the
821 raw_pci_ops->read(seg, bus, PCI_DEVFN(dev, 0),
822 PCI_PREF_MEMORY_BASE, 2, &tmp);
823 base = ((u64)tmp & PCI_PREF_RANGE_MASK) << 16;
825 raw_pci_ops->read(seg, bus, PCI_DEVFN(dev, 0),
826 PCI_PREF_BASE_UPPER32, 4, &tmp);
827 base |= (u64)tmp << 32;
829 raw_pci_ops->read(seg, bus, PCI_DEVFN(dev, 0),
830 PCI_PREF_MEMORY_LIMIT, 2, &tmp);
832 limit = ((u64)tmp & PCI_PREF_RANGE_MASK) << 16;
835 raw_pci_ops->read(seg, bus, PCI_DEVFN(dev, 0),
836 PCI_PREF_LIMIT_UPPER32, 4, &tmp);
837 limit |= (u64)tmp << 32;
839 if ((base < limit) && TIOCE_M32_ADDR(base))
840 tioce_reserve_m32(tioce_kern, base, limit);
847 * tioce_force_interrupt - implement altix force_interrupt() backend for CE
848 * @sn_irq_info: sn asic irq that we need an interrupt generated for
850 * Given an sn_irq_info struct, set the proper bit in ce_adm_force_int to
851 * force a secondary interrupt to be generated. This is to work around an
852 * asic issue where there is a small window of opportunity for a legacy device
853 * interrupt to be lost.
856 tioce_force_interrupt(struct sn_irq_info *sn_irq_info)
858 struct pcidev_info *pcidev_info;
859 struct tioce_common *ce_common;
860 struct tioce_kernel *ce_kern;
861 struct tioce *ce_mmr;
864 if (!sn_irq_info->irq_bridge)
867 if (sn_irq_info->irq_bridge_type != PCIIO_ASIC_TYPE_TIOCE)
870 pcidev_info = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
874 ce_common = (struct tioce_common *)pcidev_info->pdi_pcibus_info;
875 ce_mmr = (struct tioce *)ce_common->ce_pcibus.bs_base;
876 ce_kern = (struct tioce_kernel *)ce_common->ce_kernel_private;
879 * TIOCE Rev A workaround (PV 945826), force an interrupt by writing
880 * the TIO_INTx register directly (1/26/2006)
882 if (ce_common->ce_rev == TIOCE_REV_A) {
883 u64 int_bit_mask = (1ULL << sn_irq_info->irq_int_bit);
886 tioce_mmr_load(ce_kern, &ce_mmr->ce_adm_int_status, &status);
887 if (status & int_bit_mask) {
888 u64 force_irq = (1 << 8) | sn_irq_info->irq_irq;
889 u64 ctalk = sn_irq_info->irq_xtalkaddr;
892 nasid = (ctalk & CTALK_NASID_MASK) >> CTALK_NASID_SHFT;
893 offset = (ctalk & CTALK_NODE_OFFSET);
894 HUB_S(TIO_IOSPACE_ADDR(nasid, offset), force_irq);
901 * irq_int_bit is originally set up by prom, and holds the interrupt
902 * bit shift (not mask) as defined by the bit definitions in the
903 * ce_adm_int mmr. These shifts are not the same for the
904 * ce_adm_force_int register, so do an explicit mapping here to make
908 switch (sn_irq_info->irq_int_bit) {
909 case CE_ADM_INT_PCIE_PORT1_DEV_A_SHFT:
910 force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT1_DEV_A_SHFT;
912 case CE_ADM_INT_PCIE_PORT1_DEV_B_SHFT:
913 force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT1_DEV_B_SHFT;
915 case CE_ADM_INT_PCIE_PORT1_DEV_C_SHFT:
916 force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT1_DEV_C_SHFT;
918 case CE_ADM_INT_PCIE_PORT1_DEV_D_SHFT:
919 force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT1_DEV_D_SHFT;
921 case CE_ADM_INT_PCIE_PORT2_DEV_A_SHFT:
922 force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT2_DEV_A_SHFT;
924 case CE_ADM_INT_PCIE_PORT2_DEV_B_SHFT:
925 force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT2_DEV_B_SHFT;
927 case CE_ADM_INT_PCIE_PORT2_DEV_C_SHFT:
928 force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT2_DEV_C_SHFT;
930 case CE_ADM_INT_PCIE_PORT2_DEV_D_SHFT:
931 force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT2_DEV_D_SHFT;
936 tioce_mmr_storei(ce_kern, &ce_mmr->ce_adm_force_int, force_int_val);
940 * tioce_target_interrupt - implement set_irq_affinity for tioce resident
941 * functions. Note: only applies to line interrupts, not MSI's.
943 * @sn_irq_info: SN IRQ context
945 * Given an sn_irq_info, set the associated CE device's interrupt destination
946 * register. Since the interrupt destination registers are on a per-ce-slot
947 * basis, this will retarget line interrupts for all functions downstream of
951 tioce_target_interrupt(struct sn_irq_info *sn_irq_info)
953 struct pcidev_info *pcidev_info;
954 struct tioce_common *ce_common;
955 struct tioce_kernel *ce_kern;
956 struct tioce *ce_mmr;
960 pcidev_info = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
964 ce_common = (struct tioce_common *)pcidev_info->pdi_pcibus_info;
965 ce_mmr = (struct tioce *)ce_common->ce_pcibus.bs_base;
966 ce_kern = (struct tioce_kernel *)ce_common->ce_kernel_private;
968 bit = sn_irq_info->irq_int_bit;
970 tioce_mmr_seti(ce_kern, &ce_mmr->ce_adm_int_mask, (1UL << bit));
971 vector = (u64)sn_irq_info->irq_irq << INTR_VECTOR_SHFT;
972 vector |= sn_irq_info->irq_xtalkaddr;
973 tioce_mmr_storei(ce_kern, &ce_mmr->ce_adm_int_dest[bit], vector);
974 tioce_mmr_clri(ce_kern, &ce_mmr->ce_adm_int_mask, (1UL << bit));
976 tioce_force_interrupt(sn_irq_info);
980 * tioce_bus_fixup - perform final PCI fixup for a TIO CE bus
981 * @prom_bussoft: Common prom/kernel struct representing the bus
983 * Replicates the tioce_common pointed to by @prom_bussoft in kernel
984 * space. Allocates and initializes a kernel-only area for a given CE,
985 * and sets up an irq for handling CE error interrupts.
987 * On successful setup, returns the kernel version of tioce_common back to
991 tioce_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *controller)
994 cnodeid_t my_cnode, mem_cnode;
995 struct tioce_common *tioce_common;
996 struct tioce_kernel *tioce_kern;
997 struct tioce *tioce_mmr;
1000 * Allocate kernel bus soft and copy from prom.
1003 tioce_common = kzalloc(sizeof(struct tioce_common), GFP_KERNEL);
1007 memcpy(tioce_common, prom_bussoft, sizeof(struct tioce_common));
1008 tioce_common->ce_pcibus.bs_base |= __IA64_UNCACHED_OFFSET;
1010 tioce_kern = tioce_kern_init(tioce_common);
1011 if (tioce_kern == NULL) {
1012 kfree(tioce_common);
1017 * Clear out any transient errors before registering the error
1018 * interrupt handler.
1021 tioce_mmr = (struct tioce *)tioce_common->ce_pcibus.bs_base;
1022 tioce_mmr_seti(tioce_kern, &tioce_mmr->ce_adm_int_status_alias, ~0ULL);
1023 tioce_mmr_seti(tioce_kern, &tioce_mmr->ce_adm_error_summary_alias,
1025 tioce_mmr_seti(tioce_kern, &tioce_mmr->ce_dre_comp_err_addr, 0ULL);
1027 if (request_irq(SGI_PCIASIC_ERROR,
1028 tioce_error_intr_handler,
1029 IRQF_SHARED, "TIOCE error", (void *)tioce_common))
1031 "%s: Unable to get irq %d. "
1032 "Error interrupts won't be routed for "
1033 "TIOCE bus %04x:%02x\n",
1034 __FUNCTION__, SGI_PCIASIC_ERROR,
1035 tioce_common->ce_pcibus.bs_persist_segment,
1036 tioce_common->ce_pcibus.bs_persist_busnum);
1039 * identify closest nasid for memory allocations
1042 my_nasid = NASID_GET(tioce_common->ce_pcibus.bs_base);
1043 my_cnode = nasid_to_cnodeid(my_nasid);
1045 if (sn_hwperf_get_nearest_node(my_cnode, &mem_cnode, NULL) < 0) {
1046 printk(KERN_WARNING "tioce_bus_fixup: failed to find "
1047 "closest node with MEM to TIO node %d\n", my_cnode);
1048 mem_cnode = (cnodeid_t)-1; /* use any node */
1051 controller->node = mem_cnode;
1053 return tioce_common;
1056 static struct sn_pcibus_provider tioce_pci_interfaces = {
1057 .dma_map = tioce_dma,
1058 .dma_map_consistent = tioce_dma_consistent,
1059 .dma_unmap = tioce_dma_unmap,
1060 .bus_fixup = tioce_bus_fixup,
1061 .force_interrupt = tioce_force_interrupt,
1062 .target_interrupt = tioce_target_interrupt
1066 * tioce_init_provider - init SN PCI provider ops for TIO CE
1069 tioce_init_provider(void)
1071 sn_pci_provider[PCIIO_ASIC_TYPE_TIOCE] = &tioce_pci_interfaces;