]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/ia64/pci/pci.c
ia64/PCI/ACPI: Use common ACPI resource parsing interface for host bridge
[karo-tx-linux.git] / arch / ia64 / pci / pci.c
1 /*
2  * pci.c - Low-Level PCI Access in IA-64
3  *
4  * Derived from bios32.c of i386 tree.
5  *
6  * (c) Copyright 2002, 2005 Hewlett-Packard Development Company, L.P.
7  *      David Mosberger-Tang <davidm@hpl.hp.com>
8  *      Bjorn Helgaas <bjorn.helgaas@hp.com>
9  * Copyright (C) 2004 Silicon Graphics, Inc.
10  *
11  * Note: Above list of copyright holders is incomplete...
12  */
13
14 #include <linux/acpi.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/pci.h>
18 #include <linux/pci-acpi.h>
19 #include <linux/init.h>
20 #include <linux/ioport.h>
21 #include <linux/slab.h>
22 #include <linux/spinlock.h>
23 #include <linux/bootmem.h>
24 #include <linux/export.h>
25
26 #include <asm/machvec.h>
27 #include <asm/page.h>
28 #include <asm/io.h>
29 #include <asm/sal.h>
30 #include <asm/smp.h>
31 #include <asm/irq.h>
32 #include <asm/hw_irq.h>
33
34 /*
35  * Low-level SAL-based PCI configuration access functions. Note that SAL
36  * calls are already serialized (via sal_lock), so we don't need another
37  * synchronization mechanism here.
38  */
39
40 #define PCI_SAL_ADDRESS(seg, bus, devfn, reg)           \
41         (((u64) seg << 24) | (bus << 16) | (devfn << 8) | (reg))
42
43 /* SAL 3.2 adds support for extended config space. */
44
45 #define PCI_SAL_EXT_ADDRESS(seg, bus, devfn, reg)       \
46         (((u64) seg << 28) | (bus << 20) | (devfn << 12) | (reg))
47
48 int raw_pci_read(unsigned int seg, unsigned int bus, unsigned int devfn,
49               int reg, int len, u32 *value)
50 {
51         u64 addr, data = 0;
52         int mode, result;
53
54         if (!value || (seg > 65535) || (bus > 255) || (devfn > 255) || (reg > 4095))
55                 return -EINVAL;
56
57         if ((seg | reg) <= 255) {
58                 addr = PCI_SAL_ADDRESS(seg, bus, devfn, reg);
59                 mode = 0;
60         } else if (sal_revision >= SAL_VERSION_CODE(3,2)) {
61                 addr = PCI_SAL_EXT_ADDRESS(seg, bus, devfn, reg);
62                 mode = 1;
63         } else {
64                 return -EINVAL;
65         }
66
67         result = ia64_sal_pci_config_read(addr, mode, len, &data);
68         if (result != 0)
69                 return -EINVAL;
70
71         *value = (u32) data;
72         return 0;
73 }
74
75 int raw_pci_write(unsigned int seg, unsigned int bus, unsigned int devfn,
76                int reg, int len, u32 value)
77 {
78         u64 addr;
79         int mode, result;
80
81         if ((seg > 65535) || (bus > 255) || (devfn > 255) || (reg > 4095))
82                 return -EINVAL;
83
84         if ((seg | reg) <= 255) {
85                 addr = PCI_SAL_ADDRESS(seg, bus, devfn, reg);
86                 mode = 0;
87         } else if (sal_revision >= SAL_VERSION_CODE(3,2)) {
88                 addr = PCI_SAL_EXT_ADDRESS(seg, bus, devfn, reg);
89                 mode = 1;
90         } else {
91                 return -EINVAL;
92         }
93         result = ia64_sal_pci_config_write(addr, mode, len, value);
94         if (result != 0)
95                 return -EINVAL;
96         return 0;
97 }
98
99 static int pci_read(struct pci_bus *bus, unsigned int devfn, int where,
100                                                         int size, u32 *value)
101 {
102         return raw_pci_read(pci_domain_nr(bus), bus->number,
103                                  devfn, where, size, value);
104 }
105
106 static int pci_write(struct pci_bus *bus, unsigned int devfn, int where,
107                                                         int size, u32 value)
108 {
109         return raw_pci_write(pci_domain_nr(bus), bus->number,
110                                   devfn, where, size, value);
111 }
112
113 struct pci_ops pci_root_ops = {
114         .read = pci_read,
115         .write = pci_write,
116 };
117
118 struct pci_root_info {
119         struct pci_controller controller;
120         struct acpi_device *bridge;
121         struct list_head resources;
122         struct list_head io_resources;
123         char name[16];
124 };
125
126 static unsigned int
127 new_space (u64 phys_base, int sparse)
128 {
129         u64 mmio_base;
130         int i;
131
132         if (phys_base == 0)
133                 return 0;       /* legacy I/O port space */
134
135         mmio_base = (u64) ioremap(phys_base, 0);
136         for (i = 0; i < num_io_spaces; i++)
137                 if (io_space[i].mmio_base == mmio_base &&
138                     io_space[i].sparse == sparse)
139                         return i;
140
141         if (num_io_spaces == MAX_IO_SPACES) {
142                 pr_err("PCI: Too many IO port spaces "
143                         "(MAX_IO_SPACES=%lu)\n", MAX_IO_SPACES);
144                 return ~0;
145         }
146
147         i = num_io_spaces++;
148         io_space[i].mmio_base = mmio_base;
149         io_space[i].sparse = sparse;
150
151         return i;
152 }
153
154 static int add_io_space(struct device *dev, struct pci_root_info *info,
155                         struct resource_entry *entry)
156 {
157         struct iospace_resource *iospace;
158         struct resource *resource, *res = entry->res;
159         char *name;
160         unsigned long base, min, max, base_port;
161         unsigned int sparse = 0, space_nr, len;
162
163         len = strlen(info->name) + 32;
164         iospace = kzalloc(sizeof(*iospace) + len, GFP_KERNEL);
165         if (!iospace) {
166                 dev_err(dev, "PCI: No memory for %s I/O port space\n",
167                         info->name);
168                 return -ENOMEM;
169         }
170
171         if (res->flags & IORESOURCE_IO_SPARSE)
172                 sparse = 1;
173         space_nr = new_space(entry->offset, sparse);
174         if (space_nr == ~0)
175                 goto free_resource;
176
177         name = (char *)(iospace + 1);
178         min = res->start - entry->offset;
179         max = res->end - entry->offset;
180         base = __pa(io_space[space_nr].mmio_base);
181         base_port = IO_SPACE_BASE(space_nr);
182         snprintf(name, len, "%s I/O Ports %08lx-%08lx", info->name,
183                  base_port + min, base_port + max);
184
185         /*
186          * The SDM guarantees the legacy 0-64K space is sparse, but if the
187          * mapping is done by the processor (not the bridge), ACPI may not
188          * mark it as sparse.
189          */
190         if (space_nr == 0)
191                 sparse = 1;
192
193         resource = &iospace->res;
194         resource->name  = name;
195         resource->flags = IORESOURCE_MEM;
196         resource->start = base + (sparse ? IO_SPACE_SPARSE_ENCODING(min) : min);
197         resource->end   = base + (sparse ? IO_SPACE_SPARSE_ENCODING(max) : max);
198         if (insert_resource(&iomem_resource, resource)) {
199                 dev_err(dev,
200                         "can't allocate host bridge io space resource  %pR\n",
201                         resource);
202                 goto free_resource;
203         }
204
205         entry->offset = base_port;
206         res->start = min + base_port;
207         res->end = max + base_port;
208         list_add_tail(&iospace->list, &info->io_resources);
209
210         return 0;
211
212 free_resource:
213         kfree(iospace);
214         return -ENOSPC;
215 }
216
217 /*
218  * An IO port or MMIO resource assigned to a PCI host bridge may be
219  * consumed by the host bridge itself or available to its child
220  * bus/devices. The ACPI specification defines a bit (Producer/Consumer)
221  * to tell whether the resource is consumed by the host bridge itself,
222  * but firmware hasn't used that bit consistently, so we can't rely on it.
223  *
224  * On x86 and IA64 platforms, all IO port and MMIO resources are assumed
225  * to be available to child bus/devices except one special case:
226  *     IO port [0xCF8-0xCFF] is consumed by the host bridge itself
227  *     to access PCI configuration space.
228  *
229  * So explicitly filter out PCI CFG IO ports[0xCF8-0xCFF].
230  */
231 static bool resource_is_pcicfg_ioport(struct resource *res)
232 {
233         return (res->flags & IORESOURCE_IO) &&
234                 res->start == 0xCF8 && res->end == 0xCFF;
235 }
236
237 static int
238 probe_pci_root_info(struct pci_root_info *info, struct acpi_device *device,
239                     int busnum, int domain)
240 {
241         int ret;
242         struct list_head *list = &info->resources;
243         struct resource_entry *entry, *tmp;
244
245         ret = acpi_dev_get_resources(device, list,
246                                      acpi_dev_filter_resource_type_cb,
247                                      (void *)(IORESOURCE_IO | IORESOURCE_MEM));
248         if (ret < 0)
249                 dev_warn(&device->dev,
250                          "failed to parse _CRS method, error code %d\n", ret);
251         else if (ret == 0)
252                 dev_dbg(&device->dev,
253                         "no IO and memory resources present in _CRS\n");
254         else
255                 resource_list_for_each_entry_safe(entry, tmp, list) {
256                         if ((entry->res->flags & IORESOURCE_DISABLED) ||
257                             resource_is_pcicfg_ioport(entry->res))
258                                 resource_list_destroy_entry(entry);
259                         else
260                                 entry->res->name = info->name;
261                 }
262
263         return ret;
264 }
265
266 static void validate_resources(struct device *dev, struct list_head *resources,
267                                unsigned long type)
268 {
269         LIST_HEAD(list);
270         struct resource *res1, *res2, *root = NULL;
271         struct resource_entry *tmp, *entry, *entry2;
272
273         BUG_ON((type & (IORESOURCE_MEM | IORESOURCE_IO)) == 0);
274         root = (type & IORESOURCE_MEM) ? &iomem_resource : &ioport_resource;
275
276         list_splice_init(resources, &list);
277         resource_list_for_each_entry_safe(entry, tmp, &list) {
278                 bool free = false;
279                 resource_size_t end;
280
281                 res1 = entry->res;
282                 if (!(res1->flags & type))
283                         goto next;
284
285                 /* Exclude non-addressable range or non-addressable portion */
286                 end = min(res1->end, root->end);
287                 if (end <= res1->start) {
288                         dev_info(dev, "host bridge window %pR (ignored, not CPU addressable)\n",
289                                  res1);
290                         free = true;
291                         goto next;
292                 } else if (res1->end != end) {
293                         dev_info(dev, "host bridge window %pR ([%#llx-%#llx] ignored, not CPU addressable)\n",
294                                  res1, (unsigned long long)end + 1,
295                                  (unsigned long long)res1->end);
296                         res1->end = end;
297                 }
298
299                 resource_list_for_each_entry(entry2, resources) {
300                         res2 = entry2->res;
301                         if (!(res2->flags & type))
302                                 continue;
303
304                         /*
305                          * I don't like throwing away windows because then
306                          * our resources no longer match the ACPI _CRS, but
307                          * the kernel resource tree doesn't allow overlaps.
308                          */
309                         if (resource_overlaps(res1, res2)) {
310                                 res2->start = min(res1->start, res2->start);
311                                 res2->end = max(res1->end, res2->end);
312                                 dev_info(dev, "host bridge window expanded to %pR; %pR ignored\n",
313                                          res2, res1);
314                                 free = true;
315                                 goto next;
316                         }
317                 }
318
319 next:
320                 resource_list_del(entry);
321                 if (free)
322                         resource_list_free_entry(entry);
323                 else
324                         resource_list_add_tail(entry, resources);
325         }
326 }
327
328 static void add_resources(struct pci_root_info *info, struct device *dev)
329 {
330         struct resource_entry *entry, *tmp;
331         struct resource *res, *conflict, *root = NULL;
332         struct list_head *list = &info->resources;
333
334         validate_resources(dev, list, IORESOURCE_MEM);
335         validate_resources(dev, list, IORESOURCE_IO);
336
337         resource_list_for_each_entry_safe(entry, tmp, list) {
338                 res = entry->res;
339                 if (res->flags & IORESOURCE_MEM) {
340                         root = &iomem_resource;
341                         /*
342                          * HP's firmware has a hack to work around a Windows
343                          * bug. Ignore these tiny memory ranges.
344                          */
345                         if (resource_size(res) <= 16) {
346                                 resource_list_destroy_entry(entry);
347                                 continue;
348                         }
349                 } else if (res->flags & IORESOURCE_IO) {
350                         root = &ioport_resource;
351                         if (add_io_space(&info->bridge->dev, info, entry)) {
352                                 resource_list_destroy_entry(entry);
353                                 continue;
354                         }
355                 } else {
356                         BUG_ON(res);
357                 }
358
359                 conflict = insert_resource_conflict(root, res);
360                 if (conflict) {
361                         dev_info(dev,
362                                  "ignoring host bridge window %pR (conflicts with %s %pR)\n",
363                                  res, conflict->name, conflict);
364                         resource_list_destroy_entry(entry);
365                 }
366         }
367 }
368
369 static void __release_pci_root_info(struct pci_root_info *info)
370 {
371         struct resource *res;
372         struct iospace_resource *iospace, *tmp;
373         struct resource_entry *entry, *tentry;
374
375         list_for_each_entry_safe(iospace, tmp, &info->io_resources, list) {
376                 release_resource(&iospace->res);
377                 kfree(iospace);
378         }
379
380         resource_list_for_each_entry_safe(entry, tentry, &info->resources) {
381                 res = entry->res;
382                 if (res->parent &&
383                     (res->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
384                         release_resource(res);
385                 resource_list_destroy_entry(entry);
386         }
387
388         kfree(info);
389 }
390
391 static void release_pci_root_info(struct pci_host_bridge *bridge)
392 {
393         struct pci_root_info *info = bridge->release_data;
394
395         __release_pci_root_info(info);
396 }
397
398 struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
399 {
400         struct acpi_device *device = root->device;
401         int domain = root->segment;
402         int bus = root->secondary.start;
403         struct pci_root_info *info;
404         struct pci_bus *pbus;
405         int ret;
406
407         info = kzalloc(sizeof(*info), GFP_KERNEL);
408         if (!info) {
409                 dev_err(&device->dev,
410                         "pci_bus %04x:%02x: ignored (out of memory)\n",
411                         domain, bus);
412                 return NULL;
413         }
414
415         info->controller.segment = domain;
416         info->controller.companion = device;
417         info->controller.node = acpi_get_node(device->handle);
418         info->bridge = device;
419         INIT_LIST_HEAD(&info->resources);
420         INIT_LIST_HEAD(&info->io_resources);
421         snprintf(info->name, sizeof(info->name),
422                  "PCI Bus %04x:%02x", domain, bus);
423
424         ret = probe_pci_root_info(info, device, bus, domain);
425         if (ret <= 0) {
426                 kfree(info);
427                 return NULL;
428         }
429         add_resources(info, &info->bridge->dev);
430         pci_add_resource(&info->resources, &root->secondary);
431
432         /*
433          * See arch/x86/pci/acpi.c.
434          * The desired pci bus might already be scanned in a quirk. We
435          * should handle the case here, but it appears that IA64 hasn't
436          * such quirk. So we just ignore the case now.
437          */
438         pbus = pci_create_root_bus(NULL, bus, &pci_root_ops,
439                                    &info->controller, &info->resources);
440         if (!pbus) {
441                 __release_pci_root_info(info);
442                 return NULL;
443         }
444
445         pci_set_host_bridge_release(to_pci_host_bridge(pbus->bridge),
446                         release_pci_root_info, info);
447         pci_scan_child_bus(pbus);
448         return pbus;
449 }
450
451 int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
452 {
453         /*
454          * We pass NULL as parent to pci_create_root_bus(), so if it is not NULL
455          * here, pci_create_root_bus() has been called by someone else and
456          * sysdata is likely to be different from what we expect.  Let it go in
457          * that case.
458          */
459         if (!bridge->dev.parent) {
460                 struct pci_controller *controller = bridge->bus->sysdata;
461                 ACPI_COMPANION_SET(&bridge->dev, controller->companion);
462         }
463         return 0;
464 }
465
466 void pcibios_fixup_device_resources(struct pci_dev *dev)
467 {
468         int idx;
469
470         if (!dev->bus)
471                 return;
472
473         for (idx = 0; idx < PCI_BRIDGE_RESOURCES; idx++) {
474                 struct resource *r = &dev->resource[idx];
475
476                 if (!r->flags || r->parent || !r->start)
477                         continue;
478
479                 pci_claim_resource(dev, idx);
480         }
481 }
482 EXPORT_SYMBOL_GPL(pcibios_fixup_device_resources);
483
484 static void pcibios_fixup_bridge_resources(struct pci_dev *dev)
485 {
486         int idx;
487
488         if (!dev->bus)
489                 return;
490
491         for (idx = PCI_BRIDGE_RESOURCES; idx < PCI_NUM_RESOURCES; idx++) {
492                 struct resource *r = &dev->resource[idx];
493
494                 if (!r->flags || r->parent || !r->start)
495                         continue;
496
497                 pci_claim_bridge_resource(dev, idx);
498         }
499 }
500
501 /*
502  *  Called after each bus is probed, but before its children are examined.
503  */
504 void pcibios_fixup_bus(struct pci_bus *b)
505 {
506         struct pci_dev *dev;
507
508         if (b->self) {
509                 pci_read_bridge_bases(b);
510                 pcibios_fixup_bridge_resources(b->self);
511         }
512         list_for_each_entry(dev, &b->devices, bus_list)
513                 pcibios_fixup_device_resources(dev);
514         platform_pci_fixup_bus(b);
515 }
516
517 void pcibios_add_bus(struct pci_bus *bus)
518 {
519         acpi_pci_add_bus(bus);
520 }
521
522 void pcibios_remove_bus(struct pci_bus *bus)
523 {
524         acpi_pci_remove_bus(bus);
525 }
526
527 void pcibios_set_master (struct pci_dev *dev)
528 {
529         /* No special bus mastering setup handling */
530 }
531
532 int
533 pcibios_enable_device (struct pci_dev *dev, int mask)
534 {
535         int ret;
536
537         ret = pci_enable_resources(dev, mask);
538         if (ret < 0)
539                 return ret;
540
541         if (!dev->msi_enabled)
542                 return acpi_pci_irq_enable(dev);
543         return 0;
544 }
545
546 void
547 pcibios_disable_device (struct pci_dev *dev)
548 {
549         BUG_ON(atomic_read(&dev->enable_cnt));
550         if (!dev->msi_enabled)
551                 acpi_pci_irq_disable(dev);
552 }
553
554 resource_size_t
555 pcibios_align_resource (void *data, const struct resource *res,
556                         resource_size_t size, resource_size_t align)
557 {
558         return res->start;
559 }
560
561 int
562 pci_mmap_page_range (struct pci_dev *dev, struct vm_area_struct *vma,
563                      enum pci_mmap_state mmap_state, int write_combine)
564 {
565         unsigned long size = vma->vm_end - vma->vm_start;
566         pgprot_t prot;
567
568         /*
569          * I/O space cannot be accessed via normal processor loads and
570          * stores on this platform.
571          */
572         if (mmap_state == pci_mmap_io)
573                 /*
574                  * XXX we could relax this for I/O spaces for which ACPI
575                  * indicates that the space is 1-to-1 mapped.  But at the
576                  * moment, we don't support multiple PCI address spaces and
577                  * the legacy I/O space is not 1-to-1 mapped, so this is moot.
578                  */
579                 return -EINVAL;
580
581         if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size))
582                 return -EINVAL;
583
584         prot = phys_mem_access_prot(NULL, vma->vm_pgoff, size,
585                                     vma->vm_page_prot);
586
587         /*
588          * If the user requested WC, the kernel uses UC or WC for this region,
589          * and the chipset supports WC, we can use WC. Otherwise, we have to
590          * use the same attribute the kernel uses.
591          */
592         if (write_combine &&
593             ((pgprot_val(prot) & _PAGE_MA_MASK) == _PAGE_MA_UC ||
594              (pgprot_val(prot) & _PAGE_MA_MASK) == _PAGE_MA_WC) &&
595             efi_range_is_wc(vma->vm_start, vma->vm_end - vma->vm_start))
596                 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
597         else
598                 vma->vm_page_prot = prot;
599
600         if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
601                              vma->vm_end - vma->vm_start, vma->vm_page_prot))
602                 return -EAGAIN;
603
604         return 0;
605 }
606
607 /**
608  * ia64_pci_get_legacy_mem - generic legacy mem routine
609  * @bus: bus to get legacy memory base address for
610  *
611  * Find the base of legacy memory for @bus.  This is typically the first
612  * megabyte of bus address space for @bus or is simply 0 on platforms whose
613  * chipsets support legacy I/O and memory routing.  Returns the base address
614  * or an error pointer if an error occurred.
615  *
616  * This is the ia64 generic version of this routine.  Other platforms
617  * are free to override it with a machine vector.
618  */
619 char *ia64_pci_get_legacy_mem(struct pci_bus *bus)
620 {
621         return (char *)__IA64_UNCACHED_OFFSET;
622 }
623
624 /**
625  * pci_mmap_legacy_page_range - map legacy memory space to userland
626  * @bus: bus whose legacy space we're mapping
627  * @vma: vma passed in by mmap
628  *
629  * Map legacy memory space for this device back to userspace using a machine
630  * vector to get the base address.
631  */
632 int
633 pci_mmap_legacy_page_range(struct pci_bus *bus, struct vm_area_struct *vma,
634                            enum pci_mmap_state mmap_state)
635 {
636         unsigned long size = vma->vm_end - vma->vm_start;
637         pgprot_t prot;
638         char *addr;
639
640         /* We only support mmap'ing of legacy memory space */
641         if (mmap_state != pci_mmap_mem)
642                 return -ENOSYS;
643
644         /*
645          * Avoid attribute aliasing.  See Documentation/ia64/aliasing.txt
646          * for more details.
647          */
648         if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size))
649                 return -EINVAL;
650         prot = phys_mem_access_prot(NULL, vma->vm_pgoff, size,
651                                     vma->vm_page_prot);
652
653         addr = pci_get_legacy_mem(bus);
654         if (IS_ERR(addr))
655                 return PTR_ERR(addr);
656
657         vma->vm_pgoff += (unsigned long)addr >> PAGE_SHIFT;
658         vma->vm_page_prot = prot;
659
660         if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
661                             size, vma->vm_page_prot))
662                 return -EAGAIN;
663
664         return 0;
665 }
666
667 /**
668  * ia64_pci_legacy_read - read from legacy I/O space
669  * @bus: bus to read
670  * @port: legacy port value
671  * @val: caller allocated storage for returned value
672  * @size: number of bytes to read
673  *
674  * Simply reads @size bytes from @port and puts the result in @val.
675  *
676  * Again, this (and the write routine) are generic versions that can be
677  * overridden by the platform.  This is necessary on platforms that don't
678  * support legacy I/O routing or that hard fail on legacy I/O timeouts.
679  */
680 int ia64_pci_legacy_read(struct pci_bus *bus, u16 port, u32 *val, u8 size)
681 {
682         int ret = size;
683
684         switch (size) {
685         case 1:
686                 *val = inb(port);
687                 break;
688         case 2:
689                 *val = inw(port);
690                 break;
691         case 4:
692                 *val = inl(port);
693                 break;
694         default:
695                 ret = -EINVAL;
696                 break;
697         }
698
699         return ret;
700 }
701
702 /**
703  * ia64_pci_legacy_write - perform a legacy I/O write
704  * @bus: bus pointer
705  * @port: port to write
706  * @val: value to write
707  * @size: number of bytes to write from @val
708  *
709  * Simply writes @size bytes of @val to @port.
710  */
711 int ia64_pci_legacy_write(struct pci_bus *bus, u16 port, u32 val, u8 size)
712 {
713         int ret = size;
714
715         switch (size) {
716         case 1:
717                 outb(val, port);
718                 break;
719         case 2:
720                 outw(val, port);
721                 break;
722         case 4:
723                 outl(val, port);
724                 break;
725         default:
726                 ret = -EINVAL;
727                 break;
728         }
729
730         return ret;
731 }
732
733 /**
734  * set_pci_cacheline_size - determine cacheline size for PCI devices
735  *
736  * We want to use the line-size of the outer-most cache.  We assume
737  * that this line-size is the same for all CPUs.
738  *
739  * Code mostly taken from arch/ia64/kernel/palinfo.c:cache_info().
740  */
741 static void __init set_pci_dfl_cacheline_size(void)
742 {
743         unsigned long levels, unique_caches;
744         long status;
745         pal_cache_config_info_t cci;
746
747         status = ia64_pal_cache_summary(&levels, &unique_caches);
748         if (status != 0) {
749                 pr_err("%s: ia64_pal_cache_summary() failed "
750                         "(status=%ld)\n", __func__, status);
751                 return;
752         }
753
754         status = ia64_pal_cache_config_info(levels - 1,
755                                 /* cache_type (data_or_unified)= */ 2, &cci);
756         if (status != 0) {
757                 pr_err("%s: ia64_pal_cache_config_info() failed "
758                         "(status=%ld)\n", __func__, status);
759                 return;
760         }
761         pci_dfl_cache_line_size = (1 << cci.pcci_line_size) / 4;
762 }
763
764 u64 ia64_dma_get_required_mask(struct device *dev)
765 {
766         u32 low_totalram = ((max_pfn - 1) << PAGE_SHIFT);
767         u32 high_totalram = ((max_pfn - 1) >> (32 - PAGE_SHIFT));
768         u64 mask;
769
770         if (!high_totalram) {
771                 /* convert to mask just covering totalram */
772                 low_totalram = (1 << (fls(low_totalram) - 1));
773                 low_totalram += low_totalram - 1;
774                 mask = low_totalram;
775         } else {
776                 high_totalram = (1 << (fls(high_totalram) - 1));
777                 high_totalram += high_totalram - 1;
778                 mask = (((u64)high_totalram) << 32) + 0xffffffff;
779         }
780         return mask;
781 }
782 EXPORT_SYMBOL_GPL(ia64_dma_get_required_mask);
783
784 u64 dma_get_required_mask(struct device *dev)
785 {
786         return platform_dma_get_required_mask(dev);
787 }
788 EXPORT_SYMBOL_GPL(dma_get_required_mask);
789
790 static int __init pcibios_init(void)
791 {
792         set_pci_dfl_cacheline_size();
793         return 0;
794 }
795
796 subsys_initcall(pcibios_init);