1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
/*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*
* Copyright (C) 2000 Silicon Graphics, Inc.
* Copyright (C) 2000 by Leo Dagum
*/
#include <linux/config.h>
#include <linux/types.h>
#include <linux/mm.h>
#include <linux/string.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/devfs_fs_kernel.h>
#ifndef LANGUAGE_C
#define LANGUAGE_C 99
#endif
#ifndef _LANGUAGE_C
#define _LANGUAGE_C 99
#endif
#ifndef CONFIG_IA64_SGI_IO
#define CONFIG_IA64_SGI_IO 99
#endif
#include <asm/io.h>
#include <asm/sn/sgi.h>
#include <asm/sn/invent.h>
#include <asm/sn/hcl.h>
#include <asm/sn/pci/pcibr.h>
#include <asm/sn/pci/pcibr_private.h>
#include <asm/sn/iobus.h>
#include <asm/sn/pci/pci_bus_cvlink.h>
#include <asm/sn/types.h>
#include <asm/sn/alenlist.h>
/*
* this is REALLY ugly, blame it on gcc's lame inlining that we
* have to put procedures in header files
*/
#if LANGUAGE_C == 99
#undef LANGUAGE_C
#endif
#if _LANGUAGE_C == 99
#undef _LANGUAGE_C
#endif
#if CONFIG_IA64_SGI_IO == 99
#undef CONFIG_IA64_SGI_IO
#endif
/*
* sn1 platform specific pci_alloc_consistent()
*
* this interface is meant for "command" streams, i.e. called only
* once for initializing a device, so we don't want prefetching or
* write gathering turned on, hence the PCIIO_DMA_CMD flag
*/
void *
sn1_pci_alloc_consistent (struct pci_dev *hwdev, size_t size, dma_addr_t *dma_handle)
{
void *ret;
int gfp = GFP_ATOMIC;
devfs_handle_t vhdl;
struct sn1_device_sysdata *device_sysdata;
paddr_t temp_ptr;
*dma_handle = (dma_addr_t) NULL;
/*
* get vertex for the device
*/
device_sysdata = (struct sn1_device_sysdata *) hwdev->sysdata;
vhdl = device_sysdata->vhdl;
if ( ret = (void *)__get_free_pages(gfp, get_order(size)) ) {
memset(ret, 0, size);
} else {
return(NULL);
}
temp_ptr = (paddr_t) __pa(ret);
if (IS_PCIA64(hwdev)) {
/*
* This device supports 64bits DMA addresses.
*/
*dma_handle = pciio_dmatrans_addr(vhdl, NULL, temp_ptr, size,
PCIBR_BARRIER | PCIIO_BYTE_STREAM | PCIIO_DMA_CMD
| PCIIO_DMA_A64 );
return (ret);
}
/*
* Devices that supports 32 Bits upto 63 Bits DMA Address gets
* 32 Bits DMA addresses.
*
* First try to get 32 Bit Direct Map Support.
*/
if (IS_PCI32G(hwdev)) {
*dma_handle = pciio_dmatrans_addr(vhdl, NULL, temp_ptr, size,
PCIBR_BARRIER | PCIIO_BYTE_STREAM | PCIIO_DMA_CMD);
if (dma_handle) {
return (ret);
} else {
/*
* We need to map this request by using ATEs.
*/
printk("sn1_pci_alloc_consistent: 32Bits DMA Page Map support not available yet!");
BUG();
}
}
if (IS_PCI32L(hwdev)) {
/*
* SNIA64 cannot support DMA Addresses smaller than 32 bits.
*/
return (NULL);
}
return NULL;
}
void
sn1_pci_free_consistent(struct pci_dev *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle)
{
free_pages((unsigned long) vaddr, get_order(size));
}
/*
* On sn1 we use the alt_address entry of the scatterlist to store
* the physical address corresponding to the given virtual address
*/
int
sn1_pci_map_sg (struct pci_dev *hwdev,
struct scatterlist *sg, int nents, int direction)
{
int i;
devfs_handle_t vhdl;
dma_addr_t dma_addr;
paddr_t temp_ptr;
struct sn1_device_sysdata *device_sysdata;
if (direction == PCI_DMA_NONE)
BUG();
/*
* Handle 64 bit cards.
*/
device_sysdata = (struct sn1_device_sysdata *) hwdev->sysdata;
vhdl = device_sysdata->vhdl;
for (i = 0; i < nents; i++, sg++) {
sg->orig_address = sg->address;
dma_addr = 0;
temp_ptr = (paddr_t) __pa(sg->address);
/*
* Handle the most common case 64Bit cards.
*/
if (IS_PCIA64(hwdev)) {
dma_addr = (dma_addr_t) pciio_dmatrans_addr(vhdl, NULL,
temp_ptr, sg->length,
PCIBR_BARRIER | PCIIO_BYTE_STREAM |
PCIIO_DMA_CMD | PCIIO_DMA_A64 );
sg->address = (char *)dma_addr;
/* printk("pci_map_sg: 64Bits hwdev %p DMA Address 0x%p alt_address 0x%p orig_address 0x%p length 0x%x\n", hwdev, sg->address, sg->alt_address, sg->orig_address, sg->length); */
continue;
}
/*
* Handle 32Bits and greater cards.
*/
if (IS_PCI32G(hwdev)) {
dma_addr = (dma_addr_t) pciio_dmatrans_addr(vhdl, NULL,
temp_ptr, sg->length,
PCIBR_BARRIER | PCIIO_BYTE_STREAM |
PCIIO_DMA_CMD);
if (dma_addr) {
sg->address = (char *)dma_addr;
/* printk("pci_map_single: 32Bit direct pciio_dmatrans_addr pcidev %p returns dma_addr 0x%lx\n", hwdev, dma_addr); */
continue;
} else {
/*
* We need to map this request by using ATEs.
*/
printk("pci_map_single: 32Bits DMA Page Map support not available yet!");
BUG();
}
}
}
return nents;
}
/*
* Unmap a set of streaming mode DMA translations.
* Again, cpu read rules concerning calls here are the same as for
* pci_unmap_single() above.
*/
void
sn1_pci_unmap_sg (struct pci_dev *hwdev, struct scatterlist *sg, int nelems, int direction)
{
int i;
if (direction == PCI_DMA_NONE)
BUG();
for (i = 0; i < nelems; i++, sg++)
if (sg->orig_address != sg->address) {
/* phys_to_virt((dma_addr_t)sg->address | ~0x80000000); */
sg->address = sg->orig_address;
sg->orig_address = 0;
}
}
/*
* We map this to the one step pciio_dmamap_trans interface rather than
* the two step pciio_dmamap_alloc/pciio_dmamap_addr because we have
* no way of saving the dmamap handle from the alloc to later free
* (which is pretty much unacceptable).
*
* TODO: simplify our interface;
* get rid of dev_desc and vhdl (seems redundant given a pci_dev);
* figure out how to save dmamap handle so can use two step.
*/
dma_addr_t sn1_pci_map_single (struct pci_dev *hwdev,
void *ptr, size_t size, int direction)
{
devfs_handle_t vhdl;
dma_addr_t dma_addr;
paddr_t temp_ptr;
struct sn1_device_sysdata *device_sysdata;
if (direction == PCI_DMA_NONE)
BUG();
if (IS_PCI32L(hwdev)) {
/*
* SNIA64 cannot support DMA Addresses smaller than 32 bits.
*/
return ((dma_addr_t) NULL);
}
/*
* find vertex for the device
*/
device_sysdata = (struct sn1_device_sysdata *)hwdev->sysdata;
vhdl = device_sysdata->vhdl;
/* printk("pci_map_single: Called vhdl = 0x%p ptr = 0x%p size = %d\n", vhdl, ptr, size); */
/*
* Call our dmamap interface
*/
dma_addr = 0;
temp_ptr = (paddr_t) __pa(ptr);
if (IS_PCIA64(hwdev)) {
/*
* This device supports 64bits DMA addresses.
*/
dma_addr = (dma_addr_t) pciio_dmatrans_addr(vhdl, NULL,
temp_ptr, size,
PCIBR_BARRIER | PCIIO_BYTE_STREAM | PCIIO_DMA_CMD
| PCIIO_DMA_A64 );
/* printk("pci_map_single: 64Bit pciio_dmatrans_addr pcidev %p returns dma_addr 0x%lx\n", hwdev, dma_addr); */
return (dma_addr);
}
/*
* Devices that supports 32 Bits upto 63 Bits DMA Address gets
* 32 Bits DMA addresses.
*
* First try to get 32 Bit Direct Map Support.
*/
if (IS_PCI32G(hwdev)) {
dma_addr = (dma_addr_t) pciio_dmatrans_addr(vhdl, NULL,
temp_ptr, size,
PCIBR_BARRIER | PCIIO_BYTE_STREAM | PCIIO_DMA_CMD);
if (dma_addr) {
/* printk("pci_map_single: 32Bit direct pciio_dmatrans_addr pcidev %p returns dma_addr 0x%lx\n", hwdev, dma_addr); */
return (dma_addr);
} else {
/*
* We need to map this request by using ATEs.
*/
printk("pci_map_single: 32Bits DMA Page Map support not available yet!");
BUG();
}
}
if (IS_PCI32L(hwdev)) {
/*
* SNIA64 cannot support DMA Addresses smaller than 32 bits.
*/
return ((dma_addr_t) NULL);
}
return ((dma_addr_t) NULL);
}
void
sn1_pci_unmap_single (struct pci_dev *hwdev, dma_addr_t dma_addr, size_t size, int direction)
{
if (direction == PCI_DMA_NONE)
BUG();
/* Nothing to do */
}
void
sn1_pci_dma_sync_single (struct pci_dev *hwdev, dma_addr_t dma_handle, size_t size, int direction)
{
if (direction == PCI_DMA_NONE)
BUG();
/* Nothing to do */
}
void
sn1_pci_dma_sync_sg (struct pci_dev *hwdev, struct scatterlist *sg, int nelems, int direction)
{
if (direction == PCI_DMA_NONE)
BUG();
/* Nothing to do */
}
unsigned long
sn1_dma_address (struct scatterlist *sg)
{
return (sg->address);
}
|