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) 2001-2005 Silicon Graphics, Inc. All rights reserved.
9 #include <linux/types.h>
10 #include <linux/pci.h>
11 #include <asm/sn/addrs.h>
12 #include <asm/sn/geo.h>
13 #include <asm/sn/pcibr_provider.h>
14 #include <asm/sn/pcibus_provider_defs.h>
15 #include <asm/sn/pcidev.h>
16 #include <asm/sn/pic.h>
17 #include <asm/sn/sn_sal.h>
18 #include <asm/sn/tiocp.h>
20 #include "xtalk/xwidgetdev.h"
21 #include "xtalk/hubdev.h"
23 extern int sn_ioif_inited
;
25 /* =====================================================================
28 * The Bridge ASIC provides three methods of doing DMA: via a "direct map"
29 * register available in 32-bit PCI space (which selects a contiguous 2G
30 * address space on some other widget), via "direct" addressing via 64-bit
31 * PCI space (all destination information comes from the PCI address,
32 * including transfer attributes), and via a "mapped" region that allows
33 * a bunch of different small mappings to be established with the PMU.
35 * For efficiency, we most prefer to use the 32bit direct mapping facility,
36 * since it requires no resource allocations. The advantage of using the
37 * PMU over the 64-bit direct is that single-cycle PCI addressing can be
38 * used; the advantage of using 64-bit direct over PMU addressing is that
39 * we do not have to allocate entries in the PMU.
43 pcibr_dmamap_ate32(struct pcidev_info
*info
,
44 u64 paddr
, size_t req_size
, u64 flags
)
47 struct pcidev_info
*pcidev_info
= info
->pdi_host_pcidev_info
;
48 struct pcibus_info
*pcibus_info
= (struct pcibus_info
*)pcidev_info
->
50 u8 internal_device
= (PCI_SLOT(pcidev_info
->pdi_host_pcidev_info
->
51 pdi_linux_pcidev
->devfn
)) - 1;
54 u64 ate_flags
= flags
| PCI32_ATE_V
;
60 /* PIC in PCI-X mode does not supports 32bit PageMap mode */
61 if (IS_PIC_SOFT(pcibus_info
) && IS_PCIX(pcibus_info
)) {
65 /* Calculate the number of ATEs needed. */
66 if (!(MINIMAL_ATE_FLAG(paddr
, req_size
))) {
67 ate_count
= IOPG((IOPGSIZE
- 1) /* worst case start offset */
68 +req_size
/* max mapping bytes */
69 - 1) + 1; /* round UP */
70 } else { /* assume requested target is page aligned */
71 ate_count
= IOPG(req_size
/* max mapping bytes */
72 - 1) + 1; /* round UP */
75 /* Get the number of ATEs required. */
76 ate_index
= pcibr_ate_alloc(pcibus_info
, ate_count
);
80 /* In PCI-X mode, Prefetch not supported */
81 if (IS_PCIX(pcibus_info
))
82 ate_flags
&= ~(PCI32_ATE_PREF
);
85 IS_PIC_SOFT(pcibus_info
) ? PHYS_TO_DMA(paddr
) :
86 PHYS_TO_TIODMA(paddr
);
87 offset
= IOPGOFF(xio_addr
);
88 ate
= ate_flags
| (xio_addr
- offset
);
90 /* If PIC, put the targetid in the ATE */
91 if (IS_PIC_SOFT(pcibus_info
)) {
92 ate
|= (pcibus_info
->pbi_hub_xid
<< PIC_ATE_TARGETID_SHFT
);
94 ate_write(pcibus_info
, ate_index
, ate_count
, ate
);
97 * Set up the DMA mapped Address.
99 pci_addr
= PCI32_MAPPED_BASE
+ offset
+ IOPGSIZE
* ate_index
;
102 * If swap was set in device in pcibr_endian_set()
103 * we need to turn swapping on.
105 if (pcibus_info
->pbi_devreg
[internal_device
] & PCIBR_DEV_SWAP_DIR
)
106 ATE_SWAP_ON(pci_addr
);
112 pcibr_dmatrans_direct64(struct pcidev_info
* info
, u64 paddr
,
115 struct pcibus_info
*pcibus_info
= (struct pcibus_info
*)
116 ((info
->pdi_host_pcidev_info
)->pdi_pcibus_info
);
119 /* Translate to Crosstalk View of Physical Address */
120 pci_addr
= (IS_PIC_SOFT(pcibus_info
) ? PHYS_TO_DMA(paddr
) :
121 PHYS_TO_TIODMA(paddr
)) | dma_attributes
;
123 /* Handle Bus mode */
124 if (IS_PCIX(pcibus_info
))
125 pci_addr
&= ~PCI64_ATTR_PREF
;
127 /* Handle Bridge Chipset differences */
128 if (IS_PIC_SOFT(pcibus_info
)) {
131 pbi_hub_xid
<< PIC_PCI64_ATTR_TARG_SHFT
);
133 pci_addr
|= TIOCP_PCI64_CMDTYPE_MEM
;
135 /* If PCI mode, func zero uses VCHAN0, every other func uses VCHAN1 */
136 if (!IS_PCIX(pcibus_info
) && PCI_FUNC(info
->pdi_linux_pcidev
->devfn
))
137 pci_addr
|= PCI64_ATTR_VIRTUAL
;
143 pcibr_dmatrans_direct32(struct pcidev_info
* info
,
144 u64 paddr
, size_t req_size
, u64 flags
)
146 struct pcidev_info
*pcidev_info
= info
->pdi_host_pcidev_info
;
147 struct pcibus_info
*pcibus_info
= (struct pcibus_info
*)pcidev_info
->
155 if (IS_PCIX(pcibus_info
)) {
159 xio_addr
= IS_PIC_SOFT(pcibus_info
) ? PHYS_TO_DMA(paddr
) :
160 PHYS_TO_TIODMA(paddr
);
162 xio_base
= pcibus_info
->pbi_dir_xbase
;
163 offset
= xio_addr
- xio_base
;
164 endoff
= req_size
+ offset
;
165 if ((req_size
> (1ULL << 31)) || /* Too Big */
166 (xio_addr
< xio_base
) || /* Out of range for mappings */
167 (endoff
> (1ULL << 31))) { /* Too Big */
171 return PCI32_DIRECT_BASE
| offset
;
175 * Wrapper routine for free'ing DMA maps
176 * DMA mappings for Direct 64 and 32 do not have any DMA maps.
179 pcibr_dma_unmap(struct pci_dev
*hwdev
, dma_addr_t dma_handle
, int direction
)
181 struct pcidev_info
*pcidev_info
= SN_PCIDEV_INFO(hwdev
);
182 struct pcibus_info
*pcibus_info
=
183 (struct pcibus_info
*)pcidev_info
->pdi_pcibus_info
;
185 if (IS_PCI32_MAPPED(dma_handle
)) {
189 IOPG((ATE_SWAP_OFF(dma_handle
) - PCI32_MAPPED_BASE
));
190 pcibr_ate_free(pcibus_info
, ate_index
);
195 * On SN systems there is a race condition between a PIO read response and
196 * DMA's. In rare cases, the read response may beat the DMA, causing the
197 * driver to think that data in memory is complete and meaningful. This code
198 * eliminates that race. This routine is called by the PIO read routines
199 * after doing the read. For PIC this routine then forces a fake interrupt
200 * on another line, which is logically associated with the slot that the PIO
201 * is addressed to. It then spins while watching the memory location that
202 * the interrupt is targetted to. When the interrupt response arrives, we
203 * are sure that the DMA has landed in memory and it is safe for the driver
204 * to proceed. For TIOCP use the Device(x) Write Request Buffer Flush
205 * Bridge register since it ensures the data has entered the coherence domain,
206 * unlike the PIC Device(x) Write Request Buffer Flush register.
209 void sn_dma_flush(u64 addr
)
217 struct hubdev_info
*hubinfo
;
218 struct sn_flush_device_kernel
*p
;
219 struct sn_flush_device_common
*common
;
220 struct sn_flush_nasid_entry
*flush_nasid_list
;
225 nasid
= NASID_GET(addr
);
226 if (-1 == nasid_to_cnodeid(nasid
))
229 hubinfo
= (NODEPDA(nasid_to_cnodeid(nasid
)))->pdinfo
;
235 flush_nasid_list
= &hubinfo
->hdi_flush_nasid_list
;
236 if (flush_nasid_list
->widget_p
== NULL
)
239 is_tio
= (nasid
& 1);
245 else if (TIO_BWIN_WINDOWNUM(addr
))
246 itte_index
= TIO_BWIN_WINDOWNUM(addr
);
250 if (itte_index
>= 0) {
251 itte
= flush_nasid_list
->iio_itte
[itte_index
];
252 if (! TIO_ITTE_VALID(itte
))
254 wid_num
= TIO_ITTE_WIDGET(itte
);
256 wid_num
= TIO_SWIN_WIDGETNUM(addr
);
258 if (BWIN_WINDOWNUM(addr
)) {
259 itte
= flush_nasid_list
->iio_itte
[BWIN_WINDOWNUM(addr
)];
260 wid_num
= IIO_ITTE_WIDGET(itte
);
262 wid_num
= SWIN_WIDGETNUM(addr
);
264 if (flush_nasid_list
->widget_p
[wid_num
] == NULL
)
266 p
= &flush_nasid_list
->widget_p
[wid_num
][0];
268 /* find a matching BAR */
269 for (i
= 0; i
< DEV_PER_WIDGET
; i
++,p
++) {
271 for (j
= 0; j
< PCI_ROM_RESOURCE
; j
++) {
272 if (common
->sfdl_bar_list
[j
].start
== 0)
274 if (addr
>= common
->sfdl_bar_list
[j
].start
275 && addr
<= common
->sfdl_bar_list
[j
].end
)
278 if (j
< PCI_ROM_RESOURCE
&& common
->sfdl_bar_list
[j
].start
!= 0)
282 /* if no matching BAR, return without doing anything. */
283 if (i
== DEV_PER_WIDGET
)
287 * For TIOCP use the Device(x) Write Request Buffer Flush Bridge
288 * register since it ensures the data has entered the coherence
289 * domain, unlike PIC.
293 * Note: devices behind TIOCE should never be matched in the
294 * above code, and so the following code is PIC/CP centric.
295 * If CE ever needs the sn_dma_flush mechanism, we will have
296 * to account for that here and in tioce_bus_fixup().
298 u32 tio_id
= HUB_L(TIO_IOSPACE_ADDR(nasid
, TIO_NODE_ID
));
299 u32 revnum
= XWIDGET_PART_REV_NUM(tio_id
);
301 /* TIOCP BRINGUP WAR (PV907516): Don't write buffer flush reg */
302 if ((1 << XWIDGET_PART_REV_NUM_REV(revnum
)) & PV907516
) {
305 pcireg_wrb_flush_get(common
->sfdl_pcibus_info
,
306 (common
->sfdl_slot
- 1));
309 spin_lock_irqsave(&p
->sfdl_flush_lock
, flags
);
310 *common
->sfdl_flush_addr
= 0;
312 /* force an interrupt. */
313 *(volatile u32
*)(common
->sfdl_force_int_addr
) = 1;
315 /* wait for the interrupt to come back. */
316 while (*(common
->sfdl_flush_addr
) != 0x10f)
319 /* okay, everything is synched up. */
320 spin_unlock_irqrestore(&p
->sfdl_flush_lock
, flags
);
326 * DMA interfaces. Called from pci_dma.c routines.
330 pcibr_dma_map(struct pci_dev
* hwdev
, unsigned long phys_addr
, size_t size
)
332 dma_addr_t dma_handle
;
333 struct pcidev_info
*pcidev_info
= SN_PCIDEV_INFO(hwdev
);
335 /* SN cannot support DMA addresses smaller than 32 bits. */
336 if (hwdev
->dma_mask
< 0x7fffffff) {
340 if (hwdev
->dma_mask
== ~0UL) {
342 * Handle the most common case: 64 bit cards. This
343 * call should always succeed.
346 dma_handle
= pcibr_dmatrans_direct64(pcidev_info
, phys_addr
,
349 /* Handle 32-63 bit cards via direct mapping */
350 dma_handle
= pcibr_dmatrans_direct32(pcidev_info
, phys_addr
,
354 * It is a 32 bit card and we cannot do direct mapping,
358 dma_handle
= pcibr_dmamap_ate32(pcidev_info
, phys_addr
,
359 size
, PCI32_ATE_PREF
);
367 pcibr_dma_map_consistent(struct pci_dev
* hwdev
, unsigned long phys_addr
,
370 dma_addr_t dma_handle
;
371 struct pcidev_info
*pcidev_info
= SN_PCIDEV_INFO(hwdev
);
373 if (hwdev
->dev
.coherent_dma_mask
== ~0UL) {
374 dma_handle
= pcibr_dmatrans_direct64(pcidev_info
, phys_addr
,
377 dma_handle
= (dma_addr_t
) pcibr_dmamap_ate32(pcidev_info
,
385 EXPORT_SYMBOL(sn_dma_flush
);
This page took 0.0768 seconds and 5 git commands to generate.