pci.c 32 KB

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