x86_64: abstract how we find the iommu_table for a device
[linux-block.git] / arch / x86_64 / kernel / pci-calgary.c
CommitLineData
e465058d
JM
1/*
2 * Derived from arch/powerpc/kernel/iommu.c
3 *
9882234b 4 * Copyright IBM Corporation, 2006-2007
d8d2bedf 5 * Copyright (C) 2006 Jon Mason <jdmason@kudzu.us>
e465058d 6 *
d8d2bedf 7 * Author: Jon Mason <jdmason@kudzu.us>
aa0a9f37
MBY
8 * Author: Muli Ben-Yehuda <muli@il.ibm.com>
9
e465058d
JM
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
e465058d
JM
25#include <linux/kernel.h>
26#include <linux/init.h>
27#include <linux/types.h>
28#include <linux/slab.h>
29#include <linux/mm.h>
30#include <linux/spinlock.h>
31#include <linux/string.h>
32#include <linux/dma-mapping.h>
33#include <linux/init.h>
34#include <linux/bitops.h>
35#include <linux/pci_ids.h>
36#include <linux/pci.h>
37#include <linux/delay.h>
38#include <asm/proto.h>
39#include <asm/calgary.h>
40#include <asm/tce.h>
41#include <asm/pci-direct.h>
42#include <asm/system.h>
43#include <asm/dma.h>
b34e90b8 44#include <asm/rio.h>
e465058d 45
bff6547b
MBY
46#ifdef CONFIG_CALGARY_IOMMU_ENABLED_BY_DEFAULT
47int use_calgary __read_mostly = 1;
48#else
49int use_calgary __read_mostly = 0;
50#endif /* CONFIG_CALGARY_DEFAULT_ENABLED */
51
e465058d
JM
52#define PCI_DEVICE_ID_IBM_CALGARY 0x02a1
53#define PCI_VENDOR_DEVICE_ID_CALGARY \
54 (PCI_VENDOR_ID_IBM | PCI_DEVICE_ID_IBM_CALGARY << 16)
55
56/* we need these for register space address calculation */
57#define START_ADDRESS 0xfe000000
58#define CHASSIS_BASE 0
59#define ONE_BASED_CHASSIS_NUM 1
60
61/* register offsets inside the host bridge space */
cb01fc72
MBY
62#define CALGARY_CONFIG_REG 0x0108
63#define PHB_CSR_OFFSET 0x0110 /* Channel Status */
e465058d
JM
64#define PHB_PLSSR_OFFSET 0x0120
65#define PHB_CONFIG_RW_OFFSET 0x0160
66#define PHB_IOBASE_BAR_LOW 0x0170
67#define PHB_IOBASE_BAR_HIGH 0x0180
68#define PHB_MEM_1_LOW 0x0190
69#define PHB_MEM_1_HIGH 0x01A0
70#define PHB_IO_ADDR_SIZE 0x01B0
71#define PHB_MEM_1_SIZE 0x01C0
72#define PHB_MEM_ST_OFFSET 0x01D0
73#define PHB_AER_OFFSET 0x0200
74#define PHB_CONFIG_0_HIGH 0x0220
75#define PHB_CONFIG_0_LOW 0x0230
76#define PHB_CONFIG_0_END 0x0240
77#define PHB_MEM_2_LOW 0x02B0
78#define PHB_MEM_2_HIGH 0x02C0
79#define PHB_MEM_2_SIZE_HIGH 0x02D0
80#define PHB_MEM_2_SIZE_LOW 0x02E0
81#define PHB_DOSHOLE_OFFSET 0x08E0
82
83/* PHB_CONFIG_RW */
84#define PHB_TCE_ENABLE 0x20000000
85#define PHB_SLOT_DISABLE 0x1C000000
86#define PHB_DAC_DISABLE 0x01000000
87#define PHB_MEM2_ENABLE 0x00400000
88#define PHB_MCSR_ENABLE 0x00100000
89/* TAR (Table Address Register) */
90#define TAR_SW_BITS 0x0000ffffffff800fUL
91#define TAR_VALID 0x0000000000000008UL
92/* CSR (Channel/DMA Status Register) */
93#define CSR_AGENT_MASK 0xffe0ffff
cb01fc72
MBY
94/* CCR (Calgary Configuration Register) */
95#define CCR_2SEC_TIMEOUT 0x000000000000000EUL
e465058d
JM
96
97#define MAX_NUM_OF_PHBS 8 /* how many PHBs in total? */
d2105b10 98#define MAX_NUM_CHASSIS 8 /* max number of chassis */
4ea8a5d8
MBY
99/* MAX_PHB_BUS_NUM is the maximal possible dev->bus->number */
100#define MAX_PHB_BUS_NUM (MAX_NUM_OF_PHBS * MAX_NUM_CHASSIS * 2)
e465058d
JM
101#define PHBS_PER_CALGARY 4
102
103/* register offsets in Calgary's internal register space */
104static const unsigned long tar_offsets[] = {
105 0x0580 /* TAR0 */,
106 0x0588 /* TAR1 */,
107 0x0590 /* TAR2 */,
108 0x0598 /* TAR3 */
109};
110
111static const unsigned long split_queue_offsets[] = {
112 0x4870 /* SPLIT QUEUE 0 */,
113 0x5870 /* SPLIT QUEUE 1 */,
114 0x6870 /* SPLIT QUEUE 2 */,
115 0x7870 /* SPLIT QUEUE 3 */
116};
117
118static const unsigned long phb_offsets[] = {
119 0x8000 /* PHB0 */,
120 0x9000 /* PHB1 */,
121 0xA000 /* PHB2 */,
122 0xB000 /* PHB3 */
123};
124
b34e90b8
LV
125/* PHB debug registers */
126
127static const unsigned long phb_debug_offsets[] = {
128 0x4000 /* PHB 0 DEBUG */,
129 0x5000 /* PHB 1 DEBUG */,
130 0x6000 /* PHB 2 DEBUG */,
131 0x7000 /* PHB 3 DEBUG */
132};
133
134/*
135 * STUFF register for each debug PHB,
136 * byte 1 = start bus number, byte 2 = end bus number
137 */
138
139#define PHB_DEBUG_STUFF_OFFSET 0x0020
140
310adfdd
MBY
141#define EMERGENCY_PAGES 32 /* = 128KB */
142
e465058d
JM
143unsigned int specified_table_size = TCE_TABLE_SIZE_UNSPECIFIED;
144static int translate_empty_slots __read_mostly = 0;
145static int calgary_detected __read_mostly = 0;
146
b34e90b8
LV
147static struct rio_table_hdr *rio_table_hdr __initdata;
148static struct scal_detail *scal_devs[MAX_NUMNODES] __initdata;
eae93755 149static struct rio_detail *rio_devs[MAX_NUMNODES * 4] __initdata;
b34e90b8 150
f38db651
MBY
151struct calgary_bus_info {
152 void *tce_space;
0577f148 153 unsigned char translation_disabled;
f38db651 154 signed char phbid;
b34e90b8 155 void __iomem *bbar;
f38db651
MBY
156};
157
ff297b8c
MBY
158static void calgary_handle_quirks(struct iommu_table *tbl, struct pci_dev *dev);
159static void calgary_tce_cache_blast(struct iommu_table *tbl);
160
161static struct cal_chipset_ops calgary_chip_ops = {
162 .handle_quirks = calgary_handle_quirks,
163 .tce_cache_blast = calgary_tce_cache_blast
164};
e465058d 165
ff297b8c 166static struct calgary_bus_info bus_info[MAX_PHB_BUS_NUM] = { { NULL, 0, 0 }, };
e465058d
JM
167
168/* enable this to stress test the chip's TCE cache */
169#ifdef CONFIG_IOMMU_DEBUG
de684652
MBY
170int debugging __read_mostly = 1;
171
796e4390
MBY
172static inline unsigned long verify_bit_range(unsigned long* bitmap,
173 int expected, unsigned long start, unsigned long end)
174{
175 unsigned long idx = start;
176
177 BUG_ON(start >= end);
178
179 while (idx < end) {
180 if (!!test_bit(idx, bitmap) != expected)
181 return idx;
182 ++idx;
183 }
184
185 /* all bits have the expected value */
186 return ~0UL;
187}
de684652
MBY
188#else /* debugging is disabled */
189int debugging __read_mostly = 0;
190
796e4390
MBY
191static inline unsigned long verify_bit_range(unsigned long* bitmap,
192 int expected, unsigned long start, unsigned long end)
193{
194 return ~0UL;
195}
de684652 196#endif /* CONFIG_IOMMU_DEBUG */
e465058d
JM
197
198static inline unsigned int num_dma_pages(unsigned long dma, unsigned int dmalen)
199{
200 unsigned int npages;
201
202 npages = PAGE_ALIGN(dma + dmalen) - (dma & PAGE_MASK);
203 npages >>= PAGE_SHIFT;
204
205 return npages;
206}
207
208static inline int translate_phb(struct pci_dev* dev)
209{
f38db651 210 int disabled = bus_info[dev->bus->number].translation_disabled;
e465058d
JM
211 return !disabled;
212}
213
214static void iommu_range_reserve(struct iommu_table *tbl,
215 unsigned long start_addr, unsigned int npages)
216{
217 unsigned long index;
218 unsigned long end;
796e4390 219 unsigned long badbit;
e465058d
JM
220
221 index = start_addr >> PAGE_SHIFT;
222
223 /* bail out if we're asked to reserve a region we don't cover */
224 if (index >= tbl->it_size)
225 return;
226
227 end = index + npages;
228 if (end > tbl->it_size) /* don't go off the table */
229 end = tbl->it_size;
230
796e4390
MBY
231 badbit = verify_bit_range(tbl->it_map, 0, index, end);
232 if (badbit != ~0UL) {
233 if (printk_ratelimit())
e465058d
JM
234 printk(KERN_ERR "Calgary: entry already allocated at "
235 "0x%lx tbl %p dma 0x%lx npages %u\n",
796e4390 236 badbit, tbl, start_addr, npages);
e465058d 237 }
796e4390
MBY
238
239 set_bit_string(tbl->it_map, index, npages);
e465058d
JM
240}
241
242static unsigned long iommu_range_alloc(struct iommu_table *tbl,
243 unsigned int npages)
244{
245 unsigned long offset;
246
247 BUG_ON(npages == 0);
248
249 offset = find_next_zero_string(tbl->it_map, tbl->it_hint,
250 tbl->it_size, npages);
251 if (offset == ~0UL) {
ff297b8c 252 tbl->chip_ops->tce_cache_blast(tbl);
e465058d
JM
253 offset = find_next_zero_string(tbl->it_map, 0,
254 tbl->it_size, npages);
255 if (offset == ~0UL) {
256 printk(KERN_WARNING "Calgary: IOMMU full.\n");
257 if (panic_on_overflow)
258 panic("Calgary: fix the allocator.\n");
259 else
260 return bad_dma_address;
261 }
262 }
263
264 set_bit_string(tbl->it_map, offset, npages);
265 tbl->it_hint = offset + npages;
266 BUG_ON(tbl->it_hint > tbl->it_size);
267
268 return offset;
269}
270
271static dma_addr_t iommu_alloc(struct iommu_table *tbl, void *vaddr,
272 unsigned int npages, int direction)
273{
274 unsigned long entry, flags;
275 dma_addr_t ret = bad_dma_address;
276
277 spin_lock_irqsave(&tbl->it_lock, flags);
278
279 entry = iommu_range_alloc(tbl, npages);
280
281 if (unlikely(entry == bad_dma_address))
282 goto error;
283
284 /* set the return dma address */
285 ret = (entry << PAGE_SHIFT) | ((unsigned long)vaddr & ~PAGE_MASK);
286
287 /* put the TCEs in the HW table */
288 tce_build(tbl, entry, npages, (unsigned long)vaddr & PAGE_MASK,
289 direction);
290
291 spin_unlock_irqrestore(&tbl->it_lock, flags);
292
293 return ret;
294
295error:
296 spin_unlock_irqrestore(&tbl->it_lock, flags);
297 printk(KERN_WARNING "Calgary: failed to allocate %u pages in "
298 "iommu %p\n", npages, tbl);
299 return bad_dma_address;
300}
301
302static void __iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr,
303 unsigned int npages)
304{
305 unsigned long entry;
796e4390 306 unsigned long badbit;
310adfdd
MBY
307 unsigned long badend;
308
309 /* were we called with bad_dma_address? */
310 badend = bad_dma_address + (EMERGENCY_PAGES * PAGE_SIZE);
311 if (unlikely((dma_addr >= bad_dma_address) && (dma_addr < badend))) {
312 printk(KERN_ERR "Calgary: driver tried unmapping bad DMA "
313 "address 0x%Lx\n", dma_addr);
314 WARN_ON(1);
315 return;
316 }
e465058d
JM
317
318 entry = dma_addr >> PAGE_SHIFT;
319
320 BUG_ON(entry + npages > tbl->it_size);
321
322 tce_free(tbl, entry, npages);
323
796e4390
MBY
324 badbit = verify_bit_range(tbl->it_map, 1, entry, entry + npages);
325 if (badbit != ~0UL) {
326 if (printk_ratelimit())
e465058d
JM
327 printk(KERN_ERR "Calgary: bit is off at 0x%lx "
328 "tbl %p dma 0x%Lx entry 0x%lx npages %u\n",
796e4390 329 badbit, tbl, dma_addr, entry, npages);
e465058d
JM
330 }
331
332 __clear_bit_string(tbl->it_map, entry, npages);
e465058d
JM
333}
334
335static void iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr,
336 unsigned int npages)
337{
338 unsigned long flags;
339
340 spin_lock_irqsave(&tbl->it_lock, flags);
341
342 __iommu_free(tbl, dma_addr, npages);
343
344 spin_unlock_irqrestore(&tbl->it_lock, flags);
345}
346
35b6dfa0
MBY
347static inline struct iommu_table *find_iommu_table(struct device *dev)
348{
349 struct iommu_table *tbl;
350
351 tbl = to_pci_dev(dev)->bus->self->sysdata;
352
353 return tbl;
354}
355
e465058d
JM
356static void __calgary_unmap_sg(struct iommu_table *tbl,
357 struct scatterlist *sglist, int nelems, int direction)
358{
359 while (nelems--) {
360 unsigned int npages;
361 dma_addr_t dma = sglist->dma_address;
362 unsigned int dmalen = sglist->dma_length;
363
364 if (dmalen == 0)
365 break;
366
367 npages = num_dma_pages(dma, dmalen);
368 __iommu_free(tbl, dma, npages);
369 sglist++;
370 }
371}
372
373void calgary_unmap_sg(struct device *dev, struct scatterlist *sglist,
374 int nelems, int direction)
375{
376 unsigned long flags;
35b6dfa0 377 struct iommu_table *tbl = find_iommu_table(dev);
e465058d
JM
378
379 if (!translate_phb(to_pci_dev(dev)))
380 return;
381
382 spin_lock_irqsave(&tbl->it_lock, flags);
383
384 __calgary_unmap_sg(tbl, sglist, nelems, direction);
385
386 spin_unlock_irqrestore(&tbl->it_lock, flags);
387}
388
389static int calgary_nontranslate_map_sg(struct device* dev,
390 struct scatterlist *sg, int nelems, int direction)
391{
392 int i;
393
394 for (i = 0; i < nelems; i++ ) {
395 struct scatterlist *s = &sg[i];
396 BUG_ON(!s->page);
397 s->dma_address = virt_to_bus(page_address(s->page) +s->offset);
398 s->dma_length = s->length;
399 }
400 return nelems;
401}
402
403int calgary_map_sg(struct device *dev, struct scatterlist *sg,
404 int nelems, int direction)
405{
35b6dfa0 406 struct iommu_table *tbl = find_iommu_table(dev);
e465058d
JM
407 unsigned long flags;
408 unsigned long vaddr;
409 unsigned int npages;
410 unsigned long entry;
411 int i;
412
413 if (!translate_phb(to_pci_dev(dev)))
414 return calgary_nontranslate_map_sg(dev, sg, nelems, direction);
415
416 spin_lock_irqsave(&tbl->it_lock, flags);
417
418 for (i = 0; i < nelems; i++ ) {
419 struct scatterlist *s = &sg[i];
420 BUG_ON(!s->page);
421
422 vaddr = (unsigned long)page_address(s->page) + s->offset;
423 npages = num_dma_pages(vaddr, s->length);
424
425 entry = iommu_range_alloc(tbl, npages);
426 if (entry == bad_dma_address) {
427 /* makes sure unmap knows to stop */
428 s->dma_length = 0;
429 goto error;
430 }
431
432 s->dma_address = (entry << PAGE_SHIFT) | s->offset;
433
434 /* insert into HW table */
435 tce_build(tbl, entry, npages, vaddr & PAGE_MASK,
436 direction);
437
438 s->dma_length = s->length;
439 }
440
441 spin_unlock_irqrestore(&tbl->it_lock, flags);
442
443 return nelems;
444error:
445 __calgary_unmap_sg(tbl, sg, nelems, direction);
446 for (i = 0; i < nelems; i++) {
447 sg[i].dma_address = bad_dma_address;
448 sg[i].dma_length = 0;
449 }
450 spin_unlock_irqrestore(&tbl->it_lock, flags);
451 return 0;
452}
453
454dma_addr_t calgary_map_single(struct device *dev, void *vaddr,
455 size_t size, int direction)
456{
457 dma_addr_t dma_handle = bad_dma_address;
458 unsigned long uaddr;
459 unsigned int npages;
35b6dfa0 460 struct iommu_table *tbl = find_iommu_table(dev);
e465058d
JM
461
462 uaddr = (unsigned long)vaddr;
463 npages = num_dma_pages(uaddr, size);
464
465 if (translate_phb(to_pci_dev(dev)))
466 dma_handle = iommu_alloc(tbl, vaddr, npages, direction);
467 else
468 dma_handle = virt_to_bus(vaddr);
469
470 return dma_handle;
471}
472
473void calgary_unmap_single(struct device *dev, dma_addr_t dma_handle,
474 size_t size, int direction)
475{
35b6dfa0 476 struct iommu_table *tbl = find_iommu_table(dev);
e465058d
JM
477 unsigned int npages;
478
479 if (!translate_phb(to_pci_dev(dev)))
480 return;
481
482 npages = num_dma_pages(dma_handle, size);
483 iommu_free(tbl, dma_handle, npages);
484}
485
486void* calgary_alloc_coherent(struct device *dev, size_t size,
487 dma_addr_t *dma_handle, gfp_t flag)
488{
489 void *ret = NULL;
490 dma_addr_t mapping;
491 unsigned int npages, order;
35b6dfa0 492 struct iommu_table *tbl = find_iommu_table(dev);
e465058d
JM
493
494 size = PAGE_ALIGN(size); /* size rounded up to full pages */
495 npages = size >> PAGE_SHIFT;
496 order = get_order(size);
497
498 /* alloc enough pages (and possibly more) */
499 ret = (void *)__get_free_pages(flag, order);
500 if (!ret)
501 goto error;
502 memset(ret, 0, size);
503
504 if (translate_phb(to_pci_dev(dev))) {
505 /* set up tces to cover the allocated range */
506 mapping = iommu_alloc(tbl, ret, npages, DMA_BIDIRECTIONAL);
507 if (mapping == bad_dma_address)
508 goto free;
509
510 *dma_handle = mapping;
511 } else /* non translated slot */
512 *dma_handle = virt_to_bus(ret);
513
514 return ret;
515
516free:
517 free_pages((unsigned long)ret, get_order(size));
518 ret = NULL;
519error:
520 return ret;
521}
522
e6584504 523static const struct dma_mapping_ops calgary_dma_ops = {
e465058d
JM
524 .alloc_coherent = calgary_alloc_coherent,
525 .map_single = calgary_map_single,
526 .unmap_single = calgary_unmap_single,
527 .map_sg = calgary_map_sg,
528 .unmap_sg = calgary_unmap_sg,
529};
530
b34e90b8
LV
531static inline void __iomem * busno_to_bbar(unsigned char num)
532{
533 return bus_info[num].bbar;
534}
535
e465058d
JM
536static inline int busno_to_phbid(unsigned char num)
537{
f38db651 538 return bus_info[num].phbid;
e465058d
JM
539}
540
541static inline unsigned long split_queue_offset(unsigned char num)
542{
543 size_t idx = busno_to_phbid(num);
544
545 return split_queue_offsets[idx];
546}
547
548static inline unsigned long tar_offset(unsigned char num)
549{
550 size_t idx = busno_to_phbid(num);
551
552 return tar_offsets[idx];
553}
554
555static inline unsigned long phb_offset(unsigned char num)
556{
557 size_t idx = busno_to_phbid(num);
558
559 return phb_offsets[idx];
560}
561
562static inline void __iomem* calgary_reg(void __iomem *bar, unsigned long offset)
563{
564 unsigned long target = ((unsigned long)bar) | offset;
565 return (void __iomem*)target;
566}
567
ff297b8c 568static void calgary_tce_cache_blast(struct iommu_table *tbl)
e465058d
JM
569{
570 u64 val;
571 u32 aer;
572 int i = 0;
573 void __iomem *bbar = tbl->bbar;
574 void __iomem *target;
575
576 /* disable arbitration on the bus */
577 target = calgary_reg(bbar, phb_offset(tbl->it_busno) | PHB_AER_OFFSET);
578 aer = readl(target);
579 writel(0, target);
580
581 /* read plssr to ensure it got there */
582 target = calgary_reg(bbar, phb_offset(tbl->it_busno) | PHB_PLSSR_OFFSET);
583 val = readl(target);
584
585 /* poll split queues until all DMA activity is done */
586 target = calgary_reg(bbar, split_queue_offset(tbl->it_busno));
587 do {
588 val = readq(target);
589 i++;
590 } while ((val & 0xff) != 0xff && i < 100);
591 if (i == 100)
592 printk(KERN_WARNING "Calgary: PCI bus not quiesced, "
593 "continuing anyway\n");
594
595 /* invalidate TCE cache */
596 target = calgary_reg(bbar, tar_offset(tbl->it_busno));
597 writeq(tbl->tar_val, target);
598
599 /* enable arbitration */
600 target = calgary_reg(bbar, phb_offset(tbl->it_busno) | PHB_AER_OFFSET);
601 writel(aer, target);
602 (void)readl(target); /* flush */
603}
604
605static void __init calgary_reserve_mem_region(struct pci_dev *dev, u64 start,
606 u64 limit)
607{
608 unsigned int numpages;
609
610 limit = limit | 0xfffff;
611 limit++;
612
613 numpages = ((limit - start) >> PAGE_SHIFT);
614 iommu_range_reserve(dev->sysdata, start, numpages);
615}
616
617static void __init calgary_reserve_peripheral_mem_1(struct pci_dev *dev)
618{
619 void __iomem *target;
620 u64 low, high, sizelow;
621 u64 start, limit;
622 struct iommu_table *tbl = dev->sysdata;
623 unsigned char busnum = dev->bus->number;
624 void __iomem *bbar = tbl->bbar;
625
626 /* peripheral MEM_1 region */
627 target = calgary_reg(bbar, phb_offset(busnum) | PHB_MEM_1_LOW);
628 low = be32_to_cpu(readl(target));
629 target = calgary_reg(bbar, phb_offset(busnum) | PHB_MEM_1_HIGH);
630 high = be32_to_cpu(readl(target));
631 target = calgary_reg(bbar, phb_offset(busnum) | PHB_MEM_1_SIZE);
632 sizelow = be32_to_cpu(readl(target));
633
634 start = (high << 32) | low;
635 limit = sizelow;
636
637 calgary_reserve_mem_region(dev, start, limit);
638}
639
640static void __init calgary_reserve_peripheral_mem_2(struct pci_dev *dev)
641{
642 void __iomem *target;
643 u32 val32;
644 u64 low, high, sizelow, sizehigh;
645 u64 start, limit;
646 struct iommu_table *tbl = dev->sysdata;
647 unsigned char busnum = dev->bus->number;
648 void __iomem *bbar = tbl->bbar;
649
650 /* is it enabled? */
651 target = calgary_reg(bbar, phb_offset(busnum) | PHB_CONFIG_RW_OFFSET);
652 val32 = be32_to_cpu(readl(target));
653 if (!(val32 & PHB_MEM2_ENABLE))
654 return;
655
656 target = calgary_reg(bbar, phb_offset(busnum) | PHB_MEM_2_LOW);
657 low = be32_to_cpu(readl(target));
658 target = calgary_reg(bbar, phb_offset(busnum) | PHB_MEM_2_HIGH);
659 high = be32_to_cpu(readl(target));
660 target = calgary_reg(bbar, phb_offset(busnum) | PHB_MEM_2_SIZE_LOW);
661 sizelow = be32_to_cpu(readl(target));
662 target = calgary_reg(bbar, phb_offset(busnum) | PHB_MEM_2_SIZE_HIGH);
663 sizehigh = be32_to_cpu(readl(target));
664
665 start = (high << 32) | low;
666 limit = (sizehigh << 32) | sizelow;
667
668 calgary_reserve_mem_region(dev, start, limit);
669}
670
671/*
672 * some regions of the IO address space do not get translated, so we
673 * must not give devices IO addresses in those regions. The regions
674 * are the 640KB-1MB region and the two PCI peripheral memory holes.
675 * Reserve all of them in the IOMMU bitmap to avoid giving them out
676 * later.
677 */
678static void __init calgary_reserve_regions(struct pci_dev *dev)
679{
680 unsigned int npages;
e465058d
JM
681 u64 start;
682 struct iommu_table *tbl = dev->sysdata;
683
310adfdd
MBY
684 /* reserve EMERGENCY_PAGES from bad_dma_address and up */
685 iommu_range_reserve(tbl, bad_dma_address, EMERGENCY_PAGES);
e465058d
JM
686
687 /* avoid the BIOS/VGA first 640KB-1MB region */
688 start = (640 * 1024);
689 npages = ((1024 - 640) * 1024) >> PAGE_SHIFT;
690 iommu_range_reserve(tbl, start, npages);
691
692 /* reserve the two PCI peripheral memory regions in IO space */
693 calgary_reserve_peripheral_mem_1(dev);
694 calgary_reserve_peripheral_mem_2(dev);
695}
696
697static int __init calgary_setup_tar(struct pci_dev *dev, void __iomem *bbar)
698{
699 u64 val64;
700 u64 table_phys;
701 void __iomem *target;
702 int ret;
703 struct iommu_table *tbl;
704
705 /* build TCE tables for each PHB */
706 ret = build_tce_table(dev, bbar);
707 if (ret)
708 return ret;
709
f38db651
MBY
710 tbl = dev->sysdata;
711 tbl->it_base = (unsigned long)bus_info[dev->bus->number].tce_space;
712 tce_free(tbl, 0, tbl->it_size);
713
ff297b8c
MBY
714 tbl->chip_ops = &calgary_chip_ops;
715
e465058d
JM
716 calgary_reserve_regions(dev);
717
718 /* set TARs for each PHB */
719 target = calgary_reg(bbar, tar_offset(dev->bus->number));
720 val64 = be64_to_cpu(readq(target));
721
722 /* zero out all TAR bits under sw control */
723 val64 &= ~TAR_SW_BITS;
724
725 tbl = dev->sysdata;
726 table_phys = (u64)__pa(tbl->it_base);
727 val64 |= table_phys;
728
729 BUG_ON(specified_table_size > TCE_TABLE_SIZE_8M);
730 val64 |= (u64) specified_table_size;
731
732 tbl->tar_val = cpu_to_be64(val64);
733 writeq(tbl->tar_val, target);
734 readq(target); /* flush */
735
736 return 0;
737}
738
b8f4fe66 739static void __init calgary_free_bus(struct pci_dev *dev)
e465058d
JM
740{
741 u64 val64;
742 struct iommu_table *tbl = dev->sysdata;
743 void __iomem *target;
b8f4fe66 744 unsigned int bitmapsz;
e465058d
JM
745
746 target = calgary_reg(tbl->bbar, tar_offset(dev->bus->number));
747 val64 = be64_to_cpu(readq(target));
748 val64 &= ~TAR_SW_BITS;
749 writeq(cpu_to_be64(val64), target);
750 readq(target); /* flush */
751
b8f4fe66
MBY
752 bitmapsz = tbl->it_size / BITS_PER_BYTE;
753 free_pages((unsigned long)tbl->it_map, get_order(bitmapsz));
754 tbl->it_map = NULL;
755
e465058d
JM
756 kfree(tbl);
757 dev->sysdata = NULL;
b8f4fe66
MBY
758
759 /* Can't free bootmem allocated memory after system is up :-( */
760 bus_info[dev->bus->number].tce_space = NULL;
e465058d
JM
761}
762
763static void calgary_watchdog(unsigned long data)
764{
765 struct pci_dev *dev = (struct pci_dev *)data;
766 struct iommu_table *tbl = dev->sysdata;
767 void __iomem *bbar = tbl->bbar;
768 u32 val32;
769 void __iomem *target;
770
771 target = calgary_reg(bbar, phb_offset(tbl->it_busno) | PHB_CSR_OFFSET);
772 val32 = be32_to_cpu(readl(target));
773
774 /* If no error, the agent ID in the CSR is not valid */
775 if (val32 & CSR_AGENT_MASK) {
70d666d6 776 printk(KERN_EMERG "calgary_watchdog: DMA error on PHB %#x, "
e465058d
JM
777 "CSR = %#x\n", dev->bus->number, val32);
778 writel(0, target);
779
780 /* Disable bus that caused the error */
781 target = calgary_reg(bbar, phb_offset(tbl->it_busno) |
782 PHB_CONFIG_RW_OFFSET);
783 val32 = be32_to_cpu(readl(target));
784 val32 |= PHB_SLOT_DISABLE;
785 writel(cpu_to_be32(val32), target);
786 readl(target); /* flush */
787 } else {
788 /* Reset the timer */
789 mod_timer(&tbl->watchdog_timer, jiffies + 2 * HZ);
790 }
791}
792
a2b663f6
MBY
793static void __init calgary_set_split_completion_timeout(void __iomem *bbar,
794 unsigned char busnum, unsigned long timeout)
cb01fc72
MBY
795{
796 u64 val64;
797 void __iomem *target;
58db8548 798 unsigned int phb_shift = ~0; /* silence gcc */
cb01fc72
MBY
799 u64 mask;
800
801 switch (busno_to_phbid(busnum)) {
802 case 0: phb_shift = (63 - 19);
803 break;
804 case 1: phb_shift = (63 - 23);
805 break;
806 case 2: phb_shift = (63 - 27);
807 break;
808 case 3: phb_shift = (63 - 35);
809 break;
810 default:
811 BUG_ON(busno_to_phbid(busnum));
812 }
813
814 target = calgary_reg(bbar, CALGARY_CONFIG_REG);
815 val64 = be64_to_cpu(readq(target));
816
817 /* zero out this PHB's timer bits */
818 mask = ~(0xFUL << phb_shift);
819 val64 &= mask;
a2b663f6 820 val64 |= (timeout << phb_shift);
cb01fc72
MBY
821 writeq(cpu_to_be64(val64), target);
822 readq(target); /* flush */
823}
824
ff297b8c
MBY
825static void __init calgary_handle_quirks(struct iommu_table *tbl,
826 struct pci_dev *dev)
b8d2ea1b
MBY
827{
828 unsigned char busnum = dev->bus->number;
b8d2ea1b
MBY
829
830 /*
831 * Give split completion a longer timeout on bus 1 for aic94xx
832 * http://bugzilla.kernel.org/show_bug.cgi?id=7180
833 */
834 if (busnum == 1)
835 calgary_set_split_completion_timeout(tbl->bbar, busnum,
836 CCR_2SEC_TIMEOUT);
837}
838
e465058d
JM
839static void __init calgary_enable_translation(struct pci_dev *dev)
840{
841 u32 val32;
842 unsigned char busnum;
843 void __iomem *target;
844 void __iomem *bbar;
845 struct iommu_table *tbl;
846
847 busnum = dev->bus->number;
848 tbl = dev->sysdata;
849 bbar = tbl->bbar;
850
851 /* enable TCE in PHB Config Register */
852 target = calgary_reg(bbar, phb_offset(busnum) | PHB_CONFIG_RW_OFFSET);
853 val32 = be32_to_cpu(readl(target));
854 val32 |= PHB_TCE_ENABLE | PHB_DAC_DISABLE | PHB_MCSR_ENABLE;
855
70d666d6 856 printk(KERN_INFO "Calgary: enabling translation on PHB %#x\n", busnum);
e465058d
JM
857 printk(KERN_INFO "Calgary: errant DMAs will now be prevented on this "
858 "bus.\n");
859
860 writel(cpu_to_be32(val32), target);
861 readl(target); /* flush */
862
863 init_timer(&tbl->watchdog_timer);
864 tbl->watchdog_timer.function = &calgary_watchdog;
865 tbl->watchdog_timer.data = (unsigned long)dev;
866 mod_timer(&tbl->watchdog_timer, jiffies);
867}
868
869static void __init calgary_disable_translation(struct pci_dev *dev)
870{
871 u32 val32;
872 unsigned char busnum;
873 void __iomem *target;
874 void __iomem *bbar;
875 struct iommu_table *tbl;
876
877 busnum = dev->bus->number;
878 tbl = dev->sysdata;
879 bbar = tbl->bbar;
880
881 /* disable TCE in PHB Config Register */
882 target = calgary_reg(bbar, phb_offset(busnum) | PHB_CONFIG_RW_OFFSET);
883 val32 = be32_to_cpu(readl(target));
884 val32 &= ~(PHB_TCE_ENABLE | PHB_DAC_DISABLE | PHB_MCSR_ENABLE);
885
70d666d6 886 printk(KERN_INFO "Calgary: disabling translation on PHB %#x!\n", busnum);
e465058d
JM
887 writel(cpu_to_be32(val32), target);
888 readl(target); /* flush */
889
890 del_timer_sync(&tbl->watchdog_timer);
891}
892
a4fc520a 893static void __init calgary_init_one_nontraslated(struct pci_dev *dev)
e465058d 894{
871b1700 895 pci_dev_get(dev);
e465058d
JM
896 dev->sysdata = NULL;
897 dev->bus->self = dev;
e465058d
JM
898}
899
900static int __init calgary_init_one(struct pci_dev *dev)
901{
e465058d 902 void __iomem *bbar;
ff297b8c 903 struct iommu_table *tbl;
e465058d
JM
904 int ret;
905
dedc9937
JM
906 BUG_ON(dev->bus->number >= MAX_PHB_BUS_NUM);
907
eae93755 908 bbar = busno_to_bbar(dev->bus->number);
e465058d
JM
909 ret = calgary_setup_tar(dev, bbar);
910 if (ret)
eae93755 911 goto done;
e465058d 912
871b1700 913 pci_dev_get(dev);
e465058d 914 dev->bus->self = dev;
b8d2ea1b 915
ff297b8c
MBY
916 tbl = dev->sysdata;
917 tbl->chip_ops->handle_quirks(tbl, dev);
b8d2ea1b 918
e465058d
JM
919 calgary_enable_translation(dev);
920
921 return 0;
922
e465058d
JM
923done:
924 return ret;
925}
926
eae93755 927static int __init calgary_locate_bbars(void)
e465058d 928{
eae93755
MBY
929 int ret;
930 int rioidx, phb, bus;
b34e90b8
LV
931 void __iomem *bbar;
932 void __iomem *target;
eae93755 933 unsigned long offset;
b34e90b8
LV
934 u8 start_bus, end_bus;
935 u32 val;
936
eae93755
MBY
937 ret = -ENODATA;
938 for (rioidx = 0; rioidx < rio_table_hdr->num_rio_dev; rioidx++) {
939 struct rio_detail *rio = rio_devs[rioidx];
b34e90b8 940
eae93755 941 if ((rio->type != COMPAT_CALGARY) && (rio->type != ALT_CALGARY))
b34e90b8
LV
942 continue;
943
944 /* map entire 1MB of Calgary config space */
eae93755
MBY
945 bbar = ioremap_nocache(rio->BBAR, 1024 * 1024);
946 if (!bbar)
947 goto error;
b34e90b8
LV
948
949 for (phb = 0; phb < PHBS_PER_CALGARY; phb++) {
eae93755
MBY
950 offset = phb_debug_offsets[phb] | PHB_DEBUG_STUFF_OFFSET;
951 target = calgary_reg(bbar, offset);
b34e90b8 952
b34e90b8
LV
953 val = be32_to_cpu(readl(target));
954 start_bus = (u8)((val & 0x00FF0000) >> 16);
eae93755 955 end_bus = (u8)((val & 0x0000FF00) >> 8);
b34e90b8
LV
956 for (bus = start_bus; bus <= end_bus; bus++) {
957 bus_info[bus].bbar = bbar;
958 bus_info[bus].phbid = phb;
959 }
960 }
961 }
962
eae93755
MBY
963 return 0;
964
965error:
966 /* scan bus_info and iounmap any bbars we previously ioremap'd */
967 for (bus = 0; bus < ARRAY_SIZE(bus_info); bus++)
968 if (bus_info[bus].bbar)
969 iounmap(bus_info[bus].bbar);
970
971 return ret;
972}
973
974static int __init calgary_init(void)
975{
976 int ret;
977 struct pci_dev *dev = NULL;
978
979 ret = calgary_locate_bbars();
980 if (ret)
981 return ret;
e465058d 982
dedc9937 983 do {
e465058d
JM
984 dev = pci_get_device(PCI_VENDOR_ID_IBM,
985 PCI_DEVICE_ID_IBM_CALGARY,
986 dev);
987 if (!dev)
988 break;
989 if (!translate_phb(dev)) {
990 calgary_init_one_nontraslated(dev);
991 continue;
992 }
871b1700 993 if (!bus_info[dev->bus->number].tce_space && !translate_empty_slots)
e465058d 994 continue;
871b1700 995
e465058d
JM
996 ret = calgary_init_one(dev);
997 if (ret)
998 goto error;
dedc9937 999 } while (1);
e465058d
JM
1000
1001 return ret;
1002
1003error:
dedc9937 1004 do {
7cd8b686 1005 dev = pci_get_device_reverse(PCI_VENDOR_ID_IBM,
e465058d
JM
1006 PCI_DEVICE_ID_IBM_CALGARY,
1007 dev);
9f2dc46d
MBY
1008 if (!dev)
1009 break;
e465058d
JM
1010 if (!translate_phb(dev)) {
1011 pci_dev_put(dev);
1012 continue;
1013 }
f38db651 1014 if (!bus_info[dev->bus->number].tce_space && !translate_empty_slots)
e465058d 1015 continue;
871b1700 1016
e465058d 1017 calgary_disable_translation(dev);
b8f4fe66 1018 calgary_free_bus(dev);
871b1700 1019 pci_dev_put(dev); /* Undo calgary_init_one()'s pci_dev_get() */
dedc9937 1020 } while (1);
e465058d
JM
1021
1022 return ret;
1023}
1024
1025static inline int __init determine_tce_table_size(u64 ram)
1026{
1027 int ret;
1028
1029 if (specified_table_size != TCE_TABLE_SIZE_UNSPECIFIED)
1030 return specified_table_size;
1031
1032 /*
1033 * Table sizes are from 0 to 7 (TCE_TABLE_SIZE_64K to
1034 * TCE_TABLE_SIZE_8M). Table size 0 has 8K entries and each
1035 * larger table size has twice as many entries, so shift the
1036 * max ram address by 13 to divide by 8K and then look at the
1037 * order of the result to choose between 0-7.
1038 */
1039 ret = get_order(ram >> 13);
1040 if (ret > TCE_TABLE_SIZE_8M)
1041 ret = TCE_TABLE_SIZE_8M;
1042
1043 return ret;
1044}
1045
b34e90b8
LV
1046static int __init build_detail_arrays(void)
1047{
1048 unsigned long ptr;
1049 int i, scal_detail_size, rio_detail_size;
1050
1051 if (rio_table_hdr->num_scal_dev > MAX_NUMNODES){
1052 printk(KERN_WARNING
eae93755 1053 "Calgary: MAX_NUMNODES too low! Defined as %d, "
b34e90b8
LV
1054 "but system has %d nodes.\n",
1055 MAX_NUMNODES, rio_table_hdr->num_scal_dev);
1056 return -ENODEV;
1057 }
1058
1059 switch (rio_table_hdr->version){
b34e90b8
LV
1060 case 2:
1061 scal_detail_size = 11;
1062 rio_detail_size = 13;
1063 break;
1064 case 3:
1065 scal_detail_size = 12;
1066 rio_detail_size = 15;
1067 break;
eae93755
MBY
1068 default:
1069 printk(KERN_WARNING
1070 "Calgary: Invalid Rio Grande Table Version: %d\n",
1071 rio_table_hdr->version);
1072 return -EPROTO;
b34e90b8
LV
1073 }
1074
1075 ptr = ((unsigned long)rio_table_hdr) + 3;
1076 for (i = 0; i < rio_table_hdr->num_scal_dev;
1077 i++, ptr += scal_detail_size)
1078 scal_devs[i] = (struct scal_detail *)ptr;
1079
1080 for (i = 0; i < rio_table_hdr->num_rio_dev;
1081 i++, ptr += rio_detail_size)
1082 rio_devs[i] = (struct rio_detail *)ptr;
1083
1084 return 0;
1085}
1086
e465058d
JM
1087void __init detect_calgary(void)
1088{
1089 u32 val;
d2105b10 1090 int bus;
e465058d 1091 void *tbl;
d2105b10 1092 int calgary_found = 0;
b34e90b8 1093 unsigned long ptr;
136f1e7a 1094 unsigned int offset, prev_offset;
eae93755 1095 int ret;
e465058d
JM
1096
1097 /*
1098 * if the user specified iommu=off or iommu=soft or we found
1099 * another HW IOMMU already, bail out.
1100 */
1101 if (swiotlb || no_iommu || iommu_detected)
1102 return;
1103
bff6547b
MBY
1104 if (!use_calgary)
1105 return;
1106
0637a70a
AK
1107 if (!early_pci_allowed())
1108 return;
1109
b92cc559
MBY
1110 printk(KERN_DEBUG "Calgary: detecting Calgary via BIOS EBDA area\n");
1111
b34e90b8
LV
1112 ptr = (unsigned long)phys_to_virt(get_bios_ebda());
1113
1114 rio_table_hdr = NULL;
136f1e7a 1115 prev_offset = 0;
b34e90b8 1116 offset = 0x180;
136f1e7a
IM
1117 /*
1118 * The next offset is stored in the 1st word.
1119 * Only parse up until the offset increases:
1120 */
1121 while (offset > prev_offset) {
b34e90b8
LV
1122 /* The block id is stored in the 2nd word */
1123 if (*((unsigned short *)(ptr + offset + 2)) == 0x4752){
1124 /* set the pointer past the offset & block id */
eae93755 1125 rio_table_hdr = (struct rio_table_hdr *)(ptr + offset + 4);
b34e90b8
LV
1126 break;
1127 }
136f1e7a 1128 prev_offset = offset;
b34e90b8
LV
1129 offset = *((unsigned short *)(ptr + offset));
1130 }
eae93755 1131 if (!rio_table_hdr) {
b92cc559
MBY
1132 printk(KERN_DEBUG "Calgary: Unable to locate Rio Grande table "
1133 "in EBDA - bailing!\n");
b34e90b8
LV
1134 return;
1135 }
1136
eae93755
MBY
1137 ret = build_detail_arrays();
1138 if (ret) {
b92cc559 1139 printk(KERN_DEBUG "Calgary: build_detail_arrays ret %d\n", ret);
b34e90b8 1140 return;
eae93755 1141 }
b34e90b8 1142
e465058d
JM
1143 specified_table_size = determine_tce_table_size(end_pfn * PAGE_SIZE);
1144
d2105b10
JM
1145 for (bus = 0; bus < MAX_PHB_BUS_NUM; bus++) {
1146 int dev;
f38db651 1147 struct calgary_bus_info *info = &bus_info[bus];
d2105b10 1148
e465058d
JM
1149 if (read_pci_config(bus, 0, 0, 0) != PCI_VENDOR_DEVICE_ID_CALGARY)
1150 continue;
d2105b10 1151
f38db651 1152 if (info->translation_disabled)
e465058d 1153 continue;
f38db651 1154
e465058d 1155 /*
d2105b10
JM
1156 * Scan the slots of the PCI bus to see if there is a device present.
1157 * The parent bus will be the zero-ith device, so start at 1.
e465058d 1158 */
d2105b10
JM
1159 for (dev = 1; dev < 8; dev++) {
1160 val = read_pci_config(bus, dev, 0, 0);
1161 if (val != 0xffffffff || translate_empty_slots) {
1162 tbl = alloc_tce_table();
1163 if (!tbl)
1164 goto cleanup;
f38db651 1165 info->tce_space = tbl;
d2105b10
JM
1166 calgary_found = 1;
1167 break;
1168 }
1169 }
e465058d
JM
1170 }
1171
b92cc559
MBY
1172 printk(KERN_DEBUG "Calgary: finished detection, Calgary %s\n",
1173 calgary_found ? "found" : "not found");
1174
d2105b10 1175 if (calgary_found) {
e465058d
JM
1176 iommu_detected = 1;
1177 calgary_detected = 1;
de684652
MBY
1178 printk(KERN_INFO "PCI-DMA: Calgary IOMMU detected.\n");
1179 printk(KERN_INFO "PCI-DMA: Calgary TCE table spec is %d, "
1180 "CONFIG_IOMMU_DEBUG is %s.\n", specified_table_size,
1181 debugging ? "enabled" : "disabled");
e465058d
JM
1182 }
1183 return;
1184
1185cleanup:
f38db651
MBY
1186 for (--bus; bus >= 0; --bus) {
1187 struct calgary_bus_info *info = &bus_info[bus];
1188
1189 if (info->tce_space)
1190 free_tce_table(info->tce_space);
1191 }
e465058d
JM
1192}
1193
1194int __init calgary_iommu_init(void)
1195{
1196 int ret;
1197
1198 if (no_iommu || swiotlb)
1199 return -ENODEV;
1200
1201 if (!calgary_detected)
1202 return -ENODEV;
1203
1204 /* ok, we're trying to use Calgary - let's roll */
1205 printk(KERN_INFO "PCI-DMA: Using Calgary IOMMU\n");
1206
1207 ret = calgary_init();
1208 if (ret) {
1209 printk(KERN_ERR "PCI-DMA: Calgary init failed %d, "
1210 "falling back to no_iommu\n", ret);
1211 if (end_pfn > MAX_DMA32_PFN)
1212 printk(KERN_ERR "WARNING more than 4GB of memory, "
1213 "32bit PCI may malfunction.\n");
1214 return ret;
1215 }
1216
1217 force_iommu = 1;
310adfdd 1218 bad_dma_address = 0x0;
e465058d
JM
1219 dma_ops = &calgary_dma_ops;
1220
1221 return 0;
1222}
1223
1224static int __init calgary_parse_options(char *p)
1225{
1226 unsigned int bridge;
1227 size_t len;
1228 char* endp;
1229
1230 while (*p) {
1231 if (!strncmp(p, "64k", 3))
1232 specified_table_size = TCE_TABLE_SIZE_64K;
1233 else if (!strncmp(p, "128k", 4))
1234 specified_table_size = TCE_TABLE_SIZE_128K;
1235 else if (!strncmp(p, "256k", 4))
1236 specified_table_size = TCE_TABLE_SIZE_256K;
1237 else if (!strncmp(p, "512k", 4))
1238 specified_table_size = TCE_TABLE_SIZE_512K;
1239 else if (!strncmp(p, "1M", 2))
1240 specified_table_size = TCE_TABLE_SIZE_1M;
1241 else if (!strncmp(p, "2M", 2))
1242 specified_table_size = TCE_TABLE_SIZE_2M;
1243 else if (!strncmp(p, "4M", 2))
1244 specified_table_size = TCE_TABLE_SIZE_4M;
1245 else if (!strncmp(p, "8M", 2))
1246 specified_table_size = TCE_TABLE_SIZE_8M;
1247
1248 len = strlen("translate_empty_slots");
1249 if (!strncmp(p, "translate_empty_slots", len))
1250 translate_empty_slots = 1;
1251
1252 len = strlen("disable");
1253 if (!strncmp(p, "disable", len)) {
1254 p += len;
1255 if (*p == '=')
1256 ++p;
1257 if (*p == '\0')
1258 break;
1259 bridge = simple_strtol(p, &endp, 0);
1260 if (p == endp)
1261 break;
1262
d2105b10 1263 if (bridge < MAX_PHB_BUS_NUM) {
e465058d 1264 printk(KERN_INFO "Calgary: disabling "
70d666d6 1265 "translation for PHB %#x\n", bridge);
f38db651 1266 bus_info[bridge].translation_disabled = 1;
e465058d
JM
1267 }
1268 }
1269
1270 p = strpbrk(p, ",");
1271 if (!p)
1272 break;
1273
1274 p++; /* skip ',' */
1275 }
1276 return 1;
1277}
1278__setup("calgary=", calgary_parse_options);