pci.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  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. #include <linux/pci.h>
  20. #include <linux/slab.h>
  21. #include <linux/delay.h>
  22. #include <linux/jiffies.h>
  23. #include <asm/irq.h>
  24. #include <mach/hardware.h>
  25. #include <asm/sizes.h>
  26. #include <asm/signal.h>
  27. #include <asm/mach/pci.h>
  28. #include <mach/pci.h>
  29. #define IOP13XX_PCI_DEBUG 0
  30. #define PRINTK(x...) ((void)(IOP13XX_PCI_DEBUG && printk(x)))
  31. u32 iop13xx_atux_pmmr_offset; /* This offset can change based on strapping */
  32. u32 iop13xx_atue_pmmr_offset; /* This offset can change based on strapping */
  33. static struct pci_bus *pci_bus_atux = 0;
  34. static struct pci_bus *pci_bus_atue = 0;
  35. u32 iop13xx_atue_mem_base;
  36. u32 iop13xx_atux_mem_base;
  37. size_t iop13xx_atue_mem_size;
  38. size_t iop13xx_atux_mem_size;
  39. unsigned long iop13xx_pcibios_min_io = 0;
  40. unsigned long iop13xx_pcibios_min_mem = 0;
  41. EXPORT_SYMBOL(iop13xx_atue_mem_base);
  42. EXPORT_SYMBOL(iop13xx_atux_mem_base);
  43. EXPORT_SYMBOL(iop13xx_atue_mem_size);
  44. EXPORT_SYMBOL(iop13xx_atux_mem_size);
  45. int init_atu = 0; /* Flag to select which ATU(s) to initialize / disable */
  46. static unsigned long atux_trhfa_timeout = 0; /* Trhfa = RST# high to first
  47. access */
  48. /* Scan the initialized busses and ioremap the requested memory range
  49. */
  50. void iop13xx_map_pci_memory(void)
  51. {
  52. int atu;
  53. struct pci_bus *bus;
  54. struct pci_dev *dev;
  55. resource_size_t end = 0;
  56. for (atu = 0; atu < 2; atu++) {
  57. bus = atu ? pci_bus_atue : pci_bus_atux;
  58. if (bus) {
  59. list_for_each_entry(dev, &bus->devices, bus_list) {
  60. int i;
  61. int max = 7;
  62. if (dev->subordinate)
  63. max = DEVICE_COUNT_RESOURCE;
  64. for (i = 0; i < max; i++) {
  65. struct resource *res = &dev->resource[i];
  66. if (res->flags & IORESOURCE_MEM)
  67. end = max(res->end, end);
  68. }
  69. }
  70. switch(atu) {
  71. case 0:
  72. iop13xx_atux_mem_size =
  73. (end - IOP13XX_PCIX_LOWER_MEM_RA) + 1;
  74. /* 16MB align the request */
  75. if (iop13xx_atux_mem_size & (SZ_16M - 1)) {
  76. iop13xx_atux_mem_size &= ~(SZ_16M - 1);
  77. iop13xx_atux_mem_size += SZ_16M;
  78. }
  79. if (end) {
  80. iop13xx_atux_mem_base =
  81. (u32) __arm_ioremap_pfn(
  82. __phys_to_pfn(IOP13XX_PCIX_LOWER_MEM_PA)
  83. , 0, iop13xx_atux_mem_size, MT_DEVICE);
  84. if (!iop13xx_atux_mem_base) {
  85. printk("%s: atux allocation "
  86. "failed\n", __func__);
  87. BUG();
  88. }
  89. } else
  90. iop13xx_atux_mem_size = 0;
  91. PRINTK("%s: atu: %d bus_size: %d mem_base: %x\n",
  92. __func__, atu, iop13xx_atux_mem_size,
  93. iop13xx_atux_mem_base);
  94. break;
  95. case 1:
  96. iop13xx_atue_mem_size =
  97. (end - IOP13XX_PCIE_LOWER_MEM_RA) + 1;
  98. /* 16MB align the request */
  99. if (iop13xx_atue_mem_size & (SZ_16M - 1)) {
  100. iop13xx_atue_mem_size &= ~(SZ_16M - 1);
  101. iop13xx_atue_mem_size += SZ_16M;
  102. }
  103. if (end) {
  104. iop13xx_atue_mem_base =
  105. (u32) __arm_ioremap_pfn(
  106. __phys_to_pfn(IOP13XX_PCIE_LOWER_MEM_PA)
  107. , 0, iop13xx_atue_mem_size, MT_DEVICE);
  108. if (!iop13xx_atue_mem_base) {
  109. printk("%s: atue allocation "
  110. "failed\n", __func__);
  111. BUG();
  112. }
  113. } else
  114. iop13xx_atue_mem_size = 0;
  115. PRINTK("%s: atu: %d bus_size: %d mem_base: %x\n",
  116. __func__, atu, iop13xx_atue_mem_size,
  117. iop13xx_atue_mem_base);
  118. break;
  119. }
  120. printk("%s: Initialized (%uM @ resource/virtual: %08lx/%08x)\n",
  121. atu ? "ATUE" : "ATUX",
  122. (atu ? iop13xx_atue_mem_size : iop13xx_atux_mem_size) /
  123. SZ_1M,
  124. atu ? IOP13XX_PCIE_LOWER_MEM_RA :
  125. IOP13XX_PCIX_LOWER_MEM_RA,
  126. atu ? iop13xx_atue_mem_base :
  127. iop13xx_atux_mem_base);
  128. end = 0;
  129. }
  130. }
  131. }
  132. static int iop13xx_atu_function(int atu)
  133. {
  134. int func = 0;
  135. /* the function number depends on the value of the
  136. * IOP13XX_INTERFACE_SEL_PCIX reset strap
  137. * see C-Spec section 3.17
  138. */
  139. switch(atu) {
  140. case IOP13XX_INIT_ATU_ATUX:
  141. if (__raw_readl(IOP13XX_ESSR0) & IOP13XX_INTERFACE_SEL_PCIX)
  142. func = 5;
  143. else
  144. func = 0;
  145. break;
  146. case IOP13XX_INIT_ATU_ATUE:
  147. if (__raw_readl(IOP13XX_ESSR0) & IOP13XX_INTERFACE_SEL_PCIX)
  148. func = 0;
  149. else
  150. func = 5;
  151. break;
  152. default:
  153. BUG();
  154. }
  155. return func;
  156. }
  157. /* iop13xx_atux_cfg_address - format a configuration address for atux
  158. * @bus: Target bus to access
  159. * @devfn: Combined device number and function number
  160. * @where: Desired register's address offset
  161. *
  162. * Convert the parameters to a configuration address formatted
  163. * according the PCI-X 2.0 specification
  164. */
  165. static u32 iop13xx_atux_cfg_address(struct pci_bus *bus, int devfn, int where)
  166. {
  167. struct pci_sys_data *sys = bus->sysdata;
  168. u32 addr;
  169. if (sys->busnr == bus->number)
  170. addr = 1 << (PCI_SLOT(devfn) + 16) | (PCI_SLOT(devfn) << 11);
  171. else
  172. addr = bus->number << 16 | PCI_SLOT(devfn) << 11 | 1;
  173. addr |= PCI_FUNC(devfn) << 8 | ((where & 0xff) & ~3);
  174. addr |= ((where & 0xf00) >> 8) << 24; /* upper register number */
  175. return addr;
  176. }
  177. /* iop13xx_atue_cfg_address - format a configuration address for atue
  178. * @bus: Target bus to access
  179. * @devfn: Combined device number and function number
  180. * @where: Desired register's address offset
  181. *
  182. * Convert the parameters to an address usable by the ATUE_OCCAR
  183. */
  184. static u32 iop13xx_atue_cfg_address(struct pci_bus *bus, int devfn, int where)
  185. {
  186. struct pci_sys_data *sys = bus->sysdata;
  187. u32 addr;
  188. PRINTK("iop13xx_atue_cfg_address: bus: %d dev: %d func: %d",
  189. bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
  190. addr = ((u32) bus->number) << IOP13XX_ATUE_OCCAR_BUS_NUM |
  191. ((u32) PCI_SLOT(devfn)) << IOP13XX_ATUE_OCCAR_DEV_NUM |
  192. ((u32) PCI_FUNC(devfn)) << IOP13XX_ATUE_OCCAR_FUNC_NUM |
  193. (where & ~0x3);
  194. if (sys->busnr != bus->number)
  195. addr |= 1; /* type 1 access */
  196. return addr;
  197. }
  198. /* This routine checks the status of the last configuration cycle. If an error
  199. * was detected it returns >0, else it returns a 0. The errors being checked
  200. * are parity, master abort, target abort (master and target). These types of
  201. * errors occur during a config cycle where there is no device, like during
  202. * the discovery stage.
  203. */
  204. static int iop13xx_atux_pci_status(int clear)
  205. {
  206. unsigned int status;
  207. int err = 0;
  208. /*
  209. * Check the status registers.
  210. */
  211. status = __raw_readw(IOP13XX_ATUX_ATUSR);
  212. if (status & IOP_PCI_STATUS_ERROR)
  213. {
  214. PRINTK("\t\t\tPCI error: ATUSR %#08x", status);
  215. if(clear)
  216. __raw_writew(status & IOP_PCI_STATUS_ERROR,
  217. IOP13XX_ATUX_ATUSR);
  218. err = 1;
  219. }
  220. status = __raw_readl(IOP13XX_ATUX_ATUISR);
  221. if (status & IOP13XX_ATUX_ATUISR_ERROR)
  222. {
  223. PRINTK("\t\t\tPCI error interrupt: ATUISR %#08x", status);
  224. if(clear)
  225. __raw_writel(status & IOP13XX_ATUX_ATUISR_ERROR,
  226. IOP13XX_ATUX_ATUISR);
  227. err = 1;
  228. }
  229. return err;
  230. }
  231. /* Simply write the address register and read the configuration
  232. * data. Note that the data dependency on %0 encourages an abort
  233. * to be detected before we return.
  234. */
  235. static u32 iop13xx_atux_read(unsigned long addr)
  236. {
  237. u32 val;
  238. __asm__ __volatile__(
  239. "str %1, [%2]\n\t"
  240. "ldr %0, [%3]\n\t"
  241. "mov %0, %0\n\t"
  242. : "=r" (val)
  243. : "r" (addr), "r" (IOP13XX_ATUX_OCCAR), "r" (IOP13XX_ATUX_OCCDR));
  244. return val;
  245. }
  246. /* The read routines must check the error status of the last configuration
  247. * cycle. If there was an error, the routine returns all hex f's.
  248. */
  249. static int
  250. iop13xx_atux_read_config(struct pci_bus *bus, unsigned int devfn, int where,
  251. int size, u32 *value)
  252. {
  253. unsigned long addr = iop13xx_atux_cfg_address(bus, devfn, where);
  254. u32 val = iop13xx_atux_read(addr) >> ((where & 3) * 8);
  255. if (iop13xx_atux_pci_status(1) || is_atux_occdr_error()) {
  256. __raw_writel(__raw_readl(IOP13XX_XBG_BECSR) & 3,
  257. IOP13XX_XBG_BECSR);
  258. val = 0xffffffff;
  259. }
  260. *value = val;
  261. return PCIBIOS_SUCCESSFUL;
  262. }
  263. static int
  264. iop13xx_atux_write_config(struct pci_bus *bus, unsigned int devfn, int where,
  265. int size, u32 value)
  266. {
  267. unsigned long addr = iop13xx_atux_cfg_address(bus, devfn, where);
  268. u32 val;
  269. if (size != 4) {
  270. val = iop13xx_atux_read(addr);
  271. if (!iop13xx_atux_pci_status(1) == 0)
  272. return PCIBIOS_SUCCESSFUL;
  273. where = (where & 3) * 8;
  274. if (size == 1)
  275. val &= ~(0xff << where);
  276. else
  277. val &= ~(0xffff << where);
  278. __raw_writel(val | value << where, IOP13XX_ATUX_OCCDR);
  279. } else {
  280. __raw_writel(addr, IOP13XX_ATUX_OCCAR);
  281. __raw_writel(value, IOP13XX_ATUX_OCCDR);
  282. }
  283. return PCIBIOS_SUCCESSFUL;
  284. }
  285. static struct pci_ops iop13xx_atux_ops = {
  286. .read = iop13xx_atux_read_config,
  287. .write = iop13xx_atux_write_config,
  288. };
  289. /* This routine checks the status of the last configuration cycle. If an error
  290. * was detected it returns >0, else it returns a 0. The errors being checked
  291. * are parity, master abort, target abort (master and target). These types of
  292. * errors occur during a config cycle where there is no device, like during
  293. * the discovery stage.
  294. */
  295. static int iop13xx_atue_pci_status(int clear)
  296. {
  297. unsigned int status;
  298. int err = 0;
  299. /*
  300. * Check the status registers.
  301. */
  302. /* standard pci status register */
  303. status = __raw_readw(IOP13XX_ATUE_ATUSR);
  304. if (status & IOP_PCI_STATUS_ERROR) {
  305. PRINTK("\t\t\tPCI error: ATUSR %#08x", status);
  306. if(clear)
  307. __raw_writew(status & IOP_PCI_STATUS_ERROR,
  308. IOP13XX_ATUE_ATUSR);
  309. err++;
  310. }
  311. /* check the normal status bits in the ATUISR */
  312. status = __raw_readl(IOP13XX_ATUE_ATUISR);
  313. if (status & IOP13XX_ATUE_ATUISR_ERROR) {
  314. PRINTK("\t\t\tPCI error: ATUISR %#08x", status);
  315. if (clear)
  316. __raw_writew(status & IOP13XX_ATUE_ATUISR_ERROR,
  317. IOP13XX_ATUE_ATUISR);
  318. err++;
  319. /* check the PCI-E status if the ATUISR reports an interface error */
  320. if (status & IOP13XX_ATUE_STAT_PCI_IFACE_ERR) {
  321. /* get the unmasked errors */
  322. status = __raw_readl(IOP13XX_ATUE_PIE_STS) &
  323. ~(__raw_readl(IOP13XX_ATUE_PIE_MSK));
  324. if (status) {
  325. PRINTK("\t\t\tPCI-E error: ATUE_PIE_STS %#08x",
  326. __raw_readl(IOP13XX_ATUE_PIE_STS));
  327. err++;
  328. } else {
  329. PRINTK("\t\t\tPCI-E error: ATUE_PIE_STS %#08x",
  330. __raw_readl(IOP13XX_ATUE_PIE_STS));
  331. PRINTK("\t\t\tPCI-E error: ATUE_PIE_MSK %#08x",
  332. __raw_readl(IOP13XX_ATUE_PIE_MSK));
  333. BUG();
  334. }
  335. if(clear)
  336. __raw_writel(status, IOP13XX_ATUE_PIE_STS);
  337. }
  338. }
  339. return err;
  340. }
  341. static int
  342. iop13xx_pcie_map_irq(struct pci_dev *dev, u8 idsel, u8 pin)
  343. {
  344. WARN_ON(idsel != 0);
  345. switch (pin) {
  346. case 1: return ATUE_INTA;
  347. case 2: return ATUE_INTB;
  348. case 3: return ATUE_INTC;
  349. case 4: return ATUE_INTD;
  350. default: return -1;
  351. }
  352. }
  353. static u32 iop13xx_atue_read(unsigned long addr)
  354. {
  355. u32 val;
  356. __raw_writel(addr, IOP13XX_ATUE_OCCAR);
  357. val = __raw_readl(IOP13XX_ATUE_OCCDR);
  358. rmb();
  359. return val;
  360. }
  361. /* The read routines must check the error status of the last configuration
  362. * cycle. If there was an error, the routine returns all hex f's.
  363. */
  364. static int
  365. iop13xx_atue_read_config(struct pci_bus *bus, unsigned int devfn, int where,
  366. int size, u32 *value)
  367. {
  368. u32 val;
  369. unsigned long addr = iop13xx_atue_cfg_address(bus, devfn, where);
  370. /* Hide device numbers > 0 on the local PCI-E bus (Type 0 access) */
  371. if (!PCI_SLOT(devfn) || (addr & 1)) {
  372. val = iop13xx_atue_read(addr) >> ((where & 3) * 8);
  373. if( iop13xx_atue_pci_status(1) || is_atue_occdr_error() ) {
  374. __raw_writel(__raw_readl(IOP13XX_XBG_BECSR) & 3,
  375. IOP13XX_XBG_BECSR);
  376. val = 0xffffffff;
  377. }
  378. PRINTK("addr=%#0lx, val=%#010x", addr, val);
  379. } else
  380. val = 0xffffffff;
  381. *value = val;
  382. return PCIBIOS_SUCCESSFUL;
  383. }
  384. static int
  385. iop13xx_atue_write_config(struct pci_bus *bus, unsigned int devfn, int where,
  386. int size, u32 value)
  387. {
  388. unsigned long addr = iop13xx_atue_cfg_address(bus, devfn, where);
  389. u32 val;
  390. if (size != 4) {
  391. val = iop13xx_atue_read(addr);
  392. if (!iop13xx_atue_pci_status(1) == 0)
  393. return PCIBIOS_SUCCESSFUL;
  394. where = (where & 3) * 8;
  395. if (size == 1)
  396. val &= ~(0xff << where);
  397. else
  398. val &= ~(0xffff << where);
  399. __raw_writel(val | value << where, IOP13XX_ATUE_OCCDR);
  400. } else {
  401. __raw_writel(addr, IOP13XX_ATUE_OCCAR);
  402. __raw_writel(value, IOP13XX_ATUE_OCCDR);
  403. }
  404. return PCIBIOS_SUCCESSFUL;
  405. }
  406. static struct pci_ops iop13xx_atue_ops = {
  407. .read = iop13xx_atue_read_config,
  408. .write = iop13xx_atue_write_config,
  409. };
  410. /* When a PCI device does not exist during config cycles, the XScale gets a
  411. * bus error instead of returning 0xffffffff. We can't rely on the ATU status
  412. * bits to tell us that it was indeed a configuration cycle that caused this
  413. * error especially in the case when the ATUE link is down. Instead we rely
  414. * on data from the south XSI bridge to validate the abort
  415. */
  416. int
  417. iop13xx_pci_abort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  418. {
  419. PRINTK("Data abort: address = 0x%08lx "
  420. "fsr = 0x%03x PC = 0x%08lx LR = 0x%08lx",
  421. addr, fsr, regs->ARM_pc, regs->ARM_lr);
  422. PRINTK("IOP13XX_XBG_BECSR: %#10x", __raw_readl(IOP13XX_XBG_BECSR));
  423. PRINTK("IOP13XX_XBG_BERAR: %#10x", __raw_readl(IOP13XX_XBG_BERAR));
  424. PRINTK("IOP13XX_XBG_BERUAR: %#10x", __raw_readl(IOP13XX_XBG_BERUAR));
  425. /* If it was an imprecise abort, then we need to correct the
  426. * return address to be _after_ the instruction.
  427. */
  428. if (fsr & (1 << 10))
  429. regs->ARM_pc += 4;
  430. if (is_atue_occdr_error() || is_atux_occdr_error())
  431. return 0;
  432. else
  433. return 1;
  434. }
  435. /* Scan an IOP13XX PCI bus. nr selects which ATU we use.
  436. */
  437. struct pci_bus *iop13xx_scan_bus(int nr, struct pci_sys_data *sys)
  438. {
  439. int which_atu;
  440. struct pci_bus *bus = NULL;
  441. switch (init_atu) {
  442. case IOP13XX_INIT_ATU_ATUX:
  443. which_atu = nr ? 0 : IOP13XX_INIT_ATU_ATUX;
  444. break;
  445. case IOP13XX_INIT_ATU_ATUE:
  446. which_atu = nr ? 0 : IOP13XX_INIT_ATU_ATUE;
  447. break;
  448. case (IOP13XX_INIT_ATU_ATUX | IOP13XX_INIT_ATU_ATUE):
  449. which_atu = nr ? IOP13XX_INIT_ATU_ATUE : IOP13XX_INIT_ATU_ATUX;
  450. break;
  451. default:
  452. which_atu = 0;
  453. }
  454. if (!which_atu) {
  455. BUG();
  456. return NULL;
  457. }
  458. switch (which_atu) {
  459. case IOP13XX_INIT_ATU_ATUX:
  460. if (time_after_eq(jiffies + msecs_to_jiffies(1000),
  461. atux_trhfa_timeout)) /* ensure not wrap */
  462. while(time_before(jiffies, atux_trhfa_timeout))
  463. udelay(100);
  464. bus = pci_bus_atux = pci_scan_bus(sys->busnr,
  465. &iop13xx_atux_ops,
  466. sys);
  467. break;
  468. case IOP13XX_INIT_ATU_ATUE:
  469. bus = pci_bus_atue = pci_scan_bus(sys->busnr,
  470. &iop13xx_atue_ops,
  471. sys);
  472. break;
  473. }
  474. return bus;
  475. }
  476. /* This function is called from iop13xx_pci_init() after assigning valid
  477. * values to iop13xx_atue_pmmr_offset. This is the location for common
  478. * setup of ATUE for all IOP13XX implementations.
  479. */
  480. void __init iop13xx_atue_setup(void)
  481. {
  482. int func = iop13xx_atu_function(IOP13XX_INIT_ATU_ATUE);
  483. u32 reg_val;
  484. #ifdef CONFIG_PCI_MSI
  485. /* BAR 0 (inbound msi window) */
  486. __raw_writel(IOP13XX_MU_BASE_PHYS, IOP13XX_MU_MUBAR);
  487. __raw_writel(~(IOP13XX_MU_WINDOW_SIZE - 1), IOP13XX_ATUE_IALR0);
  488. __raw_writel(IOP13XX_MU_BASE_PHYS, IOP13XX_ATUE_IATVR0);
  489. __raw_writel(IOP13XX_MU_BASE_PCI, IOP13XX_ATUE_IABAR0);
  490. #endif
  491. /* BAR 1 (1:1 mapping with Physical RAM) */
  492. /* Set limit and enable */
  493. __raw_writel(~(IOP13XX_MAX_RAM_SIZE - PHYS_OFFSET - 1) & ~0x1,
  494. IOP13XX_ATUE_IALR1);
  495. __raw_writel(0x0, IOP13XX_ATUE_IAUBAR1);
  496. /* Set base at the top of the reserved address space */
  497. __raw_writel(PHYS_OFFSET | PCI_BASE_ADDRESS_MEM_TYPE_64 |
  498. PCI_BASE_ADDRESS_MEM_PREFETCH, IOP13XX_ATUE_IABAR1);
  499. /* 1:1 mapping with physical ram
  500. * (leave big endian byte swap disabled)
  501. */
  502. __raw_writel(0x0, IOP13XX_ATUE_IAUTVR1);
  503. __raw_writel(PHYS_OFFSET, IOP13XX_ATUE_IATVR1);
  504. /* Outbound window 1 (PCIX/PCIE memory window) */
  505. /* 32 bit Address Space */
  506. __raw_writel(0x0, IOP13XX_ATUE_OUMWTVR1);
  507. /* PA[35:32] */
  508. __raw_writel(IOP13XX_ATUE_OUMBAR_ENABLE |
  509. (IOP13XX_PCIE_MEM_PHYS_OFFSET >> 32),
  510. IOP13XX_ATUE_OUMBAR1);
  511. /* Setup the I/O Bar
  512. * A[35-16] in 31-12
  513. */
  514. __raw_writel(((IOP13XX_PCIE_LOWER_IO_PA >> 0x4) & 0xfffff000),
  515. IOP13XX_ATUE_OIOBAR);
  516. __raw_writel(IOP13XX_PCIE_LOWER_IO_BA, IOP13XX_ATUE_OIOWTVR);
  517. /* clear startup errors */
  518. iop13xx_atue_pci_status(1);
  519. /* OIOBAR function number
  520. */
  521. reg_val = __raw_readl(IOP13XX_ATUE_OIOBAR);
  522. reg_val &= ~0x7;
  523. reg_val |= func;
  524. __raw_writel(reg_val, IOP13XX_ATUE_OIOBAR);
  525. /* OUMBAR function numbers
  526. */
  527. reg_val = __raw_readl(IOP13XX_ATUE_OUMBAR0);
  528. reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
  529. IOP13XX_ATU_OUMBAR_FUNC_NUM);
  530. reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
  531. __raw_writel(reg_val, IOP13XX_ATUE_OUMBAR0);
  532. reg_val = __raw_readl(IOP13XX_ATUE_OUMBAR1);
  533. reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
  534. IOP13XX_ATU_OUMBAR_FUNC_NUM);
  535. reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
  536. __raw_writel(reg_val, IOP13XX_ATUE_OUMBAR1);
  537. reg_val = __raw_readl(IOP13XX_ATUE_OUMBAR2);
  538. reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
  539. IOP13XX_ATU_OUMBAR_FUNC_NUM);
  540. reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
  541. __raw_writel(reg_val, IOP13XX_ATUE_OUMBAR2);
  542. reg_val = __raw_readl(IOP13XX_ATUE_OUMBAR3);
  543. reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
  544. IOP13XX_ATU_OUMBAR_FUNC_NUM);
  545. reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
  546. __raw_writel(reg_val, IOP13XX_ATUE_OUMBAR3);
  547. /* Enable inbound and outbound cycles
  548. */
  549. reg_val = __raw_readw(IOP13XX_ATUE_ATUCMD);
  550. reg_val |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
  551. PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  552. __raw_writew(reg_val, IOP13XX_ATUE_ATUCMD);
  553. reg_val = __raw_readl(IOP13XX_ATUE_ATUCR);
  554. reg_val |= IOP13XX_ATUE_ATUCR_OUT_EN |
  555. IOP13XX_ATUE_ATUCR_IVM;
  556. __raw_writel(reg_val, IOP13XX_ATUE_ATUCR);
  557. }
  558. void __init iop13xx_atue_disable(void)
  559. {
  560. u32 reg_val;
  561. __raw_writew(0x0, IOP13XX_ATUE_ATUCMD);
  562. __raw_writel(IOP13XX_ATUE_ATUCR_IVM, IOP13XX_ATUE_ATUCR);
  563. /* wait for cycles to quiesce */
  564. while (__raw_readl(IOP13XX_ATUE_PCSR) & (IOP13XX_ATUE_PCSR_OUT_Q_BUSY |
  565. IOP13XX_ATUE_PCSR_IN_Q_BUSY |
  566. IOP13XX_ATUE_PCSR_LLRB_BUSY))
  567. cpu_relax();
  568. /* BAR 0 ( Disabled ) */
  569. __raw_writel(0x0, IOP13XX_ATUE_IAUBAR0);
  570. __raw_writel(0x0, IOP13XX_ATUE_IABAR0);
  571. __raw_writel(0x0, IOP13XX_ATUE_IAUTVR0);
  572. __raw_writel(0x0, IOP13XX_ATUE_IATVR0);
  573. __raw_writel(0x0, IOP13XX_ATUE_IALR0);
  574. reg_val = __raw_readl(IOP13XX_ATUE_OUMBAR0);
  575. reg_val &= ~IOP13XX_ATUE_OUMBAR_ENABLE;
  576. __raw_writel(reg_val, IOP13XX_ATUE_OUMBAR0);
  577. /* BAR 1 ( Disabled ) */
  578. __raw_writel(0x0, IOP13XX_ATUE_IAUBAR1);
  579. __raw_writel(0x0, IOP13XX_ATUE_IABAR1);
  580. __raw_writel(0x0, IOP13XX_ATUE_IAUTVR1);
  581. __raw_writel(0x0, IOP13XX_ATUE_IATVR1);
  582. __raw_writel(0x0, IOP13XX_ATUE_IALR1);
  583. reg_val = __raw_readl(IOP13XX_ATUE_OUMBAR1);
  584. reg_val &= ~IOP13XX_ATUE_OUMBAR_ENABLE;
  585. __raw_writel(reg_val, IOP13XX_ATUE_OUMBAR1);
  586. /* BAR 2 ( Disabled ) */
  587. __raw_writel(0x0, IOP13XX_ATUE_IAUBAR2);
  588. __raw_writel(0x0, IOP13XX_ATUE_IABAR2);
  589. __raw_writel(0x0, IOP13XX_ATUE_IAUTVR2);
  590. __raw_writel(0x0, IOP13XX_ATUE_IATVR2);
  591. __raw_writel(0x0, IOP13XX_ATUE_IALR2);
  592. reg_val = __raw_readl(IOP13XX_ATUE_OUMBAR2);
  593. reg_val &= ~IOP13XX_ATUE_OUMBAR_ENABLE;
  594. __raw_writel(reg_val, IOP13XX_ATUE_OUMBAR2);
  595. /* BAR 3 ( Disabled ) */
  596. reg_val = __raw_readl(IOP13XX_ATUE_OUMBAR3);
  597. reg_val &= ~IOP13XX_ATUE_OUMBAR_ENABLE;
  598. __raw_writel(reg_val, IOP13XX_ATUE_OUMBAR3);
  599. /* Setup the I/O Bar
  600. * A[35-16] in 31-12
  601. */
  602. __raw_writel((IOP13XX_PCIE_LOWER_IO_PA >> 0x4) & 0xfffff000,
  603. IOP13XX_ATUE_OIOBAR);
  604. __raw_writel(IOP13XX_PCIE_LOWER_IO_BA, IOP13XX_ATUE_OIOWTVR);
  605. }
  606. /* This function is called from iop13xx_pci_init() after assigning valid
  607. * values to iop13xx_atux_pmmr_offset. This is the location for common
  608. * setup of ATUX for all IOP13XX implementations.
  609. */
  610. void __init iop13xx_atux_setup(void)
  611. {
  612. u32 reg_val;
  613. int func = iop13xx_atu_function(IOP13XX_INIT_ATU_ATUX);
  614. /* Take PCI-X bus out of reset if bootloader hasn't already.
  615. * According to spec, we should wait for 2^25 PCI clocks to meet
  616. * the PCI timing parameter Trhfa (RST# high to first access).
  617. * This is rarely necessary and often ignored.
  618. */
  619. reg_val = __raw_readl(IOP13XX_ATUX_PCSR);
  620. if (reg_val & IOP13XX_ATUX_PCSR_P_RSTOUT) {
  621. int msec = (reg_val >> IOP13XX_ATUX_PCSR_FREQ_OFFSET) & 0x7;
  622. msec = 1000 / (8-msec); /* bits 100=133MHz, 111=>33MHz */
  623. __raw_writel(reg_val & ~IOP13XX_ATUX_PCSR_P_RSTOUT,
  624. IOP13XX_ATUX_PCSR);
  625. atux_trhfa_timeout = jiffies + msecs_to_jiffies(msec);
  626. }
  627. else
  628. atux_trhfa_timeout = jiffies;
  629. #ifdef CONFIG_PCI_MSI
  630. /* BAR 0 (inbound msi window) */
  631. __raw_writel(IOP13XX_MU_BASE_PHYS, IOP13XX_MU_MUBAR);
  632. __raw_writel(~(IOP13XX_MU_WINDOW_SIZE - 1), IOP13XX_ATUX_IALR0);
  633. __raw_writel(IOP13XX_MU_BASE_PHYS, IOP13XX_ATUX_IATVR0);
  634. __raw_writel(IOP13XX_MU_BASE_PCI, IOP13XX_ATUX_IABAR0);
  635. #endif
  636. /* BAR 1 (1:1 mapping with Physical RAM) */
  637. /* Set limit and enable */
  638. __raw_writel(~(IOP13XX_MAX_RAM_SIZE - PHYS_OFFSET - 1) & ~0x1,
  639. IOP13XX_ATUX_IALR1);
  640. __raw_writel(0x0, IOP13XX_ATUX_IAUBAR1);
  641. /* Set base at the top of the reserved address space */
  642. __raw_writel(PHYS_OFFSET | PCI_BASE_ADDRESS_MEM_TYPE_64 |
  643. PCI_BASE_ADDRESS_MEM_PREFETCH, IOP13XX_ATUX_IABAR1);
  644. /* 1:1 mapping with physical ram
  645. * (leave big endian byte swap disabled)
  646. */
  647. __raw_writel(0x0, IOP13XX_ATUX_IAUTVR1);
  648. __raw_writel(PHYS_OFFSET, IOP13XX_ATUX_IATVR1);
  649. /* Outbound window 1 (PCIX/PCIE memory window) */
  650. /* 32 bit Address Space */
  651. __raw_writel(0x0, IOP13XX_ATUX_OUMWTVR1);
  652. /* PA[35:32] */
  653. __raw_writel(IOP13XX_ATUX_OUMBAR_ENABLE |
  654. IOP13XX_PCIX_MEM_PHYS_OFFSET >> 32,
  655. IOP13XX_ATUX_OUMBAR1);
  656. /* Setup the I/O Bar
  657. * A[35-16] in 31-12
  658. */
  659. __raw_writel((IOP13XX_PCIX_LOWER_IO_PA >> 0x4) & 0xfffff000,
  660. IOP13XX_ATUX_OIOBAR);
  661. __raw_writel(IOP13XX_PCIX_LOWER_IO_BA, IOP13XX_ATUX_OIOWTVR);
  662. /* clear startup errors */
  663. iop13xx_atux_pci_status(1);
  664. /* OIOBAR function number
  665. */
  666. reg_val = __raw_readl(IOP13XX_ATUX_OIOBAR);
  667. reg_val &= ~0x7;
  668. reg_val |= func;
  669. __raw_writel(reg_val, IOP13XX_ATUX_OIOBAR);
  670. /* OUMBAR function numbers
  671. */
  672. reg_val = __raw_readl(IOP13XX_ATUX_OUMBAR0);
  673. reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
  674. IOP13XX_ATU_OUMBAR_FUNC_NUM);
  675. reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
  676. __raw_writel(reg_val, IOP13XX_ATUX_OUMBAR0);
  677. reg_val = __raw_readl(IOP13XX_ATUX_OUMBAR1);
  678. reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
  679. IOP13XX_ATU_OUMBAR_FUNC_NUM);
  680. reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
  681. __raw_writel(reg_val, IOP13XX_ATUX_OUMBAR1);
  682. reg_val = __raw_readl(IOP13XX_ATUX_OUMBAR2);
  683. reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
  684. IOP13XX_ATU_OUMBAR_FUNC_NUM);
  685. reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
  686. __raw_writel(reg_val, IOP13XX_ATUX_OUMBAR2);
  687. reg_val = __raw_readl(IOP13XX_ATUX_OUMBAR3);
  688. reg_val &= ~(IOP13XX_ATU_OUMBAR_FUNC_NUM_MASK <<
  689. IOP13XX_ATU_OUMBAR_FUNC_NUM);
  690. reg_val |= func << IOP13XX_ATU_OUMBAR_FUNC_NUM;
  691. __raw_writel(reg_val, IOP13XX_ATUX_OUMBAR3);
  692. /* Enable inbound and outbound cycles
  693. */
  694. reg_val = __raw_readw(IOP13XX_ATUX_ATUCMD);
  695. reg_val |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
  696. PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  697. __raw_writew(reg_val, IOP13XX_ATUX_ATUCMD);
  698. reg_val = __raw_readl(IOP13XX_ATUX_ATUCR);
  699. reg_val |= IOP13XX_ATUX_ATUCR_OUT_EN;
  700. __raw_writel(reg_val, IOP13XX_ATUX_ATUCR);
  701. }
  702. void __init iop13xx_atux_disable(void)
  703. {
  704. u32 reg_val;
  705. __raw_writew(0x0, IOP13XX_ATUX_ATUCMD);
  706. __raw_writel(0x0, IOP13XX_ATUX_ATUCR);
  707. /* wait for cycles to quiesce */
  708. while (__raw_readl(IOP13XX_ATUX_PCSR) & (IOP13XX_ATUX_PCSR_OUT_Q_BUSY |
  709. IOP13XX_ATUX_PCSR_IN_Q_BUSY))
  710. cpu_relax();
  711. /* BAR 0 ( Disabled ) */
  712. __raw_writel(0x0, IOP13XX_ATUX_IAUBAR0);
  713. __raw_writel(0x0, IOP13XX_ATUX_IABAR0);
  714. __raw_writel(0x0, IOP13XX_ATUX_IAUTVR0);
  715. __raw_writel(0x0, IOP13XX_ATUX_IATVR0);
  716. __raw_writel(0x0, IOP13XX_ATUX_IALR0);
  717. reg_val = __raw_readl(IOP13XX_ATUX_OUMBAR0);
  718. reg_val &= ~IOP13XX_ATUX_OUMBAR_ENABLE;
  719. __raw_writel(reg_val, IOP13XX_ATUX_OUMBAR0);
  720. /* BAR 1 ( Disabled ) */
  721. __raw_writel(0x0, IOP13XX_ATUX_IAUBAR1);
  722. __raw_writel(0x0, IOP13XX_ATUX_IABAR1);
  723. __raw_writel(0x0, IOP13XX_ATUX_IAUTVR1);
  724. __raw_writel(0x0, IOP13XX_ATUX_IATVR1);
  725. __raw_writel(0x0, IOP13XX_ATUX_IALR1);
  726. reg_val = __raw_readl(IOP13XX_ATUX_OUMBAR1);
  727. reg_val &= ~IOP13XX_ATUX_OUMBAR_ENABLE;
  728. __raw_writel(reg_val, IOP13XX_ATUX_OUMBAR1);
  729. /* BAR 2 ( Disabled ) */
  730. __raw_writel(0x0, IOP13XX_ATUX_IAUBAR2);
  731. __raw_writel(0x0, IOP13XX_ATUX_IABAR2);
  732. __raw_writel(0x0, IOP13XX_ATUX_IAUTVR2);
  733. __raw_writel(0x0, IOP13XX_ATUX_IATVR2);
  734. __raw_writel(0x0, IOP13XX_ATUX_IALR2);
  735. reg_val = __raw_readl(IOP13XX_ATUX_OUMBAR2);
  736. reg_val &= ~IOP13XX_ATUX_OUMBAR_ENABLE;
  737. __raw_writel(reg_val, IOP13XX_ATUX_OUMBAR2);
  738. /* BAR 3 ( Disabled ) */
  739. __raw_writel(0x0, IOP13XX_ATUX_IAUBAR3);
  740. __raw_writel(0x0, IOP13XX_ATUX_IABAR3);
  741. __raw_writel(0x0, IOP13XX_ATUX_IAUTVR3);
  742. __raw_writel(0x0, IOP13XX_ATUX_IATVR3);
  743. __raw_writel(0x0, IOP13XX_ATUX_IALR3);
  744. reg_val = __raw_readl(IOP13XX_ATUX_OUMBAR3);
  745. reg_val &= ~IOP13XX_ATUX_OUMBAR_ENABLE;
  746. __raw_writel(reg_val, IOP13XX_ATUX_OUMBAR3);
  747. /* Setup the I/O Bar
  748. * A[35-16] in 31-12
  749. */
  750. __raw_writel((IOP13XX_PCIX_LOWER_IO_PA >> 0x4) & 0xfffff000,
  751. IOP13XX_ATUX_OIOBAR);
  752. __raw_writel(IOP13XX_PCIX_LOWER_IO_BA, IOP13XX_ATUX_OIOWTVR);
  753. }
  754. void __init iop13xx_set_atu_mmr_bases(void)
  755. {
  756. /* Based on ESSR0, determine the ATU X/E offsets */
  757. switch(__raw_readl(IOP13XX_ESSR0) &
  758. (IOP13XX_CONTROLLER_ONLY | IOP13XX_INTERFACE_SEL_PCIX)) {
  759. /* both asserted */
  760. case 0:
  761. iop13xx_atux_pmmr_offset = IOP13XX_ATU1_PMMR_OFFSET;
  762. iop13xx_atue_pmmr_offset = IOP13XX_ATU2_PMMR_OFFSET;
  763. break;
  764. /* IOP13XX_CONTROLLER_ONLY = deasserted
  765. * IOP13XX_INTERFACE_SEL_PCIX = asserted
  766. */
  767. case IOP13XX_CONTROLLER_ONLY:
  768. iop13xx_atux_pmmr_offset = IOP13XX_ATU0_PMMR_OFFSET;
  769. iop13xx_atue_pmmr_offset = IOP13XX_ATU2_PMMR_OFFSET;
  770. break;
  771. /* IOP13XX_CONTROLLER_ONLY = asserted
  772. * IOP13XX_INTERFACE_SEL_PCIX = deasserted
  773. */
  774. case IOP13XX_INTERFACE_SEL_PCIX:
  775. iop13xx_atux_pmmr_offset = IOP13XX_ATU1_PMMR_OFFSET;
  776. iop13xx_atue_pmmr_offset = IOP13XX_ATU2_PMMR_OFFSET;
  777. break;
  778. /* both deasserted */
  779. case IOP13XX_CONTROLLER_ONLY | IOP13XX_INTERFACE_SEL_PCIX:
  780. iop13xx_atux_pmmr_offset = IOP13XX_ATU2_PMMR_OFFSET;
  781. iop13xx_atue_pmmr_offset = IOP13XX_ATU0_PMMR_OFFSET;
  782. break;
  783. default:
  784. BUG();
  785. }
  786. }
  787. void __init iop13xx_atu_select(struct hw_pci *plat_pci)
  788. {
  789. int i;
  790. /* set system defaults
  791. * note: if "iop13xx_init_atu=" is specified this autodetect
  792. * sequence will be bypassed
  793. */
  794. if (init_atu == IOP13XX_INIT_ATU_DEFAULT) {
  795. /* check for single/dual interface */
  796. if (__raw_readl(IOP13XX_ESSR0) & IOP13XX_INTERFACE_SEL_PCIX) {
  797. /* ATUE must be present check the device id
  798. * to see if ATUX is present.
  799. */
  800. init_atu |= IOP13XX_INIT_ATU_ATUE;
  801. switch (__raw_readw(IOP13XX_ATUE_DID) & 0xf0) {
  802. case 0x70:
  803. case 0x80:
  804. case 0xc0:
  805. init_atu |= IOP13XX_INIT_ATU_ATUX;
  806. break;
  807. }
  808. } else {
  809. /* ATUX must be present check the device id
  810. * to see if ATUE is present.
  811. */
  812. init_atu |= IOP13XX_INIT_ATU_ATUX;
  813. switch (__raw_readw(IOP13XX_ATUX_DID) & 0xf0) {
  814. case 0x70:
  815. case 0x80:
  816. case 0xc0:
  817. init_atu |= IOP13XX_INIT_ATU_ATUE;
  818. break;
  819. }
  820. }
  821. /* check central resource and root complex capability */
  822. if (init_atu & IOP13XX_INIT_ATU_ATUX)
  823. if (!(__raw_readl(IOP13XX_ATUX_PCSR) &
  824. IOP13XX_ATUX_PCSR_CENTRAL_RES))
  825. init_atu &= ~IOP13XX_INIT_ATU_ATUX;
  826. if (init_atu & IOP13XX_INIT_ATU_ATUE)
  827. if (__raw_readl(IOP13XX_ATUE_PCSR) &
  828. IOP13XX_ATUE_PCSR_END_POINT)
  829. init_atu &= ~IOP13XX_INIT_ATU_ATUE;
  830. }
  831. for (i = 0; i < 2; i++) {
  832. if((init_atu & (1 << i)) == (1 << i))
  833. plat_pci->nr_controllers++;
  834. }
  835. }
  836. void __init iop13xx_pci_init(void)
  837. {
  838. /* clear pre-existing south bridge errors */
  839. __raw_writel(__raw_readl(IOP13XX_XBG_BECSR) & 3, IOP13XX_XBG_BECSR);
  840. /* Setup the Min Address for PCI memory... */
  841. iop13xx_pcibios_min_mem = IOP13XX_PCIX_LOWER_MEM_BA;
  842. /* if Linux is given control of an ATU
  843. * clear out its prior configuration,
  844. * otherwise do not touch the registers
  845. */
  846. if (init_atu & IOP13XX_INIT_ATU_ATUE) {
  847. iop13xx_atue_disable();
  848. iop13xx_atue_setup();
  849. }
  850. if (init_atu & IOP13XX_INIT_ATU_ATUX) {
  851. iop13xx_atux_disable();
  852. iop13xx_atux_setup();
  853. }
  854. hook_fault_code(16+6, iop13xx_pci_abort, SIGBUS, 0,
  855. "imprecise external abort");
  856. }
  857. /* initialize the pci memory space. handle any combination of
  858. * atue and atux enabled/disabled
  859. */
  860. int iop13xx_pci_setup(int nr, struct pci_sys_data *sys)
  861. {
  862. struct resource *res;
  863. int which_atu;
  864. u32 pcixsr, pcsr;
  865. if (nr > 1)
  866. return 0;
  867. res = kcalloc(2, sizeof(struct resource), GFP_KERNEL);
  868. if (!res)
  869. panic("PCI: unable to alloc resources");
  870. /* 'nr' assumptions:
  871. * ATUX is always 0
  872. * ATUE is 1 when ATUX is also enabled
  873. * ATUE is 0 when ATUX is disabled
  874. */
  875. switch(init_atu) {
  876. case IOP13XX_INIT_ATU_ATUX:
  877. which_atu = nr ? 0 : IOP13XX_INIT_ATU_ATUX;
  878. break;
  879. case IOP13XX_INIT_ATU_ATUE:
  880. which_atu = nr ? 0 : IOP13XX_INIT_ATU_ATUE;
  881. break;
  882. case (IOP13XX_INIT_ATU_ATUX | IOP13XX_INIT_ATU_ATUE):
  883. which_atu = nr ? IOP13XX_INIT_ATU_ATUE : IOP13XX_INIT_ATU_ATUX;
  884. break;
  885. default:
  886. which_atu = 0;
  887. }
  888. if (!which_atu) {
  889. kfree(res);
  890. return 0;
  891. }
  892. switch(which_atu) {
  893. case IOP13XX_INIT_ATU_ATUX:
  894. pcixsr = __raw_readl(IOP13XX_ATUX_PCIXSR);
  895. pcixsr &= ~0xffff;
  896. pcixsr |= sys->busnr << IOP13XX_ATUX_PCIXSR_BUS_NUM |
  897. 0 << IOP13XX_ATUX_PCIXSR_DEV_NUM |
  898. iop13xx_atu_function(IOP13XX_INIT_ATU_ATUX)
  899. << IOP13XX_ATUX_PCIXSR_FUNC_NUM;
  900. __raw_writel(pcixsr, IOP13XX_ATUX_PCIXSR);
  901. res[0].start = IOP13XX_PCIX_LOWER_IO_PA + IOP13XX_PCIX_IO_BUS_OFFSET;
  902. res[0].end = IOP13XX_PCIX_UPPER_IO_PA;
  903. res[0].name = "IQ81340 ATUX PCI I/O Space";
  904. res[0].flags = IORESOURCE_IO;
  905. res[1].start = IOP13XX_PCIX_LOWER_MEM_RA;
  906. res[1].end = IOP13XX_PCIX_UPPER_MEM_RA;
  907. res[1].name = "IQ81340 ATUX PCI Memory Space";
  908. res[1].flags = IORESOURCE_MEM;
  909. sys->mem_offset = IOP13XX_PCIX_MEM_OFFSET;
  910. sys->io_offset = IOP13XX_PCIX_LOWER_IO_PA;
  911. break;
  912. case IOP13XX_INIT_ATU_ATUE:
  913. /* Note: the function number field in the PCSR is ro */
  914. pcsr = __raw_readl(IOP13XX_ATUE_PCSR);
  915. pcsr &= ~(0xfff8 << 16);
  916. pcsr |= sys->busnr << IOP13XX_ATUE_PCSR_BUS_NUM |
  917. 0 << IOP13XX_ATUE_PCSR_DEV_NUM;
  918. __raw_writel(pcsr, IOP13XX_ATUE_PCSR);
  919. res[0].start = IOP13XX_PCIE_LOWER_IO_PA + IOP13XX_PCIE_IO_BUS_OFFSET;
  920. res[0].end = IOP13XX_PCIE_UPPER_IO_PA;
  921. res[0].name = "IQ81340 ATUE PCI I/O Space";
  922. res[0].flags = IORESOURCE_IO;
  923. res[1].start = IOP13XX_PCIE_LOWER_MEM_RA;
  924. res[1].end = IOP13XX_PCIE_UPPER_MEM_RA;
  925. res[1].name = "IQ81340 ATUE PCI Memory Space";
  926. res[1].flags = IORESOURCE_MEM;
  927. sys->mem_offset = IOP13XX_PCIE_MEM_OFFSET;
  928. sys->io_offset = IOP13XX_PCIE_LOWER_IO_PA;
  929. sys->map_irq = iop13xx_pcie_map_irq;
  930. break;
  931. default:
  932. kfree(res);
  933. return 0;
  934. }
  935. request_resource(&ioport_resource, &res[0]);
  936. request_resource(&iomem_resource, &res[1]);
  937. sys->resource[0] = &res[0];
  938. sys->resource[1] = &res[1];
  939. sys->resource[2] = NULL;
  940. return 1;
  941. }
  942. u16 iop13xx_dev_id(void)
  943. {
  944. if (__raw_readl(IOP13XX_ESSR0) & IOP13XX_INTERFACE_SEL_PCIX)
  945. return __raw_readw(IOP13XX_ATUE_DID);
  946. else
  947. return __raw_readw(IOP13XX_ATUX_DID);
  948. }
  949. static int __init iop13xx_init_atu_setup(char *str)
  950. {
  951. init_atu = IOP13XX_INIT_ATU_NONE;
  952. if (str) {
  953. while (*str != '\0') {
  954. switch (*str) {
  955. case 'x':
  956. case 'X':
  957. init_atu |= IOP13XX_INIT_ATU_ATUX;
  958. init_atu &= ~IOP13XX_INIT_ATU_NONE;
  959. break;
  960. case 'e':
  961. case 'E':
  962. init_atu |= IOP13XX_INIT_ATU_ATUE;
  963. init_atu &= ~IOP13XX_INIT_ATU_NONE;
  964. break;
  965. case ',':
  966. case '=':
  967. break;
  968. default:
  969. PRINTK("\"iop13xx_init_atu\" malformed at "
  970. "character: \'%c\'", *str);
  971. *(str + 1) = '\0';
  972. init_atu = IOP13XX_INIT_ATU_DEFAULT;
  973. }
  974. str++;
  975. }
  976. }
  977. return 1;
  978. }
  979. __setup("iop13xx_init_atu", iop13xx_init_atu_setup);