blob: 7e1a9b6717b5a988f2bc9cc76437a15a10a89eec [file] [log] [blame]
David S. Miller861fe902007-05-02 17:31:36 -07001/* pci_fire.c: Sun4u platform PCI-E controller support.
2 *
3 * Copyright (C) 2007 David S. Miller (davem@davemloft.net)
4 */
5#include <linux/kernel.h>
6#include <linux/pci.h>
7#include <linux/slab.h>
8#include <linux/init.h>
David S. Miller9bb3c222007-08-30 22:33:25 -07009#include <linux/msi.h>
10#include <linux/irq.h>
David S. Millerc8049962008-08-30 03:12:38 -070011#include <linux/of_device.h>
David S. Miller861fe902007-05-02 17:31:36 -070012
David S. Miller861fe902007-05-02 17:31:36 -070013#include <asm/prom.h>
David S. Miller9bb3c222007-08-30 22:33:25 -070014#include <asm/irq.h>
David S. Miller861fe902007-05-02 17:31:36 -070015
16#include "pci_impl.h"
17
David S. Millerc8049962008-08-30 03:12:38 -070018#define DRIVER_NAME "fire"
19#define PFX DRIVER_NAME ": "
20
David S. Miller861fe902007-05-02 17:31:36 -070021#define fire_read(__reg) \
22({ u64 __ret; \
23 __asm__ __volatile__("ldxa [%1] %2, %0" \
24 : "=r" (__ret) \
25 : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
26 : "memory"); \
27 __ret; \
28})
29#define fire_write(__reg, __val) \
30 __asm__ __volatile__("stxa %0, [%1] %2" \
31 : /* no outputs */ \
32 : "r" (__val), "r" (__reg), \
33 "i" (ASI_PHYS_BYPASS_EC_E) \
34 : "memory")
35
David S. Miller861fe902007-05-02 17:31:36 -070036#define FIRE_IOMMU_CONTROL 0x40000UL
37#define FIRE_IOMMU_TSBBASE 0x40008UL
38#define FIRE_IOMMU_FLUSH 0x40100UL
David S. Miller95d71e62007-05-11 21:02:09 -070039#define FIRE_IOMMU_FLUSHINV 0x40108UL
David S. Miller861fe902007-05-02 17:31:36 -070040
David S. Millerad7ad572007-07-27 22:39:14 -070041static int pci_fire_pbm_iommu_init(struct pci_pbm_info *pbm)
David S. Miller861fe902007-05-02 17:31:36 -070042{
43 struct iommu *iommu = pbm->iommu;
44 u32 vdma[2], dma_mask;
45 u64 control;
David S. Millerad7ad572007-07-27 22:39:14 -070046 int tsbsize, err;
David S. Miller861fe902007-05-02 17:31:36 -070047
48 /* No virtual-dma property on these guys, use largest size. */
49 vdma[0] = 0xc0000000; /* base */
50 vdma[1] = 0x40000000; /* size */
51 dma_mask = 0xffffffff;
52 tsbsize = 128;
53
54 /* Register addresses. */
55 iommu->iommu_control = pbm->pbm_regs + FIRE_IOMMU_CONTROL;
56 iommu->iommu_tsbbase = pbm->pbm_regs + FIRE_IOMMU_TSBBASE;
57 iommu->iommu_flush = pbm->pbm_regs + FIRE_IOMMU_FLUSH;
58 iommu->iommu_flushinv = pbm->pbm_regs + FIRE_IOMMU_FLUSHINV;
59
60 /* We use the main control/status register of FIRE as the write
61 * completion register.
62 */
63 iommu->write_complete_reg = pbm->controller_regs + 0x410000UL;
64
65 /*
66 * Invalidate TLB Entries.
67 */
68 fire_write(iommu->iommu_flushinv, ~(u64)0);
69
David S. Millerc1b1a5f2008-03-19 04:52:48 -070070 err = iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask,
71 pbm->numa_node);
David S. Millerad7ad572007-07-27 22:39:14 -070072 if (err)
73 return err;
David S. Miller861fe902007-05-02 17:31:36 -070074
75 fire_write(iommu->iommu_tsbbase, __pa(iommu->page_table) | 0x7UL);
76
77 control = fire_read(iommu->iommu_control);
78 control |= (0x00000400 /* TSB cache snoop enable */ |
79 0x00000300 /* Cache mode */ |
80 0x00000002 /* Bypass enable */ |
81 0x00000001 /* Translation enable */);
82 fire_write(iommu->iommu_control, control);
David S. Millerad7ad572007-07-27 22:39:14 -070083
84 return 0;
David S. Miller861fe902007-05-02 17:31:36 -070085}
86
David S. Miller9bb3c222007-08-30 22:33:25 -070087#ifdef CONFIG_PCI_MSI
88struct pci_msiq_entry {
89 u64 word0;
90#define MSIQ_WORD0_RESV 0x8000000000000000UL
91#define MSIQ_WORD0_FMT_TYPE 0x7f00000000000000UL
92#define MSIQ_WORD0_FMT_TYPE_SHIFT 56
93#define MSIQ_WORD0_LEN 0x00ffc00000000000UL
94#define MSIQ_WORD0_LEN_SHIFT 46
95#define MSIQ_WORD0_ADDR0 0x00003fff00000000UL
96#define MSIQ_WORD0_ADDR0_SHIFT 32
97#define MSIQ_WORD0_RID 0x00000000ffff0000UL
98#define MSIQ_WORD0_RID_SHIFT 16
99#define MSIQ_WORD0_DATA0 0x000000000000ffffUL
100#define MSIQ_WORD0_DATA0_SHIFT 0
101
102#define MSIQ_TYPE_MSG 0x6
103#define MSIQ_TYPE_MSI32 0xb
104#define MSIQ_TYPE_MSI64 0xf
105
106 u64 word1;
107#define MSIQ_WORD1_ADDR1 0xffffffffffff0000UL
108#define MSIQ_WORD1_ADDR1_SHIFT 16
109#define MSIQ_WORD1_DATA1 0x000000000000ffffUL
110#define MSIQ_WORD1_DATA1_SHIFT 0
111
112 u64 resv[6];
113};
114
115/* All MSI registers are offset from pbm->pbm_regs */
116#define EVENT_QUEUE_BASE_ADDR_REG 0x010000UL
117#define EVENT_QUEUE_BASE_ADDR_ALL_ONES 0xfffc000000000000UL
118
119#define EVENT_QUEUE_CONTROL_SET(EQ) (0x011000UL + (EQ) * 0x8UL)
120#define EVENT_QUEUE_CONTROL_SET_OFLOW 0x0200000000000000UL
121#define EVENT_QUEUE_CONTROL_SET_EN 0x0000100000000000UL
122
123#define EVENT_QUEUE_CONTROL_CLEAR(EQ) (0x011200UL + (EQ) * 0x8UL)
124#define EVENT_QUEUE_CONTROL_CLEAR_OF 0x0200000000000000UL
125#define EVENT_QUEUE_CONTROL_CLEAR_E2I 0x0000800000000000UL
126#define EVENT_QUEUE_CONTROL_CLEAR_DIS 0x0000100000000000UL
127
128#define EVENT_QUEUE_STATE(EQ) (0x011400UL + (EQ) * 0x8UL)
129#define EVENT_QUEUE_STATE_MASK 0x0000000000000007UL
130#define EVENT_QUEUE_STATE_IDLE 0x0000000000000001UL
131#define EVENT_QUEUE_STATE_ACTIVE 0x0000000000000002UL
132#define EVENT_QUEUE_STATE_ERROR 0x0000000000000004UL
133
134#define EVENT_QUEUE_TAIL(EQ) (0x011600UL + (EQ) * 0x8UL)
135#define EVENT_QUEUE_TAIL_OFLOW 0x0200000000000000UL
136#define EVENT_QUEUE_TAIL_VAL 0x000000000000007fUL
137
138#define EVENT_QUEUE_HEAD(EQ) (0x011800UL + (EQ) * 0x8UL)
139#define EVENT_QUEUE_HEAD_VAL 0x000000000000007fUL
140
141#define MSI_MAP(MSI) (0x020000UL + (MSI) * 0x8UL)
142#define MSI_MAP_VALID 0x8000000000000000UL
143#define MSI_MAP_EQWR_N 0x4000000000000000UL
144#define MSI_MAP_EQNUM 0x000000000000003fUL
145
146#define MSI_CLEAR(MSI) (0x028000UL + (MSI) * 0x8UL)
147#define MSI_CLEAR_EQWR_N 0x4000000000000000UL
148
149#define IMONDO_DATA0 0x02C000UL
150#define IMONDO_DATA0_DATA 0xffffffffffffffc0UL
151
152#define IMONDO_DATA1 0x02C008UL
153#define IMONDO_DATA1_DATA 0xffffffffffffffffUL
154
155#define MSI_32BIT_ADDR 0x034000UL
156#define MSI_32BIT_ADDR_VAL 0x00000000ffff0000UL
157
158#define MSI_64BIT_ADDR 0x034008UL
159#define MSI_64BIT_ADDR_VAL 0xffffffffffff0000UL
160
David S. Miller759f89e2007-10-11 03:16:13 -0700161static int pci_fire_get_head(struct pci_pbm_info *pbm, unsigned long msiqid,
162 unsigned long *head)
David S. Miller9bb3c222007-08-30 22:33:25 -0700163{
David S. Miller759f89e2007-10-11 03:16:13 -0700164 *head = fire_read(pbm->pbm_regs + EVENT_QUEUE_HEAD(msiqid));
165 return 0;
David S. Miller9bb3c222007-08-30 22:33:25 -0700166}
167
David S. Miller759f89e2007-10-11 03:16:13 -0700168static int pci_fire_dequeue_msi(struct pci_pbm_info *pbm, unsigned long msiqid,
169 unsigned long *head, unsigned long *msi)
David S. Miller9bb3c222007-08-30 22:33:25 -0700170{
David S. Miller759f89e2007-10-11 03:16:13 -0700171 unsigned long type_fmt, type, msi_num;
172 struct pci_msiq_entry *base, *ep;
David S. Miller9bb3c222007-08-30 22:33:25 -0700173
David S. Miller759f89e2007-10-11 03:16:13 -0700174 base = (pbm->msi_queues + ((msiqid - pbm->msiq_first) * 8192));
175 ep = &base[*head];
David S. Miller9bb3c222007-08-30 22:33:25 -0700176
David S. Miller759f89e2007-10-11 03:16:13 -0700177 if ((ep->word0 & MSIQ_WORD0_FMT_TYPE) == 0)
178 return 0;
179
180 type_fmt = ((ep->word0 & MSIQ_WORD0_FMT_TYPE) >>
181 MSIQ_WORD0_FMT_TYPE_SHIFT);
182 type = (type_fmt >> 3);
183 if (unlikely(type != MSIQ_TYPE_MSI32 &&
184 type != MSIQ_TYPE_MSI64))
185 return -EINVAL;
186
187 *msi = msi_num = ((ep->word0 & MSIQ_WORD0_DATA0) >>
188 MSIQ_WORD0_DATA0_SHIFT);
189
190 fire_write(pbm->pbm_regs + MSI_CLEAR(msi_num),
191 MSI_CLEAR_EQWR_N);
192
193 /* Clear the entry. */
194 ep->word0 &= ~MSIQ_WORD0_FMT_TYPE;
195
196 /* Go to next entry in ring. */
197 (*head)++;
198 if (*head >= pbm->msiq_ent_count)
199 *head = 0;
200
201 return 1;
202}
203
204static int pci_fire_set_head(struct pci_pbm_info *pbm, unsigned long msiqid,
205 unsigned long head)
206{
207 fire_write(pbm->pbm_regs + EVENT_QUEUE_HEAD(msiqid), head);
208 return 0;
209}
210
211static int pci_fire_msi_setup(struct pci_pbm_info *pbm, unsigned long msiqid,
212 unsigned long msi, int is_msi64)
213{
214 u64 val;
215
216 val = fire_read(pbm->pbm_regs + MSI_MAP(msi));
217 val &= ~(MSI_MAP_EQNUM);
218 val |= msiqid;
219 fire_write(pbm->pbm_regs + MSI_MAP(msi), val);
220
221 fire_write(pbm->pbm_regs + MSI_CLEAR(msi),
222 MSI_CLEAR_EQWR_N);
223
224 val = fire_read(pbm->pbm_regs + MSI_MAP(msi));
225 val |= MSI_MAP_VALID;
226 fire_write(pbm->pbm_regs + MSI_MAP(msi), val);
David S. Miller9bb3c222007-08-30 22:33:25 -0700227
228 return 0;
229}
230
David S. Miller759f89e2007-10-11 03:16:13 -0700231static int pci_fire_msi_teardown(struct pci_pbm_info *pbm, unsigned long msi)
David S. Miller9bb3c222007-08-30 22:33:25 -0700232{
David S. Miller759f89e2007-10-11 03:16:13 -0700233 unsigned long msiqid;
234 u64 val;
235
236 val = fire_read(pbm->pbm_regs + MSI_MAP(msi));
237 msiqid = (val & MSI_MAP_EQNUM);
238
239 val &= ~MSI_MAP_VALID;
240
241 fire_write(pbm->pbm_regs + MSI_MAP(msi), val);
242
243 return 0;
David S. Miller9bb3c222007-08-30 22:33:25 -0700244}
245
David S. Miller759f89e2007-10-11 03:16:13 -0700246static int pci_fire_msiq_alloc(struct pci_pbm_info *pbm)
David S. Miller9bb3c222007-08-30 22:33:25 -0700247{
248 unsigned long pages, order, i;
249
250 order = get_order(512 * 1024);
251 pages = __get_free_pages(GFP_KERNEL | __GFP_COMP, order);
252 if (pages == 0UL) {
253 printk(KERN_ERR "MSI: Cannot allocate MSI queues (o=%lu).\n",
254 order);
255 return -ENOMEM;
256 }
257 memset((char *)pages, 0, PAGE_SIZE << order);
258 pbm->msi_queues = (void *) pages;
259
260 fire_write(pbm->pbm_regs + EVENT_QUEUE_BASE_ADDR_REG,
261 (EVENT_QUEUE_BASE_ADDR_ALL_ONES |
262 __pa(pbm->msi_queues)));
263
264 fire_write(pbm->pbm_regs + IMONDO_DATA0,
265 pbm->portid << 6);
266 fire_write(pbm->pbm_regs + IMONDO_DATA1, 0);
267
268 fire_write(pbm->pbm_regs + MSI_32BIT_ADDR,
269 pbm->msi32_start);
270 fire_write(pbm->pbm_regs + MSI_64BIT_ADDR,
271 pbm->msi64_start);
272
273 for (i = 0; i < pbm->msiq_num; i++) {
274 fire_write(pbm->pbm_regs + EVENT_QUEUE_HEAD(i), 0);
275 fire_write(pbm->pbm_regs + EVENT_QUEUE_TAIL(i), 0);
276 }
277
278 return 0;
279}
280
David S. Miller759f89e2007-10-11 03:16:13 -0700281static void pci_fire_msiq_free(struct pci_pbm_info *pbm)
David S. Miller9bb3c222007-08-30 22:33:25 -0700282{
David S. Miller759f89e2007-10-11 03:16:13 -0700283 unsigned long pages, order;
David S. Miller9bb3c222007-08-30 22:33:25 -0700284
David S. Miller759f89e2007-10-11 03:16:13 -0700285 order = get_order(512 * 1024);
286 pages = (unsigned long) pbm->msi_queues;
David S. Miller9bb3c222007-08-30 22:33:25 -0700287
David S. Miller759f89e2007-10-11 03:16:13 -0700288 free_pages(pages, order);
289
290 pbm->msi_queues = NULL;
David S. Miller9bb3c222007-08-30 22:33:25 -0700291}
292
David S. Miller759f89e2007-10-11 03:16:13 -0700293static int pci_fire_msiq_build_irq(struct pci_pbm_info *pbm,
294 unsigned long msiqid,
295 unsigned long devino)
David S. Miller9bb3c222007-08-30 22:33:25 -0700296{
David S. Miller759f89e2007-10-11 03:16:13 -0700297 unsigned long cregs = (unsigned long) pbm->pbm_regs;
298 unsigned long imap_reg, iclr_reg, int_ctrlr;
299 unsigned int virt_irq;
300 int fixup;
David S. Miller9bb3c222007-08-30 22:33:25 -0700301 u64 val;
302
David S. Miller759f89e2007-10-11 03:16:13 -0700303 imap_reg = cregs + (0x001000UL + (devino * 0x08UL));
304 iclr_reg = cregs + (0x001400UL + (devino * 0x08UL));
David S. Miller9bb3c222007-08-30 22:33:25 -0700305
David S. Miller759f89e2007-10-11 03:16:13 -0700306 /* XXX iterate amongst the 4 IRQ controllers XXX */
307 int_ctrlr = (1UL << 6);
David S. Miller9bb3c222007-08-30 22:33:25 -0700308
David S. Miller759f89e2007-10-11 03:16:13 -0700309 val = fire_read(imap_reg);
310 val |= (1UL << 63) | int_ctrlr;
311 fire_write(imap_reg, val);
David S. Miller9bb3c222007-08-30 22:33:25 -0700312
David S. Miller759f89e2007-10-11 03:16:13 -0700313 fixup = ((pbm->portid << 6) | devino) - int_ctrlr;
David S. Miller9bb3c222007-08-30 22:33:25 -0700314
David S. Miller759f89e2007-10-11 03:16:13 -0700315 virt_irq = build_irq(fixup, iclr_reg, imap_reg);
316 if (!virt_irq)
317 return -ENOMEM;
David S. Miller9bb3c222007-08-30 22:33:25 -0700318
319 fire_write(pbm->pbm_regs +
320 EVENT_QUEUE_CONTROL_SET(msiqid),
321 EVENT_QUEUE_CONTROL_SET_EN);
322
David S. Miller759f89e2007-10-11 03:16:13 -0700323 return virt_irq;
David S. Miller9bb3c222007-08-30 22:33:25 -0700324}
325
David S. Miller759f89e2007-10-11 03:16:13 -0700326static const struct sparc64_msiq_ops pci_fire_msiq_ops = {
327 .get_head = pci_fire_get_head,
328 .dequeue_msi = pci_fire_dequeue_msi,
329 .set_head = pci_fire_set_head,
330 .msi_setup = pci_fire_msi_setup,
331 .msi_teardown = pci_fire_msi_teardown,
332 .msiq_alloc = pci_fire_msiq_alloc,
333 .msiq_free = pci_fire_msiq_free,
334 .msiq_build_irq = pci_fire_msiq_build_irq,
335};
David S. Miller9bb3c222007-08-30 22:33:25 -0700336
337static void pci_fire_msi_init(struct pci_pbm_info *pbm)
338{
David S. Miller759f89e2007-10-11 03:16:13 -0700339 sparc64_pbm_msi_init(pbm, &pci_fire_msiq_ops);
David S. Miller9bb3c222007-08-30 22:33:25 -0700340}
341#else /* CONFIG_PCI_MSI */
342static void pci_fire_msi_init(struct pci_pbm_info *pbm)
343{
344}
345#endif /* !(CONFIG_PCI_MSI) */
346
David S. Miller861fe902007-05-02 17:31:36 -0700347/* Based at pbm->controller_regs */
348#define FIRE_PARITY_CONTROL 0x470010UL
349#define FIRE_PARITY_ENAB 0x8000000000000000UL
350#define FIRE_FATAL_RESET_CTL 0x471028UL
351#define FIRE_FATAL_RESET_SPARE 0x0000000004000000UL
352#define FIRE_FATAL_RESET_MB 0x0000000002000000UL
353#define FIRE_FATAL_RESET_CPE 0x0000000000008000UL
354#define FIRE_FATAL_RESET_APE 0x0000000000004000UL
355#define FIRE_FATAL_RESET_PIO 0x0000000000000040UL
356#define FIRE_FATAL_RESET_JW 0x0000000000000004UL
357#define FIRE_FATAL_RESET_JI 0x0000000000000002UL
358#define FIRE_FATAL_RESET_JR 0x0000000000000001UL
359#define FIRE_CORE_INTR_ENABLE 0x471800UL
360
361/* Based at pbm->pbm_regs */
362#define FIRE_TLU_CTRL 0x80000UL
363#define FIRE_TLU_CTRL_TIM 0x00000000da000000UL
364#define FIRE_TLU_CTRL_QDET 0x0000000000000100UL
365#define FIRE_TLU_CTRL_CFG 0x0000000000000001UL
366#define FIRE_TLU_DEV_CTRL 0x90008UL
367#define FIRE_TLU_LINK_CTRL 0x90020UL
368#define FIRE_TLU_LINK_CTRL_CLK 0x0000000000000040UL
369#define FIRE_LPU_RESET 0xe2008UL
370#define FIRE_LPU_LLCFG 0xe2200UL
371#define FIRE_LPU_LLCFG_VC0 0x0000000000000100UL
372#define FIRE_LPU_FCTRL_UCTRL 0xe2240UL
373#define FIRE_LPU_FCTRL_UCTRL_N 0x0000000000000002UL
374#define FIRE_LPU_FCTRL_UCTRL_P 0x0000000000000001UL
375#define FIRE_LPU_TXL_FIFOP 0xe2430UL
376#define FIRE_LPU_LTSSM_CFG2 0xe2788UL
377#define FIRE_LPU_LTSSM_CFG3 0xe2790UL
378#define FIRE_LPU_LTSSM_CFG4 0xe2798UL
379#define FIRE_LPU_LTSSM_CFG5 0xe27a0UL
380#define FIRE_DMC_IENAB 0x31800UL
381#define FIRE_DMC_DBG_SEL_A 0x53000UL
382#define FIRE_DMC_DBG_SEL_B 0x53008UL
383#define FIRE_PEC_IENAB 0x51800UL
384
385static void pci_fire_hw_init(struct pci_pbm_info *pbm)
386{
387 u64 val;
388
389 fire_write(pbm->controller_regs + FIRE_PARITY_CONTROL,
390 FIRE_PARITY_ENAB);
391
392 fire_write(pbm->controller_regs + FIRE_FATAL_RESET_CTL,
393 (FIRE_FATAL_RESET_SPARE |
394 FIRE_FATAL_RESET_MB |
395 FIRE_FATAL_RESET_CPE |
396 FIRE_FATAL_RESET_APE |
397 FIRE_FATAL_RESET_PIO |
398 FIRE_FATAL_RESET_JW |
399 FIRE_FATAL_RESET_JI |
400 FIRE_FATAL_RESET_JR));
401
402 fire_write(pbm->controller_regs + FIRE_CORE_INTR_ENABLE, ~(u64)0);
403
404 val = fire_read(pbm->pbm_regs + FIRE_TLU_CTRL);
405 val |= (FIRE_TLU_CTRL_TIM |
406 FIRE_TLU_CTRL_QDET |
407 FIRE_TLU_CTRL_CFG);
408 fire_write(pbm->pbm_regs + FIRE_TLU_CTRL, val);
409 fire_write(pbm->pbm_regs + FIRE_TLU_DEV_CTRL, 0);
410 fire_write(pbm->pbm_regs + FIRE_TLU_LINK_CTRL,
411 FIRE_TLU_LINK_CTRL_CLK);
412
413 fire_write(pbm->pbm_regs + FIRE_LPU_RESET, 0);
414 fire_write(pbm->pbm_regs + FIRE_LPU_LLCFG,
415 FIRE_LPU_LLCFG_VC0);
416 fire_write(pbm->pbm_regs + FIRE_LPU_FCTRL_UCTRL,
417 (FIRE_LPU_FCTRL_UCTRL_N |
418 FIRE_LPU_FCTRL_UCTRL_P));
419 fire_write(pbm->pbm_regs + FIRE_LPU_TXL_FIFOP,
420 ((0xffff << 16) | (0x0000 << 0)));
421 fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG2, 3000000);
422 fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG3, 500000);
423 fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG4,
424 (2 << 16) | (140 << 8));
425 fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG5, 0);
426
427 fire_write(pbm->pbm_regs + FIRE_DMC_IENAB, ~(u64)0);
428 fire_write(pbm->pbm_regs + FIRE_DMC_DBG_SEL_A, 0);
429 fire_write(pbm->pbm_regs + FIRE_DMC_DBG_SEL_B, 0);
430
431 fire_write(pbm->pbm_regs + FIRE_PEC_IENAB, ~(u64)0);
432}
433
David S. Millerd3ae4b52008-09-09 23:54:02 -0700434static int __init pci_fire_pbm_init(struct pci_pbm_info *pbm,
David S. Millere822358a2008-09-01 18:32:22 -0700435 struct of_device *op, u32 portid)
David S. Miller861fe902007-05-02 17:31:36 -0700436{
437 const struct linux_prom64_registers *regs;
David S. Millere822358a2008-09-01 18:32:22 -0700438 struct device_node *dp = op->node;
David S. Miller9bb3c222007-08-30 22:33:25 -0700439 int err;
David S. Miller861fe902007-05-02 17:31:36 -0700440
David S. Millerc1b1a5f2008-03-19 04:52:48 -0700441 pbm->numa_node = -1;
442
David S. Millerca3dd882007-05-09 02:35:27 -0700443 pbm->pci_ops = &sun4u_pci_ops;
444 pbm->config_space_reg_bits = 12;
David S. Miller34768bc2007-05-07 23:06:27 -0700445
David S. Miller6c108f12007-05-07 23:49:01 -0700446 pbm->index = pci_num_pbms++;
447
David S. Miller861fe902007-05-02 17:31:36 -0700448 pbm->portid = portid;
David S. Miller22fecba2008-09-10 00:19:28 -0700449 pbm->op = op;
David S. Miller861fe902007-05-02 17:31:36 -0700450 pbm->name = dp->full_name;
451
452 regs = of_get_property(dp, "reg", NULL);
453 pbm->pbm_regs = regs[0].phys_addr;
454 pbm->controller_regs = regs[1].phys_addr - 0x410000UL;
455
456 printk("%s: SUN4U PCIE Bus Module\n", pbm->name);
457
458 pci_determine_mem_io_space(pbm);
459
David S. Millercfa06522007-05-07 21:51:41 -0700460 pci_get_pbm_props(pbm);
David S. Miller861fe902007-05-02 17:31:36 -0700461
462 pci_fire_hw_init(pbm);
David S. Millerad7ad572007-07-27 22:39:14 -0700463
David S. Miller9bb3c222007-08-30 22:33:25 -0700464 err = pci_fire_pbm_iommu_init(pbm);
465 if (err)
466 return err;
467
468 pci_fire_msi_init(pbm);
469
David S. Millere822358a2008-09-01 18:32:22 -0700470 pbm->pci_bus = pci_scan_one_pbm(pbm, &op->dev);
471
472 /* XXX register error interrupt handlers XXX */
David S. Millerc8049962008-08-30 03:12:38 -0700473
David S. Millerd3ae4b52008-09-09 23:54:02 -0700474 pbm->next = pci_pbm_root;
475 pci_pbm_root = pbm;
David S. Miller861fe902007-05-02 17:31:36 -0700476
David S. Miller861fe902007-05-02 17:31:36 -0700477 return 0;
478}
479
David S. Millerc8049962008-08-30 03:12:38 -0700480static int __devinit fire_probe(struct of_device *op,
481 const struct of_device_id *match)
David S. Miller861fe902007-05-02 17:31:36 -0700482{
David S. Millerc8049962008-08-30 03:12:38 -0700483 struct device_node *dp = op->node;
David S. Miller34768bc2007-05-07 23:06:27 -0700484 struct pci_pbm_info *pbm;
David S. Millerc8049962008-08-30 03:12:38 -0700485 struct iommu *iommu;
486 u32 portid;
487 int err;
David S. Miller861fe902007-05-02 17:31:36 -0700488
David S. Millerc8049962008-08-30 03:12:38 -0700489 portid = of_getintprop_default(dp, "portid", 0xff);
David S. Miller861fe902007-05-02 17:31:36 -0700490
David S. Millerc8049962008-08-30 03:12:38 -0700491 err = -ENOMEM;
David S. Millerd3ae4b52008-09-09 23:54:02 -0700492 pbm = kzalloc(sizeof(*pbm), GFP_KERNEL);
493 if (!pbm) {
494 printk(KERN_ERR PFX "Cannot allocate pci_pbminfo.\n");
David S. Millerd7472c32008-08-31 01:33:52 -0700495 goto out_err;
David S. Millerc8049962008-08-30 03:12:38 -0700496 }
David S. Miller861fe902007-05-02 17:31:36 -0700497
David S. Millerd3ae4b52008-09-09 23:54:02 -0700498 iommu = kzalloc(sizeof(struct iommu), GFP_KERNEL);
David S. Millerc8049962008-08-30 03:12:38 -0700499 if (!iommu) {
David S. Millerd3ae4b52008-09-09 23:54:02 -0700500 printk(KERN_ERR PFX "Cannot allocate PBM iommu.\n");
David S. Millerd7472c32008-08-31 01:33:52 -0700501 goto out_free_controller;
David S. Millerc8049962008-08-30 03:12:38 -0700502 }
David S. Miller861fe902007-05-02 17:31:36 -0700503
David S. Millerd3ae4b52008-09-09 23:54:02 -0700504 pbm->iommu = iommu;
David S. Miller861fe902007-05-02 17:31:36 -0700505
David S. Millerd3ae4b52008-09-09 23:54:02 -0700506 err = pci_fire_pbm_init(pbm, op, portid);
507 if (err)
508 goto out_free_iommu;
David S. Miller861fe902007-05-02 17:31:36 -0700509
David S. Millerd3ae4b52008-09-09 23:54:02 -0700510 dev_set_drvdata(&op->dev, pbm);
David S. Miller861fe902007-05-02 17:31:36 -0700511
David S. Millerd3ae4b52008-09-09 23:54:02 -0700512 return 0;
David S. Millerad7ad572007-07-27 22:39:14 -0700513
David S. Millerd3ae4b52008-09-09 23:54:02 -0700514out_free_iommu:
515 kfree(pbm->iommu);
David S. Millerd7472c32008-08-31 01:33:52 -0700516
517out_free_controller:
David S. Millerd3ae4b52008-09-09 23:54:02 -0700518 kfree(pbm);
David S. Millerd7472c32008-08-31 01:33:52 -0700519
520out_err:
David S. Millerc8049962008-08-30 03:12:38 -0700521 return err;
David S. Miller861fe902007-05-02 17:31:36 -0700522}
David S. Millerc8049962008-08-30 03:12:38 -0700523
David S. Millerfd098312008-08-31 01:23:17 -0700524static struct of_device_id __initdata fire_match[] = {
David S. Millerc8049962008-08-30 03:12:38 -0700525 {
526 .name = "pci",
527 .compatible = "pciex108e,80f0",
528 },
529 {},
530};
531
532static struct of_platform_driver fire_driver = {
533 .name = DRIVER_NAME,
534 .match_table = fire_match,
535 .probe = fire_probe,
536};
537
538static int __init fire_init(void)
539{
540 return of_register_driver(&fire_driver, &of_bus_type);
541}
542
543subsys_initcall(fire_init);