x86/mm/pat: Don't report PAT on CPUs that don't support it
[linux/fpc-iii.git] / arch / ia64 / sn / kernel / io_init.c
blobd63809a6adfadbd87e4b3ad0cbf658de05d3bf45
1 /*
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
4 * for more details.
6 * Copyright (C) 1992 - 1997, 2000-2006 Silicon Graphics, Inc. All rights reserved.
7 */
9 #include <linux/slab.h>
10 #include <linux/export.h>
11 #include <asm/sn/types.h>
12 #include <asm/sn/addrs.h>
13 #include <asm/sn/io.h>
14 #include <asm/sn/module.h>
15 #include <asm/sn/intr.h>
16 #include <asm/sn/pcibus_provider_defs.h>
17 #include <asm/sn/pcidev.h>
18 #include <asm/sn/sn_sal.h>
19 #include "xtalk/hubdev.h"
22 * The code in this file will only be executed when running with
23 * a PROM that does _not_ have base ACPI IO support.
24 * (i.e., SN_ACPI_BASE_SUPPORT() == 0)
27 static int max_segment_number; /* Default highest segment number */
28 static int max_pcibus_number = 255; /* Default highest pci bus number */
32 * Retrieve the hub device info structure for the given nasid.
34 static inline u64 sal_get_hubdev_info(u64 handle, u64 address)
36 struct ia64_sal_retval ret_stuff;
37 ret_stuff.status = 0;
38 ret_stuff.v0 = 0;
40 SAL_CALL_NOLOCK(ret_stuff,
41 (u64) SN_SAL_IOIF_GET_HUBDEV_INFO,
42 (u64) handle, (u64) address, 0, 0, 0, 0, 0);
43 return ret_stuff.v0;
47 * Retrieve the pci bus information given the bus number.
49 static inline u64 sal_get_pcibus_info(u64 segment, u64 busnum, u64 address)
51 struct ia64_sal_retval ret_stuff;
52 ret_stuff.status = 0;
53 ret_stuff.v0 = 0;
55 SAL_CALL_NOLOCK(ret_stuff,
56 (u64) SN_SAL_IOIF_GET_PCIBUS_INFO,
57 (u64) segment, (u64) busnum, (u64) address, 0, 0, 0, 0);
58 return ret_stuff.v0;
62 * Retrieve the pci device information given the bus and device|function number.
64 static inline u64
65 sal_get_pcidev_info(u64 segment, u64 bus_number, u64 devfn, u64 pci_dev,
66 u64 sn_irq_info)
68 struct ia64_sal_retval ret_stuff;
69 ret_stuff.status = 0;
70 ret_stuff.v0 = 0;
72 SAL_CALL_NOLOCK(ret_stuff,
73 (u64) SN_SAL_IOIF_GET_PCIDEV_INFO,
74 (u64) segment, (u64) bus_number, (u64) devfn,
75 (u64) pci_dev,
76 sn_irq_info, 0, 0);
77 return ret_stuff.v0;
82 * sn_fixup_ionodes() - This routine initializes the HUB data structure for
83 * each node in the system. This function is only
84 * executed when running with a non-ACPI capable PROM.
86 static void __init sn_fixup_ionodes(void)
89 struct hubdev_info *hubdev;
90 u64 status;
91 u64 nasid;
92 int i;
93 extern void sn_common_hubdev_init(struct hubdev_info *);
96 * Get SGI Specific HUB chipset information.
97 * Inform Prom that this kernel can support domain bus numbering.
99 for (i = 0; i < num_cnodes; i++) {
100 hubdev = (struct hubdev_info *)(NODEPDA(i)->pdinfo);
101 nasid = cnodeid_to_nasid(i);
102 hubdev->max_segment_number = 0xffffffff;
103 hubdev->max_pcibus_number = 0xff;
104 status = sal_get_hubdev_info(nasid, (u64) __pa(hubdev));
105 if (status)
106 continue;
108 /* Save the largest Domain and pcibus numbers found. */
109 if (hubdev->max_segment_number) {
111 * Dealing with a Prom that supports segments.
113 max_segment_number = hubdev->max_segment_number;
114 max_pcibus_number = hubdev->max_pcibus_number;
116 sn_common_hubdev_init(hubdev);
121 * sn_pci_legacy_window_fixup - Setup PCI resources for
122 * legacy IO and MEM space. This needs to
123 * be done here, as the PROM does not have
124 * ACPI support defining the root buses
125 * and their resources (_CRS),
127 static void
128 sn_legacy_pci_window_fixup(struct resource *res,
129 u64 legacy_io, u64 legacy_mem)
131 res[0].name = "legacy_io";
132 res[0].flags = IORESOURCE_IO;
133 res[0].start = legacy_io;
134 res[0].end = res[0].start + 0xffff;
135 res[0].parent = &ioport_resource;
136 res[1].name = "legacy_mem";
137 res[1].flags = IORESOURCE_MEM;
138 res[1].start = legacy_mem;
139 res[1].end = res[1].start + (1024 * 1024) - 1;
140 res[1].parent = &iomem_resource;
144 * sn_io_slot_fixup() - We are not running with an ACPI capable PROM,
145 * and need to convert the pci_dev->resource
146 * 'start' and 'end' addresses to mapped addresses,
147 * and setup the pci_controller->window array entries.
149 void
150 sn_io_slot_fixup(struct pci_dev *dev)
152 int idx;
153 struct resource *res;
154 unsigned long size;
155 struct pcidev_info *pcidev_info;
156 struct sn_irq_info *sn_irq_info;
157 int status;
159 pcidev_info = kzalloc(sizeof(struct pcidev_info), GFP_KERNEL);
160 if (!pcidev_info)
161 panic("%s: Unable to alloc memory for pcidev_info", __func__);
163 sn_irq_info = kzalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
164 if (!sn_irq_info)
165 panic("%s: Unable to alloc memory for sn_irq_info", __func__);
167 /* Call to retrieve pci device information needed by kernel. */
168 status = sal_get_pcidev_info((u64) pci_domain_nr(dev),
169 (u64) dev->bus->number,
170 dev->devfn,
171 (u64) __pa(pcidev_info),
172 (u64) __pa(sn_irq_info));
174 BUG_ON(status); /* Cannot get platform pci device information */
177 /* Copy over PIO Mapped Addresses */
178 for (idx = 0; idx <= PCI_ROM_RESOURCE; idx++) {
179 if (!pcidev_info->pdi_pio_mapped_addr[idx])
180 continue;
182 res = &dev->resource[idx];
184 size = res->end - res->start;
185 if (size == 0)
186 continue;
188 res->start = pcidev_info->pdi_pio_mapped_addr[idx];
189 res->end = res->start + size;
192 * if it's already in the device structure, remove it before
193 * inserting
195 if (res->parent && res->parent->child)
196 release_resource(res);
198 if (res->flags & IORESOURCE_IO)
199 insert_resource(&ioport_resource, res);
200 else
201 insert_resource(&iomem_resource, res);
203 * If ROM, mark as shadowed in PROM.
205 if (idx == PCI_ROM_RESOURCE) {
206 pci_disable_rom(dev);
207 res->flags = IORESOURCE_MEM | IORESOURCE_ROM_SHADOW |
208 IORESOURCE_PCI_FIXED;
212 sn_pci_fixup_slot(dev, pcidev_info, sn_irq_info);
214 EXPORT_SYMBOL(sn_io_slot_fixup);
217 * sn_pci_controller_fixup() - This routine sets up a bus's resources
218 * consistent with the Linux PCI abstraction layer.
220 static void __init
221 sn_pci_controller_fixup(int segment, int busnum, struct pci_bus *bus)
223 s64 status = 0;
224 struct pci_controller *controller;
225 struct pcibus_bussoft *prom_bussoft_ptr;
226 struct resource *res;
227 LIST_HEAD(resources);
229 status = sal_get_pcibus_info((u64) segment, (u64) busnum,
230 (u64) ia64_tpa(&prom_bussoft_ptr));
231 if (status > 0)
232 return; /*bus # does not exist */
233 prom_bussoft_ptr = __va(prom_bussoft_ptr);
235 controller = kzalloc(sizeof(*controller), GFP_KERNEL);
236 BUG_ON(!controller);
237 controller->segment = segment;
239 res = kcalloc(2, sizeof(struct resource), GFP_KERNEL);
240 BUG_ON(!res);
243 * Temporarily save the prom_bussoft_ptr for use by sn_bus_fixup().
244 * (platform_data will be overwritten later in sn_common_bus_fixup())
246 controller->platform_data = prom_bussoft_ptr;
248 sn_legacy_pci_window_fixup(res,
249 prom_bussoft_ptr->bs_legacy_io,
250 prom_bussoft_ptr->bs_legacy_mem);
251 pci_add_resource_offset(&resources, &res[0],
252 prom_bussoft_ptr->bs_legacy_io);
253 pci_add_resource_offset(&resources, &res[1],
254 prom_bussoft_ptr->bs_legacy_mem);
256 bus = pci_scan_root_bus(NULL, busnum, &pci_root_ops, controller,
257 &resources);
258 if (bus == NULL) {
259 kfree(res);
260 kfree(controller);
261 return;
263 pci_bus_add_devices(bus);
267 * sn_bus_fixup
269 void
270 sn_bus_fixup(struct pci_bus *bus)
272 struct pci_dev *pci_dev = NULL;
273 struct pcibus_bussoft *prom_bussoft_ptr;
275 if (!bus->parent) { /* If root bus */
276 prom_bussoft_ptr = PCI_CONTROLLER(bus)->platform_data;
277 if (prom_bussoft_ptr == NULL) {
278 printk(KERN_ERR
279 "sn_bus_fixup: 0x%04x:0x%02x Unable to "
280 "obtain prom_bussoft_ptr\n",
281 pci_domain_nr(bus), bus->number);
282 return;
284 sn_common_bus_fixup(bus, prom_bussoft_ptr);
286 list_for_each_entry(pci_dev, &bus->devices, bus_list) {
287 sn_io_slot_fixup(pci_dev);
293 * sn_io_init - PROM does not have ACPI support to define nodes or root buses,
294 * so we need to do things the hard way, including initiating the
295 * bus scanning ourselves.
298 void __init sn_io_init(void)
300 int i, j;
302 sn_fixup_ionodes();
304 /* busses are not known yet ... */
305 for (i = 0; i <= max_segment_number; i++)
306 for (j = 0; j <= max_pcibus_number; j++)
307 sn_pci_controller_fixup(i, j, NULL);