blob: 477928aad5385137dcc204c7740deb22afe5f97b [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
Sam Ravnborga1f35ba2008-01-21 17:22:46 -080036static void __init pci_fire_scan_bus(struct pci_pbm_info *pbm)
David S. Miller861fe902007-05-02 17:31:36 -070037{
38 pbm->pci_bus = pci_scan_one_pbm(pbm);
David S. Miller861fe902007-05-02 17:31:36 -070039
40 /* XXX register error interrupt handlers XXX */
41}
42
43#define FIRE_IOMMU_CONTROL 0x40000UL
44#define FIRE_IOMMU_TSBBASE 0x40008UL
45#define FIRE_IOMMU_FLUSH 0x40100UL
David S. Miller95d71e62007-05-11 21:02:09 -070046#define FIRE_IOMMU_FLUSHINV 0x40108UL
David S. Miller861fe902007-05-02 17:31:36 -070047
David S. Millerad7ad572007-07-27 22:39:14 -070048static int pci_fire_pbm_iommu_init(struct pci_pbm_info *pbm)
David S. Miller861fe902007-05-02 17:31:36 -070049{
50 struct iommu *iommu = pbm->iommu;
51 u32 vdma[2], dma_mask;
52 u64 control;
David S. Millerad7ad572007-07-27 22:39:14 -070053 int tsbsize, err;
David S. Miller861fe902007-05-02 17:31:36 -070054
55 /* No virtual-dma property on these guys, use largest size. */
56 vdma[0] = 0xc0000000; /* base */
57 vdma[1] = 0x40000000; /* size */
58 dma_mask = 0xffffffff;
59 tsbsize = 128;
60
61 /* Register addresses. */
62 iommu->iommu_control = pbm->pbm_regs + FIRE_IOMMU_CONTROL;
63 iommu->iommu_tsbbase = pbm->pbm_regs + FIRE_IOMMU_TSBBASE;
64 iommu->iommu_flush = pbm->pbm_regs + FIRE_IOMMU_FLUSH;
65 iommu->iommu_flushinv = pbm->pbm_regs + FIRE_IOMMU_FLUSHINV;
66
67 /* We use the main control/status register of FIRE as the write
68 * completion register.
69 */
70 iommu->write_complete_reg = pbm->controller_regs + 0x410000UL;
71
72 /*
73 * Invalidate TLB Entries.
74 */
75 fire_write(iommu->iommu_flushinv, ~(u64)0);
76
David S. Millerc1b1a5f2008-03-19 04:52:48 -070077 err = iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask,
78 pbm->numa_node);
David S. Millerad7ad572007-07-27 22:39:14 -070079 if (err)
80 return err;
David S. Miller861fe902007-05-02 17:31:36 -070081
82 fire_write(iommu->iommu_tsbbase, __pa(iommu->page_table) | 0x7UL);
83
84 control = fire_read(iommu->iommu_control);
85 control |= (0x00000400 /* TSB cache snoop enable */ |
86 0x00000300 /* Cache mode */ |
87 0x00000002 /* Bypass enable */ |
88 0x00000001 /* Translation enable */);
89 fire_write(iommu->iommu_control, control);
David S. Millerad7ad572007-07-27 22:39:14 -070090
91 return 0;
David S. Miller861fe902007-05-02 17:31:36 -070092}
93
David S. Miller9bb3c222007-08-30 22:33:25 -070094#ifdef CONFIG_PCI_MSI
95struct pci_msiq_entry {
96 u64 word0;
97#define MSIQ_WORD0_RESV 0x8000000000000000UL
98#define MSIQ_WORD0_FMT_TYPE 0x7f00000000000000UL
99#define MSIQ_WORD0_FMT_TYPE_SHIFT 56
100#define MSIQ_WORD0_LEN 0x00ffc00000000000UL
101#define MSIQ_WORD0_LEN_SHIFT 46
102#define MSIQ_WORD0_ADDR0 0x00003fff00000000UL
103#define MSIQ_WORD0_ADDR0_SHIFT 32
104#define MSIQ_WORD0_RID 0x00000000ffff0000UL
105#define MSIQ_WORD0_RID_SHIFT 16
106#define MSIQ_WORD0_DATA0 0x000000000000ffffUL
107#define MSIQ_WORD0_DATA0_SHIFT 0
108
109#define MSIQ_TYPE_MSG 0x6
110#define MSIQ_TYPE_MSI32 0xb
111#define MSIQ_TYPE_MSI64 0xf
112
113 u64 word1;
114#define MSIQ_WORD1_ADDR1 0xffffffffffff0000UL
115#define MSIQ_WORD1_ADDR1_SHIFT 16
116#define MSIQ_WORD1_DATA1 0x000000000000ffffUL
117#define MSIQ_WORD1_DATA1_SHIFT 0
118
119 u64 resv[6];
120};
121
122/* All MSI registers are offset from pbm->pbm_regs */
123#define EVENT_QUEUE_BASE_ADDR_REG 0x010000UL
124#define EVENT_QUEUE_BASE_ADDR_ALL_ONES 0xfffc000000000000UL
125
126#define EVENT_QUEUE_CONTROL_SET(EQ) (0x011000UL + (EQ) * 0x8UL)
127#define EVENT_QUEUE_CONTROL_SET_OFLOW 0x0200000000000000UL
128#define EVENT_QUEUE_CONTROL_SET_EN 0x0000100000000000UL
129
130#define EVENT_QUEUE_CONTROL_CLEAR(EQ) (0x011200UL + (EQ) * 0x8UL)
131#define EVENT_QUEUE_CONTROL_CLEAR_OF 0x0200000000000000UL
132#define EVENT_QUEUE_CONTROL_CLEAR_E2I 0x0000800000000000UL
133#define EVENT_QUEUE_CONTROL_CLEAR_DIS 0x0000100000000000UL
134
135#define EVENT_QUEUE_STATE(EQ) (0x011400UL + (EQ) * 0x8UL)
136#define EVENT_QUEUE_STATE_MASK 0x0000000000000007UL
137#define EVENT_QUEUE_STATE_IDLE 0x0000000000000001UL
138#define EVENT_QUEUE_STATE_ACTIVE 0x0000000000000002UL
139#define EVENT_QUEUE_STATE_ERROR 0x0000000000000004UL
140
141#define EVENT_QUEUE_TAIL(EQ) (0x011600UL + (EQ) * 0x8UL)
142#define EVENT_QUEUE_TAIL_OFLOW 0x0200000000000000UL
143#define EVENT_QUEUE_TAIL_VAL 0x000000000000007fUL
144
145#define EVENT_QUEUE_HEAD(EQ) (0x011800UL + (EQ) * 0x8UL)
146#define EVENT_QUEUE_HEAD_VAL 0x000000000000007fUL
147
148#define MSI_MAP(MSI) (0x020000UL + (MSI) * 0x8UL)
149#define MSI_MAP_VALID 0x8000000000000000UL
150#define MSI_MAP_EQWR_N 0x4000000000000000UL
151#define MSI_MAP_EQNUM 0x000000000000003fUL
152
153#define MSI_CLEAR(MSI) (0x028000UL + (MSI) * 0x8UL)
154#define MSI_CLEAR_EQWR_N 0x4000000000000000UL
155
156#define IMONDO_DATA0 0x02C000UL
157#define IMONDO_DATA0_DATA 0xffffffffffffffc0UL
158
159#define IMONDO_DATA1 0x02C008UL
160#define IMONDO_DATA1_DATA 0xffffffffffffffffUL
161
162#define MSI_32BIT_ADDR 0x034000UL
163#define MSI_32BIT_ADDR_VAL 0x00000000ffff0000UL
164
165#define MSI_64BIT_ADDR 0x034008UL
166#define MSI_64BIT_ADDR_VAL 0xffffffffffff0000UL
167
David S. Miller759f89e2007-10-11 03:16:13 -0700168static int pci_fire_get_head(struct pci_pbm_info *pbm, unsigned long msiqid,
169 unsigned long *head)
David S. Miller9bb3c222007-08-30 22:33:25 -0700170{
David S. Miller759f89e2007-10-11 03:16:13 -0700171 *head = fire_read(pbm->pbm_regs + EVENT_QUEUE_HEAD(msiqid));
172 return 0;
David S. Miller9bb3c222007-08-30 22:33:25 -0700173}
174
David S. Miller759f89e2007-10-11 03:16:13 -0700175static int pci_fire_dequeue_msi(struct pci_pbm_info *pbm, unsigned long msiqid,
176 unsigned long *head, unsigned long *msi)
David S. Miller9bb3c222007-08-30 22:33:25 -0700177{
David S. Miller759f89e2007-10-11 03:16:13 -0700178 unsigned long type_fmt, type, msi_num;
179 struct pci_msiq_entry *base, *ep;
David S. Miller9bb3c222007-08-30 22:33:25 -0700180
David S. Miller759f89e2007-10-11 03:16:13 -0700181 base = (pbm->msi_queues + ((msiqid - pbm->msiq_first) * 8192));
182 ep = &base[*head];
David S. Miller9bb3c222007-08-30 22:33:25 -0700183
David S. Miller759f89e2007-10-11 03:16:13 -0700184 if ((ep->word0 & MSIQ_WORD0_FMT_TYPE) == 0)
185 return 0;
186
187 type_fmt = ((ep->word0 & MSIQ_WORD0_FMT_TYPE) >>
188 MSIQ_WORD0_FMT_TYPE_SHIFT);
189 type = (type_fmt >> 3);
190 if (unlikely(type != MSIQ_TYPE_MSI32 &&
191 type != MSIQ_TYPE_MSI64))
192 return -EINVAL;
193
194 *msi = msi_num = ((ep->word0 & MSIQ_WORD0_DATA0) >>
195 MSIQ_WORD0_DATA0_SHIFT);
196
197 fire_write(pbm->pbm_regs + MSI_CLEAR(msi_num),
198 MSI_CLEAR_EQWR_N);
199
200 /* Clear the entry. */
201 ep->word0 &= ~MSIQ_WORD0_FMT_TYPE;
202
203 /* Go to next entry in ring. */
204 (*head)++;
205 if (*head >= pbm->msiq_ent_count)
206 *head = 0;
207
208 return 1;
209}
210
211static int pci_fire_set_head(struct pci_pbm_info *pbm, unsigned long msiqid,
212 unsigned long head)
213{
214 fire_write(pbm->pbm_regs + EVENT_QUEUE_HEAD(msiqid), head);
215 return 0;
216}
217
218static int pci_fire_msi_setup(struct pci_pbm_info *pbm, unsigned long msiqid,
219 unsigned long msi, int is_msi64)
220{
221 u64 val;
222
223 val = fire_read(pbm->pbm_regs + MSI_MAP(msi));
224 val &= ~(MSI_MAP_EQNUM);
225 val |= msiqid;
226 fire_write(pbm->pbm_regs + MSI_MAP(msi), val);
227
228 fire_write(pbm->pbm_regs + MSI_CLEAR(msi),
229 MSI_CLEAR_EQWR_N);
230
231 val = fire_read(pbm->pbm_regs + MSI_MAP(msi));
232 val |= MSI_MAP_VALID;
233 fire_write(pbm->pbm_regs + MSI_MAP(msi), val);
David S. Miller9bb3c222007-08-30 22:33:25 -0700234
235 return 0;
236}
237
David S. Miller759f89e2007-10-11 03:16:13 -0700238static int pci_fire_msi_teardown(struct pci_pbm_info *pbm, unsigned long msi)
David S. Miller9bb3c222007-08-30 22:33:25 -0700239{
David S. Miller759f89e2007-10-11 03:16:13 -0700240 unsigned long msiqid;
241 u64 val;
242
243 val = fire_read(pbm->pbm_regs + MSI_MAP(msi));
244 msiqid = (val & MSI_MAP_EQNUM);
245
246 val &= ~MSI_MAP_VALID;
247
248 fire_write(pbm->pbm_regs + MSI_MAP(msi), val);
249
250 return 0;
David S. Miller9bb3c222007-08-30 22:33:25 -0700251}
252
David S. Miller759f89e2007-10-11 03:16:13 -0700253static int pci_fire_msiq_alloc(struct pci_pbm_info *pbm)
David S. Miller9bb3c222007-08-30 22:33:25 -0700254{
255 unsigned long pages, order, i;
256
257 order = get_order(512 * 1024);
258 pages = __get_free_pages(GFP_KERNEL | __GFP_COMP, order);
259 if (pages == 0UL) {
260 printk(KERN_ERR "MSI: Cannot allocate MSI queues (o=%lu).\n",
261 order);
262 return -ENOMEM;
263 }
264 memset((char *)pages, 0, PAGE_SIZE << order);
265 pbm->msi_queues = (void *) pages;
266
267 fire_write(pbm->pbm_regs + EVENT_QUEUE_BASE_ADDR_REG,
268 (EVENT_QUEUE_BASE_ADDR_ALL_ONES |
269 __pa(pbm->msi_queues)));
270
271 fire_write(pbm->pbm_regs + IMONDO_DATA0,
272 pbm->portid << 6);
273 fire_write(pbm->pbm_regs + IMONDO_DATA1, 0);
274
275 fire_write(pbm->pbm_regs + MSI_32BIT_ADDR,
276 pbm->msi32_start);
277 fire_write(pbm->pbm_regs + MSI_64BIT_ADDR,
278 pbm->msi64_start);
279
280 for (i = 0; i < pbm->msiq_num; i++) {
281 fire_write(pbm->pbm_regs + EVENT_QUEUE_HEAD(i), 0);
282 fire_write(pbm->pbm_regs + EVENT_QUEUE_TAIL(i), 0);
283 }
284
285 return 0;
286}
287
David S. Miller759f89e2007-10-11 03:16:13 -0700288static void pci_fire_msiq_free(struct pci_pbm_info *pbm)
David S. Miller9bb3c222007-08-30 22:33:25 -0700289{
David S. Miller759f89e2007-10-11 03:16:13 -0700290 unsigned long pages, order;
David S. Miller9bb3c222007-08-30 22:33:25 -0700291
David S. Miller759f89e2007-10-11 03:16:13 -0700292 order = get_order(512 * 1024);
293 pages = (unsigned long) pbm->msi_queues;
David S. Miller9bb3c222007-08-30 22:33:25 -0700294
David S. Miller759f89e2007-10-11 03:16:13 -0700295 free_pages(pages, order);
296
297 pbm->msi_queues = NULL;
David S. Miller9bb3c222007-08-30 22:33:25 -0700298}
299
David S. Miller759f89e2007-10-11 03:16:13 -0700300static int pci_fire_msiq_build_irq(struct pci_pbm_info *pbm,
301 unsigned long msiqid,
302 unsigned long devino)
David S. Miller9bb3c222007-08-30 22:33:25 -0700303{
David S. Miller759f89e2007-10-11 03:16:13 -0700304 unsigned long cregs = (unsigned long) pbm->pbm_regs;
305 unsigned long imap_reg, iclr_reg, int_ctrlr;
306 unsigned int virt_irq;
307 int fixup;
David S. Miller9bb3c222007-08-30 22:33:25 -0700308 u64 val;
309
David S. Miller759f89e2007-10-11 03:16:13 -0700310 imap_reg = cregs + (0x001000UL + (devino * 0x08UL));
311 iclr_reg = cregs + (0x001400UL + (devino * 0x08UL));
David S. Miller9bb3c222007-08-30 22:33:25 -0700312
David S. Miller759f89e2007-10-11 03:16:13 -0700313 /* XXX iterate amongst the 4 IRQ controllers XXX */
314 int_ctrlr = (1UL << 6);
David S. Miller9bb3c222007-08-30 22:33:25 -0700315
David S. Miller759f89e2007-10-11 03:16:13 -0700316 val = fire_read(imap_reg);
317 val |= (1UL << 63) | int_ctrlr;
318 fire_write(imap_reg, val);
David S. Miller9bb3c222007-08-30 22:33:25 -0700319
David S. Miller759f89e2007-10-11 03:16:13 -0700320 fixup = ((pbm->portid << 6) | devino) - int_ctrlr;
David S. Miller9bb3c222007-08-30 22:33:25 -0700321
David S. Miller759f89e2007-10-11 03:16:13 -0700322 virt_irq = build_irq(fixup, iclr_reg, imap_reg);
323 if (!virt_irq)
324 return -ENOMEM;
David S. Miller9bb3c222007-08-30 22:33:25 -0700325
326 fire_write(pbm->pbm_regs +
327 EVENT_QUEUE_CONTROL_SET(msiqid),
328 EVENT_QUEUE_CONTROL_SET_EN);
329
David S. Miller759f89e2007-10-11 03:16:13 -0700330 return virt_irq;
David S. Miller9bb3c222007-08-30 22:33:25 -0700331}
332
David S. Miller759f89e2007-10-11 03:16:13 -0700333static const struct sparc64_msiq_ops pci_fire_msiq_ops = {
334 .get_head = pci_fire_get_head,
335 .dequeue_msi = pci_fire_dequeue_msi,
336 .set_head = pci_fire_set_head,
337 .msi_setup = pci_fire_msi_setup,
338 .msi_teardown = pci_fire_msi_teardown,
339 .msiq_alloc = pci_fire_msiq_alloc,
340 .msiq_free = pci_fire_msiq_free,
341 .msiq_build_irq = pci_fire_msiq_build_irq,
342};
David S. Miller9bb3c222007-08-30 22:33:25 -0700343
344static void pci_fire_msi_init(struct pci_pbm_info *pbm)
345{
David S. Miller759f89e2007-10-11 03:16:13 -0700346 sparc64_pbm_msi_init(pbm, &pci_fire_msiq_ops);
David S. Miller9bb3c222007-08-30 22:33:25 -0700347}
348#else /* CONFIG_PCI_MSI */
349static void pci_fire_msi_init(struct pci_pbm_info *pbm)
350{
351}
352#endif /* !(CONFIG_PCI_MSI) */
353
David S. Miller861fe902007-05-02 17:31:36 -0700354/* Based at pbm->controller_regs */
355#define FIRE_PARITY_CONTROL 0x470010UL
356#define FIRE_PARITY_ENAB 0x8000000000000000UL
357#define FIRE_FATAL_RESET_CTL 0x471028UL
358#define FIRE_FATAL_RESET_SPARE 0x0000000004000000UL
359#define FIRE_FATAL_RESET_MB 0x0000000002000000UL
360#define FIRE_FATAL_RESET_CPE 0x0000000000008000UL
361#define FIRE_FATAL_RESET_APE 0x0000000000004000UL
362#define FIRE_FATAL_RESET_PIO 0x0000000000000040UL
363#define FIRE_FATAL_RESET_JW 0x0000000000000004UL
364#define FIRE_FATAL_RESET_JI 0x0000000000000002UL
365#define FIRE_FATAL_RESET_JR 0x0000000000000001UL
366#define FIRE_CORE_INTR_ENABLE 0x471800UL
367
368/* Based at pbm->pbm_regs */
369#define FIRE_TLU_CTRL 0x80000UL
370#define FIRE_TLU_CTRL_TIM 0x00000000da000000UL
371#define FIRE_TLU_CTRL_QDET 0x0000000000000100UL
372#define FIRE_TLU_CTRL_CFG 0x0000000000000001UL
373#define FIRE_TLU_DEV_CTRL 0x90008UL
374#define FIRE_TLU_LINK_CTRL 0x90020UL
375#define FIRE_TLU_LINK_CTRL_CLK 0x0000000000000040UL
376#define FIRE_LPU_RESET 0xe2008UL
377#define FIRE_LPU_LLCFG 0xe2200UL
378#define FIRE_LPU_LLCFG_VC0 0x0000000000000100UL
379#define FIRE_LPU_FCTRL_UCTRL 0xe2240UL
380#define FIRE_LPU_FCTRL_UCTRL_N 0x0000000000000002UL
381#define FIRE_LPU_FCTRL_UCTRL_P 0x0000000000000001UL
382#define FIRE_LPU_TXL_FIFOP 0xe2430UL
383#define FIRE_LPU_LTSSM_CFG2 0xe2788UL
384#define FIRE_LPU_LTSSM_CFG3 0xe2790UL
385#define FIRE_LPU_LTSSM_CFG4 0xe2798UL
386#define FIRE_LPU_LTSSM_CFG5 0xe27a0UL
387#define FIRE_DMC_IENAB 0x31800UL
388#define FIRE_DMC_DBG_SEL_A 0x53000UL
389#define FIRE_DMC_DBG_SEL_B 0x53008UL
390#define FIRE_PEC_IENAB 0x51800UL
391
392static void pci_fire_hw_init(struct pci_pbm_info *pbm)
393{
394 u64 val;
395
396 fire_write(pbm->controller_regs + FIRE_PARITY_CONTROL,
397 FIRE_PARITY_ENAB);
398
399 fire_write(pbm->controller_regs + FIRE_FATAL_RESET_CTL,
400 (FIRE_FATAL_RESET_SPARE |
401 FIRE_FATAL_RESET_MB |
402 FIRE_FATAL_RESET_CPE |
403 FIRE_FATAL_RESET_APE |
404 FIRE_FATAL_RESET_PIO |
405 FIRE_FATAL_RESET_JW |
406 FIRE_FATAL_RESET_JI |
407 FIRE_FATAL_RESET_JR));
408
409 fire_write(pbm->controller_regs + FIRE_CORE_INTR_ENABLE, ~(u64)0);
410
411 val = fire_read(pbm->pbm_regs + FIRE_TLU_CTRL);
412 val |= (FIRE_TLU_CTRL_TIM |
413 FIRE_TLU_CTRL_QDET |
414 FIRE_TLU_CTRL_CFG);
415 fire_write(pbm->pbm_regs + FIRE_TLU_CTRL, val);
416 fire_write(pbm->pbm_regs + FIRE_TLU_DEV_CTRL, 0);
417 fire_write(pbm->pbm_regs + FIRE_TLU_LINK_CTRL,
418 FIRE_TLU_LINK_CTRL_CLK);
419
420 fire_write(pbm->pbm_regs + FIRE_LPU_RESET, 0);
421 fire_write(pbm->pbm_regs + FIRE_LPU_LLCFG,
422 FIRE_LPU_LLCFG_VC0);
423 fire_write(pbm->pbm_regs + FIRE_LPU_FCTRL_UCTRL,
424 (FIRE_LPU_FCTRL_UCTRL_N |
425 FIRE_LPU_FCTRL_UCTRL_P));
426 fire_write(pbm->pbm_regs + FIRE_LPU_TXL_FIFOP,
427 ((0xffff << 16) | (0x0000 << 0)));
428 fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG2, 3000000);
429 fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG3, 500000);
430 fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG4,
431 (2 << 16) | (140 << 8));
432 fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG5, 0);
433
434 fire_write(pbm->pbm_regs + FIRE_DMC_IENAB, ~(u64)0);
435 fire_write(pbm->pbm_regs + FIRE_DMC_DBG_SEL_A, 0);
436 fire_write(pbm->pbm_regs + FIRE_DMC_DBG_SEL_B, 0);
437
438 fire_write(pbm->pbm_regs + FIRE_PEC_IENAB, ~(u64)0);
439}
440
Sam Ravnborga1f35ba2008-01-21 17:22:46 -0800441static int __init pci_fire_pbm_init(struct pci_controller_info *p,
442 struct device_node *dp, u32 portid)
David S. Miller861fe902007-05-02 17:31:36 -0700443{
444 const struct linux_prom64_registers *regs;
445 struct pci_pbm_info *pbm;
David S. Miller9bb3c222007-08-30 22:33:25 -0700446 int err;
David S. Miller861fe902007-05-02 17:31:36 -0700447
448 if ((portid & 1) == 0)
449 pbm = &p->pbm_A;
450 else
451 pbm = &p->pbm_B;
452
David S. Miller34768bc2007-05-07 23:06:27 -0700453 pbm->next = pci_pbm_root;
454 pci_pbm_root = pbm;
455
David S. Millerc1b1a5f2008-03-19 04:52:48 -0700456 pbm->numa_node = -1;
457
David S. Millerca3dd882007-05-09 02:35:27 -0700458 pbm->pci_ops = &sun4u_pci_ops;
459 pbm->config_space_reg_bits = 12;
David S. Miller34768bc2007-05-07 23:06:27 -0700460
David S. Miller6c108f12007-05-07 23:49:01 -0700461 pbm->index = pci_num_pbms++;
462
David S. Miller861fe902007-05-02 17:31:36 -0700463 pbm->portid = portid;
464 pbm->parent = p;
465 pbm->prom_node = dp;
466 pbm->name = dp->full_name;
467
468 regs = of_get_property(dp, "reg", NULL);
469 pbm->pbm_regs = regs[0].phys_addr;
470 pbm->controller_regs = regs[1].phys_addr - 0x410000UL;
471
472 printk("%s: SUN4U PCIE Bus Module\n", pbm->name);
473
474 pci_determine_mem_io_space(pbm);
475
David S. Millercfa06522007-05-07 21:51:41 -0700476 pci_get_pbm_props(pbm);
David S. Miller861fe902007-05-02 17:31:36 -0700477
478 pci_fire_hw_init(pbm);
David S. Millerad7ad572007-07-27 22:39:14 -0700479
David S. Miller9bb3c222007-08-30 22:33:25 -0700480 err = pci_fire_pbm_iommu_init(pbm);
481 if (err)
482 return err;
483
484 pci_fire_msi_init(pbm);
485
David S. Millerc8049962008-08-30 03:12:38 -0700486 pci_fire_scan_bus(pbm);
487
David S. Miller9bb3c222007-08-30 22:33:25 -0700488 return 0;
David S. Miller861fe902007-05-02 17:31:36 -0700489}
490
491static inline int portid_compare(u32 x, u32 y)
492{
493 if (x == (y ^ 1))
494 return 1;
495 return 0;
496}
497
David S. Millerc8049962008-08-30 03:12:38 -0700498static int __devinit fire_probe(struct of_device *op,
499 const struct of_device_id *match)
David S. Miller861fe902007-05-02 17:31:36 -0700500{
David S. Millerc8049962008-08-30 03:12:38 -0700501 struct device_node *dp = op->node;
David S. Miller861fe902007-05-02 17:31:36 -0700502 struct pci_controller_info *p;
David S. Miller34768bc2007-05-07 23:06:27 -0700503 struct pci_pbm_info *pbm;
David S. Millerc8049962008-08-30 03:12:38 -0700504 struct iommu *iommu;
505 u32 portid;
506 int err;
David S. Miller861fe902007-05-02 17:31:36 -0700507
David S. Millerc8049962008-08-30 03:12:38 -0700508 portid = of_getintprop_default(dp, "portid", 0xff);
David S. Miller34768bc2007-05-07 23:06:27 -0700509 for (pbm = pci_pbm_root; pbm; pbm = pbm->next) {
David S. Millerc8049962008-08-30 03:12:38 -0700510 if (portid_compare(pbm->portid, portid))
511 return pci_fire_pbm_init(pbm->parent, dp, portid);
David S. Miller861fe902007-05-02 17:31:36 -0700512 }
513
David S. Millerc8049962008-08-30 03:12:38 -0700514 err = -ENOMEM;
David S. Miller861fe902007-05-02 17:31:36 -0700515 p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
David S. Millerc8049962008-08-30 03:12:38 -0700516 if (!p) {
517 printk(KERN_ERR PFX "Cannot allocate controller info.\n");
518 goto out_free;
519 }
David S. Miller861fe902007-05-02 17:31:36 -0700520
521 iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
David S. Millerc8049962008-08-30 03:12:38 -0700522 if (!iommu) {
523 printk(KERN_ERR PFX "Cannot allocate PBM A iommu.\n");
524 goto out_free;
525 }
David S. Miller861fe902007-05-02 17:31:36 -0700526
527 p->pbm_A.iommu = iommu;
528
529 iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
David S. Millerc8049962008-08-30 03:12:38 -0700530 if (!iommu) {
531 printk(KERN_ERR PFX "Cannot allocate PBM A iommu.\n");
532 goto out_free;
533 }
David S. Miller861fe902007-05-02 17:31:36 -0700534
535 p->pbm_B.iommu = iommu;
536
David S. Millerc8049962008-08-30 03:12:38 -0700537 return pci_fire_pbm_init(p, dp, portid);
David S. Millerad7ad572007-07-27 22:39:14 -0700538
David S. Millerc8049962008-08-30 03:12:38 -0700539out_free:
540 if (p) {
541 if (p->pbm_A.iommu)
542 kfree(p->pbm_A.iommu);
543 if (p->pbm_B.iommu)
544 kfree(p->pbm_B.iommu);
545 kfree(p);
546 }
547 return err;
David S. Miller861fe902007-05-02 17:31:36 -0700548}
David S. Millerc8049962008-08-30 03:12:38 -0700549
David S. Millerfd098312008-08-31 01:23:17 -0700550static struct of_device_id __initdata fire_match[] = {
David S. Millerc8049962008-08-30 03:12:38 -0700551 {
552 .name = "pci",
553 .compatible = "pciex108e,80f0",
554 },
555 {},
556};
557
558static struct of_platform_driver fire_driver = {
559 .name = DRIVER_NAME,
560 .match_table = fire_match,
561 .probe = fire_probe,
562};
563
564static int __init fire_init(void)
565{
566 return of_register_driver(&fire_driver, &of_bus_type);
567}
568
569subsys_initcall(fire_init);