Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pci.c
Go to the documentation of this file.
1 /*
2  * iop13xx PCI support
3  * Copyright (c) 2005-2006, Intel Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307 USA.
17  *
18  */
19 
20 #include <linux/pci.h>
21 #include <linux/slab.h>
22 #include <linux/delay.h>
23 #include <linux/jiffies.h>
24 #include <linux/export.h>
25 #include <asm/irq.h>
26 #include <mach/hardware.h>
27 #include <asm/sizes.h>
28 #include <asm/signal.h>
29 #include <asm/mach/pci.h>
30 #include <mach/pci.h>
31 
32 #define IOP13XX_PCI_DEBUG 0
33 #define PRINTK(x...) ((void)(IOP13XX_PCI_DEBUG && printk(x)))
34 
35 u32 iop13xx_atux_pmmr_offset; /* This offset can change based on strapping */
36 u32 iop13xx_atue_pmmr_offset; /* This offset can change based on strapping */
37 static struct pci_bus *pci_bus_atux = 0;
38 static struct pci_bus *pci_bus_atue = 0;
43 
48 
49 int init_atu = 0; /* Flag to select which ATU(s) to initialize / disable */
50 static unsigned long atux_trhfa_timeout = 0; /* Trhfa = RST# high to first
51  access */
52 
53 /* Scan the initialized busses and ioremap the requested memory range
54  */
56 {
57  int atu;
58  struct pci_bus *bus;
59  struct pci_dev *dev;
60  resource_size_t end = 0;
61 
62  for (atu = 0; atu < 2; atu++) {
63  bus = atu ? pci_bus_atue : pci_bus_atux;
64  if (bus) {
65  list_for_each_entry(dev, &bus->devices, bus_list) {
66  int i;
67  int max = 7;
68 
69  if (dev->subordinate)
71 
72  for (i = 0; i < max; i++) {
73  struct resource *res = &dev->resource[i];
74  if (res->flags & IORESOURCE_MEM)
75  end = max(res->end, end);
76  }
77  }
78 
79  switch(atu) {
80  case 0:
82  (end - IOP13XX_PCIX_LOWER_MEM_RA) + 1;
83 
84  /* 16MB align the request */
85  if (iop13xx_atux_mem_size & (SZ_16M - 1)) {
86  iop13xx_atux_mem_size &= ~(SZ_16M - 1);
88  }
89 
90  if (end) {
94  if (!iop13xx_atux_mem_base) {
95  printk("%s: atux allocation "
96  "failed\n", __func__);
97  BUG();
98  }
99  } else
101  PRINTK("%s: atu: %d bus_size: %d mem_base: %p\n",
102  __func__, atu, iop13xx_atux_mem_size,
104  break;
105  case 1:
107  (end - IOP13XX_PCIE_LOWER_MEM_RA) + 1;
108 
109  /* 16MB align the request */
110  if (iop13xx_atue_mem_size & (SZ_16M - 1)) {
111  iop13xx_atue_mem_size &= ~(SZ_16M - 1);
113  }
114 
115  if (end) {
119  if (!iop13xx_atue_mem_base) {
120  printk("%s: atue allocation "
121  "failed\n", __func__);
122  BUG();
123  }
124  } else
126  PRINTK("%s: atu: %d bus_size: %d mem_base: %p\n",
127  __func__, atu, iop13xx_atue_mem_size,
129  break;
130  }
131 
132  printk("%s: Initialized (%uM @ resource/virtual: %08lx/%p)\n",
133  atu ? "ATUE" : "ATUX",
135  SZ_1M,
138  atu ? iop13xx_atue_mem_base :
140  end = 0;
141  }
142 
143  }
144 }
145 
146 static int iop13xx_atu_function(int atu)
147 {
148  int func = 0;
149  /* the function number depends on the value of the
150  * IOP13XX_INTERFACE_SEL_PCIX reset strap
151  * see C-Spec section 3.17
152  */
153  switch(atu) {
156  func = 5;
157  else
158  func = 0;
159  break;
161  if (__raw_readl(IOP13XX_ESSR0) & IOP13XX_INTERFACE_SEL_PCIX)
162  func = 0;
163  else
164  func = 5;
165  break;
166  default:
167  BUG();
168  }
169 
170  return func;
171 }
172 
173 /* iop13xx_atux_cfg_address - format a configuration address for atux
174  * @bus: Target bus to access
175  * @devfn: Combined device number and function number
176  * @where: Desired register's address offset
177  *
178  * Convert the parameters to a configuration address formatted
179  * according the PCI-X 2.0 specification
180  */
181 static u32 iop13xx_atux_cfg_address(struct pci_bus *bus, int devfn, int where)
182 {
183  struct pci_sys_data *sys = bus->sysdata;
184  u32 addr;
185 
186  if (sys->busnr == bus->number)
187  addr = 1 << (PCI_SLOT(devfn) + 16) | (PCI_SLOT(devfn) << 11);
188  else
189  addr = bus->number << 16 | PCI_SLOT(devfn) << 11 | 1;
190 
191  addr |= PCI_FUNC(devfn) << 8 | ((where & 0xff) & ~3);
192  addr |= ((where & 0xf00) >> 8) << 24; /* upper register number */
193 
194  return addr;
195 }
196 
197 /* iop13xx_atue_cfg_address - format a configuration address for atue
198  * @bus: Target bus to access
199  * @devfn: Combined device number and function number
200  * @where: Desired register's address offset
201  *
202  * Convert the parameters to an address usable by the ATUE_OCCAR
203  */
204 static u32 iop13xx_atue_cfg_address(struct pci_bus *bus, int devfn, int where)
205 {
206  struct pci_sys_data *sys = bus->sysdata;
207  u32 addr;
208 
209  PRINTK("iop13xx_atue_cfg_address: bus: %d dev: %d func: %d",
210  bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
211  addr = ((u32) bus->number) << IOP13XX_ATUE_OCCAR_BUS_NUM |
212  ((u32) PCI_SLOT(devfn)) << IOP13XX_ATUE_OCCAR_DEV_NUM |
214  (where & ~0x3);
215 
216  if (sys->busnr != bus->number)
217  addr |= 1; /* type 1 access */
218 
219  return addr;
220 }
221 
222 /* This routine checks the status of the last configuration cycle. If an error
223  * was detected it returns >0, else it returns a 0. The errors being checked
224  * are parity, master abort, target abort (master and target). These types of
225  * errors occur during a config cycle where there is no device, like during
226  * the discovery stage.
227  */
228 static int iop13xx_atux_pci_status(int clear)
229 {
230  unsigned int status;
231  int err = 0;
232 
233  /*
234  * Check the status registers.
235  */
237  if (status & IOP_PCI_STATUS_ERROR)
238  {
239  PRINTK("\t\t\tPCI error: ATUSR %#08x", status);
240  if(clear)
241  __raw_writew(status & IOP_PCI_STATUS_ERROR,
243  err = 1;
244  }
246  if (status & IOP13XX_ATUX_ATUISR_ERROR)
247  {
248  PRINTK("\t\t\tPCI error interrupt: ATUISR %#08x", status);
249  if(clear)
250  __raw_writel(status & IOP13XX_ATUX_ATUISR_ERROR,
252  err = 1;
253  }
254  return err;
255 }
256 
257 /* Simply write the address register and read the configuration
258  * data. Note that the data dependency on %0 encourages an abort
259  * to be detected before we return.
260  */
261 static u32 iop13xx_atux_read(unsigned long addr)
262 {
263  u32 val;
264 
265  __asm__ __volatile__(
266  "str %1, [%2]\n\t"
267  "ldr %0, [%3]\n\t"
268  "mov %0, %0\n\t"
269  : "=r" (val)
270  : "r" (addr), "r" (IOP13XX_ATUX_OCCAR), "r" (IOP13XX_ATUX_OCCDR));
271 
272  return val;
273 }
274 
275 /* The read routines must check the error status of the last configuration
276  * cycle. If there was an error, the routine returns all hex f's.
277  */
278 static int
279 iop13xx_atux_read_config(struct pci_bus *bus, unsigned int devfn, int where,
280  int size, u32 *value)
281 {
282  unsigned long addr = iop13xx_atux_cfg_address(bus, devfn, where);
283  u32 val = iop13xx_atux_read(addr) >> ((where & 3) * 8);
284 
285  if (iop13xx_atux_pci_status(1) || is_atux_occdr_error()) {
288  val = 0xffffffff;
289  }
290 
291  *value = val;
292 
293  return PCIBIOS_SUCCESSFUL;
294 }
295 
296 static int
297 iop13xx_atux_write_config(struct pci_bus *bus, unsigned int devfn, int where,
298  int size, u32 value)
299 {
300  unsigned long addr = iop13xx_atux_cfg_address(bus, devfn, where);
301  u32 val;
302 
303  if (size != 4) {
304  val = iop13xx_atux_read(addr);
305  if (!iop13xx_atux_pci_status(1) == 0)
306  return PCIBIOS_SUCCESSFUL;
307 
308  where = (where & 3) * 8;
309 
310  if (size == 1)
311  val &= ~(0xff << where);
312  else
313  val &= ~(0xffff << where);
314 
315  __raw_writel(val | value << where, IOP13XX_ATUX_OCCDR);
316  } else {
319  }
320 
321  return PCIBIOS_SUCCESSFUL;
322 }
323 
324 static struct pci_ops iop13xx_atux_ops = {
325  .read = iop13xx_atux_read_config,
326  .write = iop13xx_atux_write_config,
327 };
328 
329 /* This routine checks the status of the last configuration cycle. If an error
330  * was detected it returns >0, else it returns a 0. The errors being checked
331  * are parity, master abort, target abort (master and target). These types of
332  * errors occur during a config cycle where there is no device, like during
333  * the discovery stage.
334  */
335 static int iop13xx_atue_pci_status(int clear)
336 {
337  unsigned int status;
338  int err = 0;
339 
340  /*
341  * Check the status registers.
342  */
343 
344  /* standard pci status register */
346  if (status & IOP_PCI_STATUS_ERROR) {
347  PRINTK("\t\t\tPCI error: ATUSR %#08x", status);
348  if(clear)
349  __raw_writew(status & IOP_PCI_STATUS_ERROR,
351  err++;
352  }
353 
354  /* check the normal status bits in the ATUISR */
356  if (status & IOP13XX_ATUE_ATUISR_ERROR) {
357  PRINTK("\t\t\tPCI error: ATUISR %#08x", status);
358  if (clear)
359  __raw_writew(status & IOP13XX_ATUE_ATUISR_ERROR,
361  err++;
362 
363  /* check the PCI-E status if the ATUISR reports an interface error */
364  if (status & IOP13XX_ATUE_STAT_PCI_IFACE_ERR) {
365  /* get the unmasked errors */
368 
369  if (status) {
370  PRINTK("\t\t\tPCI-E error: ATUE_PIE_STS %#08x",
372  err++;
373  } else {
374  PRINTK("\t\t\tPCI-E error: ATUE_PIE_STS %#08x",
376  PRINTK("\t\t\tPCI-E error: ATUE_PIE_MSK %#08x",
378  BUG();
379  }
380 
381  if(clear)
383  }
384  }
385 
386  return err;
387 }
388 
389 static int
390 iop13xx_pcie_map_irq(const struct pci_dev *dev, u8 idsel, u8 pin)
391 {
392  WARN_ON(idsel != 0);
393 
394  switch (pin) {
395  case 1: return ATUE_INTA;
396  case 2: return ATUE_INTB;
397  case 3: return ATUE_INTC;
398  case 4: return ATUE_INTD;
399  default: return -1;
400  }
401 }
402 
403 static u32 iop13xx_atue_read(unsigned long addr)
404 {
405  u32 val;
406 
409 
410  rmb();
411 
412  return val;
413 }
414 
415 /* The read routines must check the error status of the last configuration
416  * cycle. If there was an error, the routine returns all hex f's.
417  */
418 static int
419 iop13xx_atue_read_config(struct pci_bus *bus, unsigned int devfn, int where,
420  int size, u32 *value)
421 {
422  u32 val;
423  unsigned long addr = iop13xx_atue_cfg_address(bus, devfn, where);
424 
425  /* Hide device numbers > 0 on the local PCI-E bus (Type 0 access) */
426  if (!PCI_SLOT(devfn) || (addr & 1)) {
427  val = iop13xx_atue_read(addr) >> ((where & 3) * 8);
428  if( iop13xx_atue_pci_status(1) || is_atue_occdr_error() ) {
431  val = 0xffffffff;
432  }
433 
434  PRINTK("addr=%#0lx, val=%#010x", addr, val);
435  } else
436  val = 0xffffffff;
437 
438  *value = val;
439 
440  return PCIBIOS_SUCCESSFUL;
441 }
442 
443 static int
444 iop13xx_atue_write_config(struct pci_bus *bus, unsigned int devfn, int where,
445  int size, u32 value)
446 {
447  unsigned long addr = iop13xx_atue_cfg_address(bus, devfn, where);
448  u32 val;
449 
450  if (size != 4) {
451  val = iop13xx_atue_read(addr);
452  if (!iop13xx_atue_pci_status(1) == 0)
453  return PCIBIOS_SUCCESSFUL;
454 
455  where = (where & 3) * 8;
456 
457  if (size == 1)
458  val &= ~(0xff << where);
459  else
460  val &= ~(0xffff << where);
461 
462  __raw_writel(val | value << where, IOP13XX_ATUE_OCCDR);
463  } else {
466  }
467 
468  return PCIBIOS_SUCCESSFUL;
469 }
470 
471 static struct pci_ops iop13xx_atue_ops = {
472  .read = iop13xx_atue_read_config,
473  .write = iop13xx_atue_write_config,
474 };
475 
476 /* When a PCI device does not exist during config cycles, the XScale gets a
477  * bus error instead of returning 0xffffffff. We can't rely on the ATU status
478  * bits to tell us that it was indeed a configuration cycle that caused this
479  * error especially in the case when the ATUE link is down. Instead we rely
480  * on data from the south XSI bridge to validate the abort
481  */
482 int
483 iop13xx_pci_abort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
484 {
485  PRINTK("Data abort: address = 0x%08lx "
486  "fsr = 0x%03x PC = 0x%08lx LR = 0x%08lx",
487  addr, fsr, regs->ARM_pc, regs->ARM_lr);
488 
489  PRINTK("IOP13XX_XBG_BECSR: %#10x", __raw_readl(IOP13XX_XBG_BECSR));
490  PRINTK("IOP13XX_XBG_BERAR: %#10x", __raw_readl(IOP13XX_XBG_BERAR));
491  PRINTK("IOP13XX_XBG_BERUAR: %#10x", __raw_readl(IOP13XX_XBG_BERUAR));
492 
493  /* If it was an imprecise abort, then we need to correct the
494  * return address to be _after_ the instruction.
495  */
496  if (fsr & (1 << 10))
497  regs->ARM_pc += 4;
498 
500  return 0;
501  else
502  return 1;
503 }
504 
505 /* Scan an IOP13XX PCI bus. nr selects which ATU we use.
506  */
508 {
509  int which_atu;
510  struct pci_bus *bus = NULL;
511 
512  switch (init_atu) {
514  which_atu = nr ? 0 : IOP13XX_INIT_ATU_ATUX;
515  break;
517  which_atu = nr ? 0 : IOP13XX_INIT_ATU_ATUE;
518  break;
520  which_atu = nr ? IOP13XX_INIT_ATU_ATUE : IOP13XX_INIT_ATU_ATUX;
521  break;
522  default:
523  which_atu = 0;
524  }
525 
526  if (!which_atu) {
527  BUG();
528  return NULL;
529  }
530 
531  switch (which_atu) {
534  atux_trhfa_timeout)) /* ensure not wrap */
535  while(time_before(jiffies, atux_trhfa_timeout))
536  udelay(100);
537 
538  bus = pci_bus_atux = pci_scan_root_bus(NULL, sys->busnr,
539  &iop13xx_atux_ops,
540  sys, &sys->resources);
541  break;
543  bus = pci_bus_atue = pci_scan_root_bus(NULL, sys->busnr,
544  &iop13xx_atue_ops,
545  sys, &sys->resources);
546  break;
547  }
548 
549  return bus;
550 }
551 
552 /* This function is called from iop13xx_pci_init() after assigning valid
553  * values to iop13xx_atue_pmmr_offset. This is the location for common
554  * setup of ATUE for all IOP13XX implementations.
555  */
557 {
558  int func = iop13xx_atu_function(IOP13XX_INIT_ATU_ATUE);
559  u32 reg_val;
560 
561 #ifdef CONFIG_PCI_MSI
562  /* BAR 0 (inbound msi window) */
567 #endif
568 
569  /* BAR 1 (1:1 mapping with Physical RAM) */
570  /* Set limit and enable */
574 
575  /* Set base at the top of the reserved address space */
578 
579  /* 1:1 mapping with physical ram
580  * (leave big endian byte swap disabled)
581  */
584 
585  /* Outbound window 1 (PCIX/PCIE memory window) */
586  /* 32 bit Address Space */
588  /* PA[35:32] */
592 
593  /* Setup the I/O Bar
594  * A[35-16] in 31-12
595  */
596  __raw_writel(((IOP13XX_PCIE_LOWER_IO_PA >> 0x4) & 0xfffff000),
599 
600  /* clear startup errors */
601  iop13xx_atue_pci_status(1);
602 
603  /* OIOBAR function number
604  */
605  reg_val = __raw_readl(IOP13XX_ATUE_OIOBAR);
606  reg_val &= ~0x7;
607  reg_val |= func;
609 
610  /* OUMBAR function numbers
611  */
613  reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
615  reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
617 
619  reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
621  reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
623 
625  reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
627  reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
629 
631  reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
633  reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
635 
636  /* Enable inbound and outbound cycles
637  */
638  reg_val = __raw_readw(IOP13XX_ATUE_ATUCMD);
642 
643  reg_val = __raw_readl(IOP13XX_ATUE_ATUCR);
644  reg_val |= IOP13XX_ATUE_ATUCR_OUT_EN |
647 }
648 
650 {
651  u32 reg_val;
652 
655 
656  /* wait for cycles to quiesce */
660  cpu_relax();
661 
662  /* BAR 0 ( Disabled ) */
669  reg_val &= ~IOP13XX_ATUE_OUMBAR_ENABLE;
671 
672  /* BAR 1 ( Disabled ) */
679  reg_val &= ~IOP13XX_ATUE_OUMBAR_ENABLE;
681 
682  /* BAR 2 ( Disabled ) */
689  reg_val &= ~IOP13XX_ATUE_OUMBAR_ENABLE;
691 
692  /* BAR 3 ( Disabled ) */
694  reg_val &= ~IOP13XX_ATUE_OUMBAR_ENABLE;
696 
697  /* Setup the I/O Bar
698  * A[35-16] in 31-12
699  */
700  __raw_writel((IOP13XX_PCIE_LOWER_IO_PA >> 0x4) & 0xfffff000,
703 }
704 
705 /* This function is called from iop13xx_pci_init() after assigning valid
706  * values to iop13xx_atux_pmmr_offset. This is the location for common
707  * setup of ATUX for all IOP13XX implementations.
708  */
710 {
711  u32 reg_val;
712  int func = iop13xx_atu_function(IOP13XX_INIT_ATU_ATUX);
713 
714  /* Take PCI-X bus out of reset if bootloader hasn't already.
715  * According to spec, we should wait for 2^25 PCI clocks to meet
716  * the PCI timing parameter Trhfa (RST# high to first access).
717  * This is rarely necessary and often ignored.
718  */
719  reg_val = __raw_readl(IOP13XX_ATUX_PCSR);
720  if (reg_val & IOP13XX_ATUX_PCSR_P_RSTOUT) {
721  int msec = (reg_val >> IOP13XX_ATUX_PCSR_FREQ_OFFSET) & 0x7;
722  msec = 1000 / (8-msec); /* bits 100=133MHz, 111=>33MHz */
723  __raw_writel(reg_val & ~IOP13XX_ATUX_PCSR_P_RSTOUT,
725  atux_trhfa_timeout = jiffies + msecs_to_jiffies(msec);
726  }
727  else
728  atux_trhfa_timeout = jiffies;
729 
730 #ifdef CONFIG_PCI_MSI
731  /* BAR 0 (inbound msi window) */
736 #endif
737 
738  /* BAR 1 (1:1 mapping with Physical RAM) */
739  /* Set limit and enable */
743 
744  /* Set base at the top of the reserved address space */
747 
748  /* 1:1 mapping with physical ram
749  * (leave big endian byte swap disabled)
750  */
753 
754  /* Outbound window 1 (PCIX/PCIE memory window) */
755  /* 32 bit Address Space */
757  /* PA[35:32] */
761 
762  /* Setup the I/O Bar
763  * A[35-16] in 31-12
764  */
765  __raw_writel((IOP13XX_PCIX_LOWER_IO_PA >> 0x4) & 0xfffff000,
768 
769  /* clear startup errors */
770  iop13xx_atux_pci_status(1);
771 
772  /* OIOBAR function number
773  */
774  reg_val = __raw_readl(IOP13XX_ATUX_OIOBAR);
775  reg_val &= ~0x7;
776  reg_val |= func;
778 
779  /* OUMBAR function numbers
780  */
782  reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
784  reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
786 
788  reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
790  reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
792 
794  reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
796  reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
798 
800  reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
802  reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
804 
805  /* Enable inbound and outbound cycles
806  */
807  reg_val = __raw_readw(IOP13XX_ATUX_ATUCMD);
811 
812  reg_val = __raw_readl(IOP13XX_ATUX_ATUCR);
813  reg_val |= IOP13XX_ATUX_ATUCR_OUT_EN;
815 }
816 
818 {
819  u32 reg_val;
820 
823 
824  /* wait for cycles to quiesce */
827  cpu_relax();
828 
829  /* BAR 0 ( Disabled ) */
836  reg_val &= ~IOP13XX_ATUX_OUMBAR_ENABLE;
838 
839  /* BAR 1 ( Disabled ) */
846  reg_val &= ~IOP13XX_ATUX_OUMBAR_ENABLE;
848 
849  /* BAR 2 ( Disabled ) */
856  reg_val &= ~IOP13XX_ATUX_OUMBAR_ENABLE;
858 
859  /* BAR 3 ( Disabled ) */
866  reg_val &= ~IOP13XX_ATUX_OUMBAR_ENABLE;
868 
869  /* Setup the I/O Bar
870  * A[35-16] in 31-12
871  */
872  __raw_writel((IOP13XX_PCIX_LOWER_IO_PA >> 0x4) & 0xfffff000,
875 }
876 
878 {
879  /* Based on ESSR0, determine the ATU X/E offsets */
880  switch(__raw_readl(IOP13XX_ESSR0) &
881  (IOP13XX_CONTROLLER_ONLY | IOP13XX_INTERFACE_SEL_PCIX)) {
882  /* both asserted */
883  case 0:
886  break;
887  /* IOP13XX_CONTROLLER_ONLY = deasserted
888  * IOP13XX_INTERFACE_SEL_PCIX = asserted
889  */
893  break;
894  /* IOP13XX_CONTROLLER_ONLY = asserted
895  * IOP13XX_INTERFACE_SEL_PCIX = deasserted
896  */
897  case IOP13XX_INTERFACE_SEL_PCIX:
900  break;
901  /* both deasserted */
902  case IOP13XX_CONTROLLER_ONLY | IOP13XX_INTERFACE_SEL_PCIX:
905  break;
906  default:
907  BUG();
908  }
909 }
910 
911 void __init iop13xx_atu_select(struct hw_pci *plat_pci)
912 {
913  int i;
914 
915  /* set system defaults
916  * note: if "iop13xx_init_atu=" is specified this autodetect
917  * sequence will be bypassed
918  */
920  /* check for single/dual interface */
921  if (__raw_readl(IOP13XX_ESSR0) & IOP13XX_INTERFACE_SEL_PCIX) {
922  /* ATUE must be present check the device id
923  * to see if ATUX is present.
924  */
926  switch (__raw_readw(IOP13XX_ATUE_DID) & 0xf0) {
927  case 0x70:
928  case 0x80:
929  case 0xc0:
931  break;
932  }
933  } else {
934  /* ATUX must be present check the device id
935  * to see if ATUE is present.
936  */
938  switch (__raw_readw(IOP13XX_ATUX_DID) & 0xf0) {
939  case 0x70:
940  case 0x80:
941  case 0xc0:
943  break;
944  }
945  }
946 
947  /* check central resource and root complex capability */
951  init_atu &= ~IOP13XX_INIT_ATU_ATUX;
952 
956  init_atu &= ~IOP13XX_INIT_ATU_ATUE;
957  }
958 
959  for (i = 0; i < 2; i++) {
960  if((init_atu & (1 << i)) == (1 << i))
961  plat_pci->nr_controllers++;
962  }
963 }
964 
966 {
967  /* clear pre-existing south bridge errors */
969 
970  /* Setup the Min Address for PCI memory... */
971  pcibios_min_mem = IOP13XX_PCIX_LOWER_MEM_BA;
972 
973  /* if Linux is given control of an ATU
974  * clear out its prior configuration,
975  * otherwise do not touch the registers
976  */
980  }
981 
985  }
986 
988  "imprecise external abort");
989 }
990 
991 /* initialize the pci memory space. handle any combination of
992  * atue and atux enabled/disabled
993  */
994 int iop13xx_pci_setup(int nr, struct pci_sys_data *sys)
995 {
996  struct resource *res;
997  int which_atu;
998  u32 pcixsr, pcsr;
999 
1000  if (nr > 1)
1001  return 0;
1002 
1003  res = kzalloc(sizeof(struct resource), GFP_KERNEL);
1004  if (!res)
1005  panic("PCI: unable to alloc resources");
1006 
1007 
1008  /* 'nr' assumptions:
1009  * ATUX is always 0
1010  * ATUE is 1 when ATUX is also enabled
1011  * ATUE is 0 when ATUX is disabled
1012  */
1013  switch(init_atu) {
1014  case IOP13XX_INIT_ATU_ATUX:
1015  which_atu = nr ? 0 : IOP13XX_INIT_ATU_ATUX;
1016  break;
1017  case IOP13XX_INIT_ATU_ATUE:
1018  which_atu = nr ? 0 : IOP13XX_INIT_ATU_ATUE;
1019  break;
1021  which_atu = nr ? IOP13XX_INIT_ATU_ATUE : IOP13XX_INIT_ATU_ATUX;
1022  break;
1023  default:
1024  which_atu = 0;
1025  }
1026 
1027  if (!which_atu) {
1028  kfree(res);
1029  return 0;
1030  }
1031 
1032  switch(which_atu) {
1033  case IOP13XX_INIT_ATU_ATUX:
1034  pcixsr = __raw_readl(IOP13XX_ATUX_PCIXSR);
1035  pcixsr &= ~0xffff;
1036  pcixsr |= sys->busnr << IOP13XX_ATUX_PCIXSR_BUS_NUM |
1038  iop13xx_atu_function(IOP13XX_INIT_ATU_ATUX)
1041 
1042  pci_ioremap_io(0, IOP13XX_PCIX_LOWER_IO_PA);
1043 
1046  res->name = "IQ81340 ATUX PCI Memory Space";
1047  res->flags = IORESOURCE_MEM;
1049  break;
1050  case IOP13XX_INIT_ATU_ATUE:
1051  /* Note: the function number field in the PCSR is ro */
1053  pcsr &= ~(0xfff8 << 16);
1054  pcsr |= sys->busnr << IOP13XX_ATUE_PCSR_BUS_NUM |
1056 
1058 
1059  pci_ioremap_io(SZ_64K, IOP13XX_PCIE_LOWER_IO_PA);
1060 
1063  res->name = "IQ81340 ATUE PCI Memory Space";
1064  res->flags = IORESOURCE_MEM;
1066  sys->map_irq = iop13xx_pcie_map_irq;
1067  break;
1068  default:
1069  kfree(res);
1070  return 0;
1071  }
1072 
1074 
1075  pci_add_resource_offset(&sys->resources, res, sys->mem_offset);
1076 
1077  return 1;
1078 }
1079 
1081 {
1082  if (__raw_readl(IOP13XX_ESSR0) & IOP13XX_INTERFACE_SEL_PCIX)
1083  return __raw_readw(IOP13XX_ATUE_DID);
1084  else
1085  return __raw_readw(IOP13XX_ATUX_DID);
1086 }
1087 
1088 static int __init iop13xx_init_atu_setup(char *str)
1089 {
1091  if (str) {
1092  while (*str != '\0') {
1093  switch (*str) {
1094  case 'x':
1095  case 'X':
1098  break;
1099  case 'e':
1100  case 'E':
1103  break;
1104  case ',':
1105  case '=':
1106  break;
1107  default:
1108  PRINTK("\"iop13xx_init_atu\" malformed at "
1109  "character: \'%c\'", *str);
1110  *(str + 1) = '\0';
1112  }
1113  str++;
1114  }
1115  }
1116  return 1;
1117 }
1118 
1119 __setup("iop13xx_init_atu", iop13xx_init_atu_setup);