fsl_rio.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. /*
  2. * Freescale MPC85xx/MPC86xx RapidIO support
  3. *
  4. * Copyright (C) 2007, 2008 Freescale Semiconductor, Inc.
  5. * Zhang Wei <wei.zhang@freescale.com>
  6. *
  7. * Copyright 2005 MontaVista Software, Inc.
  8. * Matt Porter <mporter@kernel.crashing.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. */
  15. #include <linux/init.h>
  16. #include <linux/module.h>
  17. #include <linux/types.h>
  18. #include <linux/dma-mapping.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/device.h>
  21. #include <linux/rio.h>
  22. #include <linux/rio_drv.h>
  23. #include <linux/of_platform.h>
  24. #include <linux/delay.h>
  25. #include <asm/io.h>
  26. /* RapidIO definition irq, which read from OF-tree */
  27. #define IRQ_RIO_BELL(m) (((struct rio_priv *)(m->priv))->bellirq)
  28. #define IRQ_RIO_TX(m) (((struct rio_priv *)(m->priv))->txirq)
  29. #define IRQ_RIO_RX(m) (((struct rio_priv *)(m->priv))->rxirq)
  30. #define RIO_ATMU_REGS_OFFSET 0x10c00
  31. #define RIO_P_MSG_REGS_OFFSET 0x11000
  32. #define RIO_S_MSG_REGS_OFFSET 0x13000
  33. #define RIO_ESCSR 0x158
  34. #define RIO_CCSR 0x15c
  35. #define RIO_ISR_AACR 0x10120
  36. #define RIO_ISR_AACR_AA 0x1 /* Accept All ID */
  37. #define RIO_MAINT_WIN_SIZE 0x400000
  38. #define RIO_DBELL_WIN_SIZE 0x1000
  39. #define RIO_MSG_OMR_MUI 0x00000002
  40. #define RIO_MSG_OSR_TE 0x00000080
  41. #define RIO_MSG_OSR_QOI 0x00000020
  42. #define RIO_MSG_OSR_QFI 0x00000010
  43. #define RIO_MSG_OSR_MUB 0x00000004
  44. #define RIO_MSG_OSR_EOMI 0x00000002
  45. #define RIO_MSG_OSR_QEI 0x00000001
  46. #define RIO_MSG_IMR_MI 0x00000002
  47. #define RIO_MSG_ISR_TE 0x00000080
  48. #define RIO_MSG_ISR_QFI 0x00000010
  49. #define RIO_MSG_ISR_DIQI 0x00000001
  50. #define RIO_MSG_DESC_SIZE 32
  51. #define RIO_MSG_BUFFER_SIZE 4096
  52. #define RIO_MIN_TX_RING_SIZE 2
  53. #define RIO_MAX_TX_RING_SIZE 2048
  54. #define RIO_MIN_RX_RING_SIZE 2
  55. #define RIO_MAX_RX_RING_SIZE 2048
  56. #define DOORBELL_DMR_DI 0x00000002
  57. #define DOORBELL_DSR_TE 0x00000080
  58. #define DOORBELL_DSR_QFI 0x00000010
  59. #define DOORBELL_DSR_DIQI 0x00000001
  60. #define DOORBELL_TID_OFFSET 0x02
  61. #define DOORBELL_SID_OFFSET 0x04
  62. #define DOORBELL_INFO_OFFSET 0x06
  63. #define DOORBELL_MESSAGE_SIZE 0x08
  64. #define DBELL_SID(x) (*(u16 *)(x + DOORBELL_SID_OFFSET))
  65. #define DBELL_TID(x) (*(u16 *)(x + DOORBELL_TID_OFFSET))
  66. #define DBELL_INF(x) (*(u16 *)(x + DOORBELL_INFO_OFFSET))
  67. struct rio_atmu_regs {
  68. u32 rowtar;
  69. u32 rowtear;
  70. u32 rowbar;
  71. u32 pad2;
  72. u32 rowar;
  73. u32 pad3[3];
  74. };
  75. struct rio_msg_regs {
  76. u32 omr;
  77. u32 osr;
  78. u32 pad1;
  79. u32 odqdpar;
  80. u32 pad2;
  81. u32 osar;
  82. u32 odpr;
  83. u32 odatr;
  84. u32 odcr;
  85. u32 pad3;
  86. u32 odqepar;
  87. u32 pad4[13];
  88. u32 imr;
  89. u32 isr;
  90. u32 pad5;
  91. u32 ifqdpar;
  92. u32 pad6;
  93. u32 ifqepar;
  94. u32 pad7[226];
  95. u32 odmr;
  96. u32 odsr;
  97. u32 res0[4];
  98. u32 oddpr;
  99. u32 oddatr;
  100. u32 res1[3];
  101. u32 odretcr;
  102. u32 res2[12];
  103. u32 dmr;
  104. u32 dsr;
  105. u32 pad8;
  106. u32 dqdpar;
  107. u32 pad9;
  108. u32 dqepar;
  109. u32 pad10[26];
  110. u32 pwmr;
  111. u32 pwsr;
  112. u32 pad11;
  113. u32 pwqbar;
  114. };
  115. struct rio_tx_desc {
  116. u32 res1;
  117. u32 saddr;
  118. u32 dport;
  119. u32 dattr;
  120. u32 res2;
  121. u32 res3;
  122. u32 dwcnt;
  123. u32 res4;
  124. };
  125. struct rio_dbell_ring {
  126. void *virt;
  127. dma_addr_t phys;
  128. };
  129. struct rio_msg_tx_ring {
  130. void *virt;
  131. dma_addr_t phys;
  132. void *virt_buffer[RIO_MAX_TX_RING_SIZE];
  133. dma_addr_t phys_buffer[RIO_MAX_TX_RING_SIZE];
  134. int tx_slot;
  135. int size;
  136. void *dev_id;
  137. };
  138. struct rio_msg_rx_ring {
  139. void *virt;
  140. dma_addr_t phys;
  141. void *virt_buffer[RIO_MAX_RX_RING_SIZE];
  142. int rx_slot;
  143. int size;
  144. void *dev_id;
  145. };
  146. struct rio_priv {
  147. struct device *dev;
  148. void __iomem *regs_win;
  149. struct rio_atmu_regs __iomem *atmu_regs;
  150. struct rio_atmu_regs __iomem *maint_atmu_regs;
  151. struct rio_atmu_regs __iomem *dbell_atmu_regs;
  152. void __iomem *dbell_win;
  153. void __iomem *maint_win;
  154. struct rio_msg_regs __iomem *msg_regs;
  155. struct rio_dbell_ring dbell_ring;
  156. struct rio_msg_tx_ring msg_tx_ring;
  157. struct rio_msg_rx_ring msg_rx_ring;
  158. int bellirq;
  159. int txirq;
  160. int rxirq;
  161. };
  162. /**
  163. * fsl_rio_doorbell_send - Send a MPC85xx doorbell message
  164. * @mport: RapidIO master port info
  165. * @index: ID of RapidIO interface
  166. * @destid: Destination ID of target device
  167. * @data: 16-bit info field of RapidIO doorbell message
  168. *
  169. * Sends a MPC85xx doorbell message. Returns %0 on success or
  170. * %-EINVAL on failure.
  171. */
  172. static int fsl_rio_doorbell_send(struct rio_mport *mport,
  173. int index, u16 destid, u16 data)
  174. {
  175. struct rio_priv *priv = mport->priv;
  176. pr_debug("fsl_doorbell_send: index %d destid %4.4x data %4.4x\n",
  177. index, destid, data);
  178. switch (mport->phy_type) {
  179. case RIO_PHY_PARALLEL:
  180. out_be32(&priv->dbell_atmu_regs->rowtar, destid << 22);
  181. out_be16(priv->dbell_win, data);
  182. break;
  183. case RIO_PHY_SERIAL:
  184. /* In the serial version silicons, such as MPC8548, MPC8641,
  185. * below operations is must be.
  186. */
  187. out_be32(&priv->msg_regs->odmr, 0x00000000);
  188. out_be32(&priv->msg_regs->odretcr, 0x00000004);
  189. out_be32(&priv->msg_regs->oddpr, destid << 16);
  190. out_be32(&priv->msg_regs->oddatr, data);
  191. out_be32(&priv->msg_regs->odmr, 0x00000001);
  192. break;
  193. }
  194. return 0;
  195. }
  196. /**
  197. * fsl_local_config_read - Generate a MPC85xx local config space read
  198. * @mport: RapidIO master port info
  199. * @index: ID of RapdiIO interface
  200. * @offset: Offset into configuration space
  201. * @len: Length (in bytes) of the maintenance transaction
  202. * @data: Value to be read into
  203. *
  204. * Generates a MPC85xx local configuration space read. Returns %0 on
  205. * success or %-EINVAL on failure.
  206. */
  207. static int fsl_local_config_read(struct rio_mport *mport,
  208. int index, u32 offset, int len, u32 *data)
  209. {
  210. struct rio_priv *priv = mport->priv;
  211. pr_debug("fsl_local_config_read: index %d offset %8.8x\n", index,
  212. offset);
  213. *data = in_be32(priv->regs_win + offset);
  214. return 0;
  215. }
  216. /**
  217. * fsl_local_config_write - Generate a MPC85xx local config space write
  218. * @mport: RapidIO master port info
  219. * @index: ID of RapdiIO interface
  220. * @offset: Offset into configuration space
  221. * @len: Length (in bytes) of the maintenance transaction
  222. * @data: Value to be written
  223. *
  224. * Generates a MPC85xx local configuration space write. Returns %0 on
  225. * success or %-EINVAL on failure.
  226. */
  227. static int fsl_local_config_write(struct rio_mport *mport,
  228. int index, u32 offset, int len, u32 data)
  229. {
  230. struct rio_priv *priv = mport->priv;
  231. pr_debug
  232. ("fsl_local_config_write: index %d offset %8.8x data %8.8x\n",
  233. index, offset, data);
  234. out_be32(priv->regs_win + offset, data);
  235. return 0;
  236. }
  237. /**
  238. * fsl_rio_config_read - Generate a MPC85xx read maintenance transaction
  239. * @mport: RapidIO master port info
  240. * @index: ID of RapdiIO interface
  241. * @destid: Destination ID of transaction
  242. * @hopcount: Number of hops to target device
  243. * @offset: Offset into configuration space
  244. * @len: Length (in bytes) of the maintenance transaction
  245. * @val: Location to be read into
  246. *
  247. * Generates a MPC85xx read maintenance transaction. Returns %0 on
  248. * success or %-EINVAL on failure.
  249. */
  250. static int
  251. fsl_rio_config_read(struct rio_mport *mport, int index, u16 destid,
  252. u8 hopcount, u32 offset, int len, u32 *val)
  253. {
  254. struct rio_priv *priv = mport->priv;
  255. u8 *data;
  256. pr_debug
  257. ("fsl_rio_config_read: index %d destid %d hopcount %d offset %8.8x len %d\n",
  258. index, destid, hopcount, offset, len);
  259. out_be32(&priv->maint_atmu_regs->rowtar,
  260. (destid << 22) | (hopcount << 12) | ((offset & ~0x3) >> 9));
  261. data = (u8 *) priv->maint_win + offset;
  262. switch (len) {
  263. case 1:
  264. *val = in_8((u8 *) data);
  265. break;
  266. case 2:
  267. *val = in_be16((u16 *) data);
  268. break;
  269. default:
  270. *val = in_be32((u32 *) data);
  271. break;
  272. }
  273. return 0;
  274. }
  275. /**
  276. * fsl_rio_config_write - Generate a MPC85xx write maintenance transaction
  277. * @mport: RapidIO master port info
  278. * @index: ID of RapdiIO interface
  279. * @destid: Destination ID of transaction
  280. * @hopcount: Number of hops to target device
  281. * @offset: Offset into configuration space
  282. * @len: Length (in bytes) of the maintenance transaction
  283. * @val: Value to be written
  284. *
  285. * Generates an MPC85xx write maintenance transaction. Returns %0 on
  286. * success or %-EINVAL on failure.
  287. */
  288. static int
  289. fsl_rio_config_write(struct rio_mport *mport, int index, u16 destid,
  290. u8 hopcount, u32 offset, int len, u32 val)
  291. {
  292. struct rio_priv *priv = mport->priv;
  293. u8 *data;
  294. pr_debug
  295. ("fsl_rio_config_write: index %d destid %d hopcount %d offset %8.8x len %d val %8.8x\n",
  296. index, destid, hopcount, offset, len, val);
  297. out_be32(&priv->maint_atmu_regs->rowtar,
  298. (destid << 22) | (hopcount << 12) | ((offset & ~0x3) >> 9));
  299. data = (u8 *) priv->maint_win + offset;
  300. switch (len) {
  301. case 1:
  302. out_8((u8 *) data, val);
  303. break;
  304. case 2:
  305. out_be16((u16 *) data, val);
  306. break;
  307. default:
  308. out_be32((u32 *) data, val);
  309. break;
  310. }
  311. return 0;
  312. }
  313. /**
  314. * rio_hw_add_outb_message - Add message to the MPC85xx outbound message queue
  315. * @mport: Master port with outbound message queue
  316. * @rdev: Target of outbound message
  317. * @mbox: Outbound mailbox
  318. * @buffer: Message to add to outbound queue
  319. * @len: Length of message
  320. *
  321. * Adds the @buffer message to the MPC85xx outbound message queue. Returns
  322. * %0 on success or %-EINVAL on failure.
  323. */
  324. int
  325. rio_hw_add_outb_message(struct rio_mport *mport, struct rio_dev *rdev, int mbox,
  326. void *buffer, size_t len)
  327. {
  328. struct rio_priv *priv = mport->priv;
  329. u32 omr;
  330. struct rio_tx_desc *desc = (struct rio_tx_desc *)priv->msg_tx_ring.virt
  331. + priv->msg_tx_ring.tx_slot;
  332. int ret = 0;
  333. pr_debug
  334. ("RIO: rio_hw_add_outb_message(): destid %4.4x mbox %d buffer %8.8x len %8.8x\n",
  335. rdev->destid, mbox, (int)buffer, len);
  336. if ((len < 8) || (len > RIO_MAX_MSG_SIZE)) {
  337. ret = -EINVAL;
  338. goto out;
  339. }
  340. /* Copy and clear rest of buffer */
  341. memcpy(priv->msg_tx_ring.virt_buffer[priv->msg_tx_ring.tx_slot], buffer,
  342. len);
  343. if (len < (RIO_MAX_MSG_SIZE - 4))
  344. memset(priv->msg_tx_ring.virt_buffer[priv->msg_tx_ring.tx_slot]
  345. + len, 0, RIO_MAX_MSG_SIZE - len);
  346. switch (mport->phy_type) {
  347. case RIO_PHY_PARALLEL:
  348. /* Set mbox field for message */
  349. desc->dport = mbox & 0x3;
  350. /* Enable EOMI interrupt, set priority, and set destid */
  351. desc->dattr = 0x28000000 | (rdev->destid << 2);
  352. break;
  353. case RIO_PHY_SERIAL:
  354. /* Set mbox field for message, and set destid */
  355. desc->dport = (rdev->destid << 16) | (mbox & 0x3);
  356. /* Enable EOMI interrupt and priority */
  357. desc->dattr = 0x28000000;
  358. break;
  359. }
  360. /* Set transfer size aligned to next power of 2 (in double words) */
  361. desc->dwcnt = is_power_of_2(len) ? len : 1 << get_bitmask_order(len);
  362. /* Set snooping and source buffer address */
  363. desc->saddr = 0x00000004
  364. | priv->msg_tx_ring.phys_buffer[priv->msg_tx_ring.tx_slot];
  365. /* Increment enqueue pointer */
  366. omr = in_be32(&priv->msg_regs->omr);
  367. out_be32(&priv->msg_regs->omr, omr | RIO_MSG_OMR_MUI);
  368. /* Go to next descriptor */
  369. if (++priv->msg_tx_ring.tx_slot == priv->msg_tx_ring.size)
  370. priv->msg_tx_ring.tx_slot = 0;
  371. out:
  372. return ret;
  373. }
  374. EXPORT_SYMBOL_GPL(rio_hw_add_outb_message);
  375. /**
  376. * fsl_rio_tx_handler - MPC85xx outbound message interrupt handler
  377. * @irq: Linux interrupt number
  378. * @dev_instance: Pointer to interrupt-specific data
  379. *
  380. * Handles outbound message interrupts. Executes a register outbound
  381. * mailbox event handler and acks the interrupt occurrence.
  382. */
  383. static irqreturn_t
  384. fsl_rio_tx_handler(int irq, void *dev_instance)
  385. {
  386. int osr;
  387. struct rio_mport *port = (struct rio_mport *)dev_instance;
  388. struct rio_priv *priv = port->priv;
  389. osr = in_be32(&priv->msg_regs->osr);
  390. if (osr & RIO_MSG_OSR_TE) {
  391. pr_info("RIO: outbound message transmission error\n");
  392. out_be32(&priv->msg_regs->osr, RIO_MSG_OSR_TE);
  393. goto out;
  394. }
  395. if (osr & RIO_MSG_OSR_QOI) {
  396. pr_info("RIO: outbound message queue overflow\n");
  397. out_be32(&priv->msg_regs->osr, RIO_MSG_OSR_QOI);
  398. goto out;
  399. }
  400. if (osr & RIO_MSG_OSR_EOMI) {
  401. u32 dqp = in_be32(&priv->msg_regs->odqdpar);
  402. int slot = (dqp - priv->msg_tx_ring.phys) >> 5;
  403. port->outb_msg[0].mcback(port, priv->msg_tx_ring.dev_id, -1,
  404. slot);
  405. /* Ack the end-of-message interrupt */
  406. out_be32(&priv->msg_regs->osr, RIO_MSG_OSR_EOMI);
  407. }
  408. out:
  409. return IRQ_HANDLED;
  410. }
  411. /**
  412. * rio_open_outb_mbox - Initialize MPC85xx outbound mailbox
  413. * @mport: Master port implementing the outbound message unit
  414. * @dev_id: Device specific pointer to pass on event
  415. * @mbox: Mailbox to open
  416. * @entries: Number of entries in the outbound mailbox ring
  417. *
  418. * Initializes buffer ring, request the outbound message interrupt,
  419. * and enables the outbound message unit. Returns %0 on success and
  420. * %-EINVAL or %-ENOMEM on failure.
  421. */
  422. int rio_open_outb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries)
  423. {
  424. int i, j, rc = 0;
  425. struct rio_priv *priv = mport->priv;
  426. if ((entries < RIO_MIN_TX_RING_SIZE) ||
  427. (entries > RIO_MAX_TX_RING_SIZE) || (!is_power_of_2(entries))) {
  428. rc = -EINVAL;
  429. goto out;
  430. }
  431. /* Initialize shadow copy ring */
  432. priv->msg_tx_ring.dev_id = dev_id;
  433. priv->msg_tx_ring.size = entries;
  434. for (i = 0; i < priv->msg_tx_ring.size; i++) {
  435. priv->msg_tx_ring.virt_buffer[i] =
  436. dma_alloc_coherent(priv->dev, RIO_MSG_BUFFER_SIZE,
  437. &priv->msg_tx_ring.phys_buffer[i], GFP_KERNEL);
  438. if (!priv->msg_tx_ring.virt_buffer[i]) {
  439. rc = -ENOMEM;
  440. for (j = 0; j < priv->msg_tx_ring.size; j++)
  441. if (priv->msg_tx_ring.virt_buffer[j])
  442. dma_free_coherent(priv->dev,
  443. RIO_MSG_BUFFER_SIZE,
  444. priv->msg_tx_ring.
  445. virt_buffer[j],
  446. priv->msg_tx_ring.
  447. phys_buffer[j]);
  448. goto out;
  449. }
  450. }
  451. /* Initialize outbound message descriptor ring */
  452. priv->msg_tx_ring.virt = dma_alloc_coherent(priv->dev,
  453. priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE,
  454. &priv->msg_tx_ring.phys, GFP_KERNEL);
  455. if (!priv->msg_tx_ring.virt) {
  456. rc = -ENOMEM;
  457. goto out_dma;
  458. }
  459. memset(priv->msg_tx_ring.virt, 0,
  460. priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE);
  461. priv->msg_tx_ring.tx_slot = 0;
  462. /* Point dequeue/enqueue pointers at first entry in ring */
  463. out_be32(&priv->msg_regs->odqdpar, priv->msg_tx_ring.phys);
  464. out_be32(&priv->msg_regs->odqepar, priv->msg_tx_ring.phys);
  465. /* Configure for snooping */
  466. out_be32(&priv->msg_regs->osar, 0x00000004);
  467. /* Clear interrupt status */
  468. out_be32(&priv->msg_regs->osr, 0x000000b3);
  469. /* Hook up outbound message handler */
  470. rc = request_irq(IRQ_RIO_TX(mport), fsl_rio_tx_handler, 0,
  471. "msg_tx", (void *)mport);
  472. if (rc < 0)
  473. goto out_irq;
  474. /*
  475. * Configure outbound message unit
  476. * Snooping
  477. * Interrupts (all enabled, except QEIE)
  478. * Chaining mode
  479. * Disable
  480. */
  481. out_be32(&priv->msg_regs->omr, 0x00100220);
  482. /* Set number of entries */
  483. out_be32(&priv->msg_regs->omr,
  484. in_be32(&priv->msg_regs->omr) |
  485. ((get_bitmask_order(entries) - 2) << 12));
  486. /* Now enable the unit */
  487. out_be32(&priv->msg_regs->omr, in_be32(&priv->msg_regs->omr) | 0x1);
  488. out:
  489. return rc;
  490. out_irq:
  491. dma_free_coherent(priv->dev,
  492. priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE,
  493. priv->msg_tx_ring.virt, priv->msg_tx_ring.phys);
  494. out_dma:
  495. for (i = 0; i < priv->msg_tx_ring.size; i++)
  496. dma_free_coherent(priv->dev, RIO_MSG_BUFFER_SIZE,
  497. priv->msg_tx_ring.virt_buffer[i],
  498. priv->msg_tx_ring.phys_buffer[i]);
  499. return rc;
  500. }
  501. /**
  502. * rio_close_outb_mbox - Shut down MPC85xx outbound mailbox
  503. * @mport: Master port implementing the outbound message unit
  504. * @mbox: Mailbox to close
  505. *
  506. * Disables the outbound message unit, free all buffers, and
  507. * frees the outbound message interrupt.
  508. */
  509. void rio_close_outb_mbox(struct rio_mport *mport, int mbox)
  510. {
  511. struct rio_priv *priv = mport->priv;
  512. /* Disable inbound message unit */
  513. out_be32(&priv->msg_regs->omr, 0);
  514. /* Free ring */
  515. dma_free_coherent(priv->dev,
  516. priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE,
  517. priv->msg_tx_ring.virt, priv->msg_tx_ring.phys);
  518. /* Free interrupt */
  519. free_irq(IRQ_RIO_TX(mport), (void *)mport);
  520. }
  521. /**
  522. * fsl_rio_rx_handler - MPC85xx inbound message interrupt handler
  523. * @irq: Linux interrupt number
  524. * @dev_instance: Pointer to interrupt-specific data
  525. *
  526. * Handles inbound message interrupts. Executes a registered inbound
  527. * mailbox event handler and acks the interrupt occurrence.
  528. */
  529. static irqreturn_t
  530. fsl_rio_rx_handler(int irq, void *dev_instance)
  531. {
  532. int isr;
  533. struct rio_mport *port = (struct rio_mport *)dev_instance;
  534. struct rio_priv *priv = port->priv;
  535. isr = in_be32(&priv->msg_regs->isr);
  536. if (isr & RIO_MSG_ISR_TE) {
  537. pr_info("RIO: inbound message reception error\n");
  538. out_be32((void *)&priv->msg_regs->isr, RIO_MSG_ISR_TE);
  539. goto out;
  540. }
  541. /* XXX Need to check/dispatch until queue empty */
  542. if (isr & RIO_MSG_ISR_DIQI) {
  543. /*
  544. * We implement *only* mailbox 0, but can receive messages
  545. * for any mailbox/letter to that mailbox destination. So,
  546. * make the callback with an unknown/invalid mailbox number
  547. * argument.
  548. */
  549. port->inb_msg[0].mcback(port, priv->msg_rx_ring.dev_id, -1, -1);
  550. /* Ack the queueing interrupt */
  551. out_be32(&priv->msg_regs->isr, RIO_MSG_ISR_DIQI);
  552. }
  553. out:
  554. return IRQ_HANDLED;
  555. }
  556. /**
  557. * rio_open_inb_mbox - Initialize MPC85xx inbound mailbox
  558. * @mport: Master port implementing the inbound message unit
  559. * @dev_id: Device specific pointer to pass on event
  560. * @mbox: Mailbox to open
  561. * @entries: Number of entries in the inbound mailbox ring
  562. *
  563. * Initializes buffer ring, request the inbound message interrupt,
  564. * and enables the inbound message unit. Returns %0 on success
  565. * and %-EINVAL or %-ENOMEM on failure.
  566. */
  567. int rio_open_inb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries)
  568. {
  569. int i, rc = 0;
  570. struct rio_priv *priv = mport->priv;
  571. if ((entries < RIO_MIN_RX_RING_SIZE) ||
  572. (entries > RIO_MAX_RX_RING_SIZE) || (!is_power_of_2(entries))) {
  573. rc = -EINVAL;
  574. goto out;
  575. }
  576. /* Initialize client buffer ring */
  577. priv->msg_rx_ring.dev_id = dev_id;
  578. priv->msg_rx_ring.size = entries;
  579. priv->msg_rx_ring.rx_slot = 0;
  580. for (i = 0; i < priv->msg_rx_ring.size; i++)
  581. priv->msg_rx_ring.virt_buffer[i] = NULL;
  582. /* Initialize inbound message ring */
  583. priv->msg_rx_ring.virt = dma_alloc_coherent(priv->dev,
  584. priv->msg_rx_ring.size * RIO_MAX_MSG_SIZE,
  585. &priv->msg_rx_ring.phys, GFP_KERNEL);
  586. if (!priv->msg_rx_ring.virt) {
  587. rc = -ENOMEM;
  588. goto out;
  589. }
  590. /* Point dequeue/enqueue pointers at first entry in ring */
  591. out_be32(&priv->msg_regs->ifqdpar, (u32) priv->msg_rx_ring.phys);
  592. out_be32(&priv->msg_regs->ifqepar, (u32) priv->msg_rx_ring.phys);
  593. /* Clear interrupt status */
  594. out_be32(&priv->msg_regs->isr, 0x00000091);
  595. /* Hook up inbound message handler */
  596. rc = request_irq(IRQ_RIO_RX(mport), fsl_rio_rx_handler, 0,
  597. "msg_rx", (void *)mport);
  598. if (rc < 0) {
  599. dma_free_coherent(priv->dev, RIO_MSG_BUFFER_SIZE,
  600. priv->msg_tx_ring.virt_buffer[i],
  601. priv->msg_tx_ring.phys_buffer[i]);
  602. goto out;
  603. }
  604. /*
  605. * Configure inbound message unit:
  606. * Snooping
  607. * 4KB max message size
  608. * Unmask all interrupt sources
  609. * Disable
  610. */
  611. out_be32(&priv->msg_regs->imr, 0x001b0060);
  612. /* Set number of queue entries */
  613. setbits32(&priv->msg_regs->imr, (get_bitmask_order(entries) - 2) << 12);
  614. /* Now enable the unit */
  615. setbits32(&priv->msg_regs->imr, 0x1);
  616. out:
  617. return rc;
  618. }
  619. /**
  620. * rio_close_inb_mbox - Shut down MPC85xx inbound mailbox
  621. * @mport: Master port implementing the inbound message unit
  622. * @mbox: Mailbox to close
  623. *
  624. * Disables the inbound message unit, free all buffers, and
  625. * frees the inbound message interrupt.
  626. */
  627. void rio_close_inb_mbox(struct rio_mport *mport, int mbox)
  628. {
  629. struct rio_priv *priv = mport->priv;
  630. /* Disable inbound message unit */
  631. out_be32(&priv->msg_regs->imr, 0);
  632. /* Free ring */
  633. dma_free_coherent(priv->dev, priv->msg_rx_ring.size * RIO_MAX_MSG_SIZE,
  634. priv->msg_rx_ring.virt, priv->msg_rx_ring.phys);
  635. /* Free interrupt */
  636. free_irq(IRQ_RIO_RX(mport), (void *)mport);
  637. }
  638. /**
  639. * rio_hw_add_inb_buffer - Add buffer to the MPC85xx inbound message queue
  640. * @mport: Master port implementing the inbound message unit
  641. * @mbox: Inbound mailbox number
  642. * @buf: Buffer to add to inbound queue
  643. *
  644. * Adds the @buf buffer to the MPC85xx inbound message queue. Returns
  645. * %0 on success or %-EINVAL on failure.
  646. */
  647. int rio_hw_add_inb_buffer(struct rio_mport *mport, int mbox, void *buf)
  648. {
  649. int rc = 0;
  650. struct rio_priv *priv = mport->priv;
  651. pr_debug("RIO: rio_hw_add_inb_buffer(), msg_rx_ring.rx_slot %d\n",
  652. priv->msg_rx_ring.rx_slot);
  653. if (priv->msg_rx_ring.virt_buffer[priv->msg_rx_ring.rx_slot]) {
  654. printk(KERN_ERR
  655. "RIO: error adding inbound buffer %d, buffer exists\n",
  656. priv->msg_rx_ring.rx_slot);
  657. rc = -EINVAL;
  658. goto out;
  659. }
  660. priv->msg_rx_ring.virt_buffer[priv->msg_rx_ring.rx_slot] = buf;
  661. if (++priv->msg_rx_ring.rx_slot == priv->msg_rx_ring.size)
  662. priv->msg_rx_ring.rx_slot = 0;
  663. out:
  664. return rc;
  665. }
  666. EXPORT_SYMBOL_GPL(rio_hw_add_inb_buffer);
  667. /**
  668. * rio_hw_get_inb_message - Fetch inbound message from the MPC85xx message unit
  669. * @mport: Master port implementing the inbound message unit
  670. * @mbox: Inbound mailbox number
  671. *
  672. * Gets the next available inbound message from the inbound message queue.
  673. * A pointer to the message is returned on success or NULL on failure.
  674. */
  675. void *rio_hw_get_inb_message(struct rio_mport *mport, int mbox)
  676. {
  677. struct rio_priv *priv = mport->priv;
  678. u32 phys_buf, virt_buf;
  679. void *buf = NULL;
  680. int buf_idx;
  681. phys_buf = in_be32(&priv->msg_regs->ifqdpar);
  682. /* If no more messages, then bail out */
  683. if (phys_buf == in_be32(&priv->msg_regs->ifqepar))
  684. goto out2;
  685. virt_buf = (u32) priv->msg_rx_ring.virt + (phys_buf
  686. - priv->msg_rx_ring.phys);
  687. buf_idx = (phys_buf - priv->msg_rx_ring.phys) / RIO_MAX_MSG_SIZE;
  688. buf = priv->msg_rx_ring.virt_buffer[buf_idx];
  689. if (!buf) {
  690. printk(KERN_ERR
  691. "RIO: inbound message copy failed, no buffers\n");
  692. goto out1;
  693. }
  694. /* Copy max message size, caller is expected to allocate that big */
  695. memcpy(buf, (void *)virt_buf, RIO_MAX_MSG_SIZE);
  696. /* Clear the available buffer */
  697. priv->msg_rx_ring.virt_buffer[buf_idx] = NULL;
  698. out1:
  699. setbits32(&priv->msg_regs->imr, RIO_MSG_IMR_MI);
  700. out2:
  701. return buf;
  702. }
  703. EXPORT_SYMBOL_GPL(rio_hw_get_inb_message);
  704. /**
  705. * fsl_rio_dbell_handler - MPC85xx doorbell interrupt handler
  706. * @irq: Linux interrupt number
  707. * @dev_instance: Pointer to interrupt-specific data
  708. *
  709. * Handles doorbell interrupts. Parses a list of registered
  710. * doorbell event handlers and executes a matching event handler.
  711. */
  712. static irqreturn_t
  713. fsl_rio_dbell_handler(int irq, void *dev_instance)
  714. {
  715. int dsr;
  716. struct rio_mport *port = (struct rio_mport *)dev_instance;
  717. struct rio_priv *priv = port->priv;
  718. dsr = in_be32(&priv->msg_regs->dsr);
  719. if (dsr & DOORBELL_DSR_TE) {
  720. pr_info("RIO: doorbell reception error\n");
  721. out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_TE);
  722. goto out;
  723. }
  724. if (dsr & DOORBELL_DSR_QFI) {
  725. pr_info("RIO: doorbell queue full\n");
  726. out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_QFI);
  727. goto out;
  728. }
  729. /* XXX Need to check/dispatch until queue empty */
  730. if (dsr & DOORBELL_DSR_DIQI) {
  731. u32 dmsg =
  732. (u32) priv->dbell_ring.virt +
  733. (in_be32(&priv->msg_regs->dqdpar) & 0xfff);
  734. struct rio_dbell *dbell;
  735. int found = 0;
  736. pr_debug
  737. ("RIO: processing doorbell, sid %2.2x tid %2.2x info %4.4x\n",
  738. DBELL_SID(dmsg), DBELL_TID(dmsg), DBELL_INF(dmsg));
  739. list_for_each_entry(dbell, &port->dbells, node) {
  740. if ((dbell->res->start <= DBELL_INF(dmsg)) &&
  741. (dbell->res->end >= DBELL_INF(dmsg))) {
  742. found = 1;
  743. break;
  744. }
  745. }
  746. if (found) {
  747. dbell->dinb(port, dbell->dev_id, DBELL_SID(dmsg), DBELL_TID(dmsg),
  748. DBELL_INF(dmsg));
  749. } else {
  750. pr_debug
  751. ("RIO: spurious doorbell, sid %2.2x tid %2.2x info %4.4x\n",
  752. DBELL_SID(dmsg), DBELL_TID(dmsg), DBELL_INF(dmsg));
  753. }
  754. setbits32(&priv->msg_regs->dmr, DOORBELL_DMR_DI);
  755. out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_DIQI);
  756. }
  757. out:
  758. return IRQ_HANDLED;
  759. }
  760. /**
  761. * fsl_rio_doorbell_init - MPC85xx doorbell interface init
  762. * @mport: Master port implementing the inbound doorbell unit
  763. *
  764. * Initializes doorbell unit hardware and inbound DMA buffer
  765. * ring. Called from fsl_rio_setup(). Returns %0 on success
  766. * or %-ENOMEM on failure.
  767. */
  768. static int fsl_rio_doorbell_init(struct rio_mport *mport)
  769. {
  770. struct rio_priv *priv = mport->priv;
  771. int rc = 0;
  772. /* Map outbound doorbell window immediately after maintenance window */
  773. priv->dbell_win = ioremap(mport->iores.start + RIO_MAINT_WIN_SIZE,
  774. RIO_DBELL_WIN_SIZE);
  775. if (!priv->dbell_win) {
  776. printk(KERN_ERR
  777. "RIO: unable to map outbound doorbell window\n");
  778. rc = -ENOMEM;
  779. goto out;
  780. }
  781. /* Initialize inbound doorbells */
  782. priv->dbell_ring.virt = dma_alloc_coherent(priv->dev, 512 *
  783. DOORBELL_MESSAGE_SIZE, &priv->dbell_ring.phys, GFP_KERNEL);
  784. if (!priv->dbell_ring.virt) {
  785. printk(KERN_ERR "RIO: unable allocate inbound doorbell ring\n");
  786. rc = -ENOMEM;
  787. iounmap(priv->dbell_win);
  788. goto out;
  789. }
  790. /* Point dequeue/enqueue pointers at first entry in ring */
  791. out_be32(&priv->msg_regs->dqdpar, (u32) priv->dbell_ring.phys);
  792. out_be32(&priv->msg_regs->dqepar, (u32) priv->dbell_ring.phys);
  793. /* Clear interrupt status */
  794. out_be32(&priv->msg_regs->dsr, 0x00000091);
  795. /* Hook up doorbell handler */
  796. rc = request_irq(IRQ_RIO_BELL(mport), fsl_rio_dbell_handler, 0,
  797. "dbell_rx", (void *)mport);
  798. if (rc < 0) {
  799. iounmap(priv->dbell_win);
  800. dma_free_coherent(priv->dev, 512 * DOORBELL_MESSAGE_SIZE,
  801. priv->dbell_ring.virt, priv->dbell_ring.phys);
  802. printk(KERN_ERR
  803. "MPC85xx RIO: unable to request inbound doorbell irq");
  804. goto out;
  805. }
  806. /* Configure doorbells for snooping, 512 entries, and enable */
  807. out_be32(&priv->msg_regs->dmr, 0x00108161);
  808. out:
  809. return rc;
  810. }
  811. static char *cmdline = NULL;
  812. static int fsl_rio_get_hdid(int index)
  813. {
  814. /* XXX Need to parse multiple entries in some format */
  815. if (!cmdline)
  816. return -1;
  817. return simple_strtol(cmdline, NULL, 0);
  818. }
  819. static int fsl_rio_get_cmdline(char *s)
  820. {
  821. if (!s)
  822. return 0;
  823. cmdline = s;
  824. return 1;
  825. }
  826. __setup("riohdid=", fsl_rio_get_cmdline);
  827. static inline void fsl_rio_info(struct device *dev, u32 ccsr)
  828. {
  829. const char *str;
  830. if (ccsr & 1) {
  831. /* Serial phy */
  832. switch (ccsr >> 30) {
  833. case 0:
  834. str = "1";
  835. break;
  836. case 1:
  837. str = "4";
  838. break;
  839. default:
  840. str = "Unknown";
  841. break;
  842. }
  843. dev_info(dev, "Hardware port width: %s\n", str);
  844. switch ((ccsr >> 27) & 7) {
  845. case 0:
  846. str = "Single-lane 0";
  847. break;
  848. case 1:
  849. str = "Single-lane 2";
  850. break;
  851. case 2:
  852. str = "Four-lane";
  853. break;
  854. default:
  855. str = "Unknown";
  856. break;
  857. }
  858. dev_info(dev, "Training connection status: %s\n", str);
  859. } else {
  860. /* Parallel phy */
  861. if (!(ccsr & 0x80000000))
  862. dev_info(dev, "Output port operating in 8-bit mode\n");
  863. if (!(ccsr & 0x08000000))
  864. dev_info(dev, "Input port operating in 8-bit mode\n");
  865. }
  866. }
  867. /**
  868. * fsl_rio_setup - Setup Freescale PowerPC RapidIO interface
  869. * @dev: of_device pointer
  870. *
  871. * Initializes MPC85xx RapidIO hardware interface, configures
  872. * master port with system-specific info, and registers the
  873. * master port with the RapidIO subsystem.
  874. */
  875. int fsl_rio_setup(struct of_device *dev)
  876. {
  877. struct rio_ops *ops;
  878. struct rio_mport *port;
  879. struct rio_priv *priv;
  880. int rc = 0;
  881. const u32 *dt_range, *cell;
  882. struct resource regs;
  883. int rlen;
  884. u32 ccsr;
  885. u64 law_start, law_size;
  886. int paw, aw, sw;
  887. if (!dev->node) {
  888. dev_err(&dev->dev, "Device OF-Node is NULL");
  889. return -EFAULT;
  890. }
  891. rc = of_address_to_resource(dev->node, 0, &regs);
  892. if (rc) {
  893. dev_err(&dev->dev, "Can't get %s property 'reg'\n",
  894. dev->node->full_name);
  895. return -EFAULT;
  896. }
  897. dev_info(&dev->dev, "Of-device full name %s\n", dev->node->full_name);
  898. dev_info(&dev->dev, "Regs: %pR\n", &regs);
  899. dt_range = of_get_property(dev->node, "ranges", &rlen);
  900. if (!dt_range) {
  901. dev_err(&dev->dev, "Can't get %s property 'ranges'\n",
  902. dev->node->full_name);
  903. return -EFAULT;
  904. }
  905. /* Get node address wide */
  906. cell = of_get_property(dev->node, "#address-cells", NULL);
  907. if (cell)
  908. aw = *cell;
  909. else
  910. aw = of_n_addr_cells(dev->node);
  911. /* Get node size wide */
  912. cell = of_get_property(dev->node, "#size-cells", NULL);
  913. if (cell)
  914. sw = *cell;
  915. else
  916. sw = of_n_size_cells(dev->node);
  917. /* Get parent address wide wide */
  918. paw = of_n_addr_cells(dev->node);
  919. law_start = of_read_number(dt_range + aw, paw);
  920. law_size = of_read_number(dt_range + aw + paw, sw);
  921. dev_info(&dev->dev, "LAW start 0x%016llx, size 0x%016llx.\n",
  922. law_start, law_size);
  923. ops = kmalloc(sizeof(struct rio_ops), GFP_KERNEL);
  924. ops->lcread = fsl_local_config_read;
  925. ops->lcwrite = fsl_local_config_write;
  926. ops->cread = fsl_rio_config_read;
  927. ops->cwrite = fsl_rio_config_write;
  928. ops->dsend = fsl_rio_doorbell_send;
  929. port = kzalloc(sizeof(struct rio_mport), GFP_KERNEL);
  930. port->id = 0;
  931. port->index = 0;
  932. priv = kzalloc(sizeof(struct rio_priv), GFP_KERNEL);
  933. if (!priv) {
  934. printk(KERN_ERR "Can't alloc memory for 'priv'\n");
  935. rc = -ENOMEM;
  936. goto err;
  937. }
  938. INIT_LIST_HEAD(&port->dbells);
  939. port->iores.start = law_start;
  940. port->iores.end = law_start + law_size - 1;
  941. port->iores.flags = IORESOURCE_MEM;
  942. port->iores.name = "rio_io_win";
  943. priv->bellirq = irq_of_parse_and_map(dev->node, 2);
  944. priv->txirq = irq_of_parse_and_map(dev->node, 3);
  945. priv->rxirq = irq_of_parse_and_map(dev->node, 4);
  946. dev_info(&dev->dev, "bellirq: %d, txirq: %d, rxirq %d\n", priv->bellirq,
  947. priv->txirq, priv->rxirq);
  948. rio_init_dbell_res(&port->riores[RIO_DOORBELL_RESOURCE], 0, 0xffff);
  949. rio_init_mbox_res(&port->riores[RIO_INB_MBOX_RESOURCE], 0, 0);
  950. rio_init_mbox_res(&port->riores[RIO_OUTB_MBOX_RESOURCE], 0, 0);
  951. strcpy(port->name, "RIO0 mport");
  952. priv->dev = &dev->dev;
  953. port->ops = ops;
  954. port->host_deviceid = fsl_rio_get_hdid(port->id);
  955. port->priv = priv;
  956. rio_register_mport(port);
  957. priv->regs_win = ioremap(regs.start, regs.end - regs.start + 1);
  958. /* Probe the master port phy type */
  959. ccsr = in_be32(priv->regs_win + RIO_CCSR);
  960. port->phy_type = (ccsr & 1) ? RIO_PHY_SERIAL : RIO_PHY_PARALLEL;
  961. dev_info(&dev->dev, "RapidIO PHY type: %s\n",
  962. (port->phy_type == RIO_PHY_PARALLEL) ? "parallel" :
  963. ((port->phy_type == RIO_PHY_SERIAL) ? "serial" :
  964. "unknown"));
  965. /* Checking the port training status */
  966. if (in_be32((priv->regs_win + RIO_ESCSR)) & 1) {
  967. dev_err(&dev->dev, "Port is not ready. "
  968. "Try to restart connection...\n");
  969. switch (port->phy_type) {
  970. case RIO_PHY_SERIAL:
  971. /* Disable ports */
  972. out_be32(priv->regs_win + RIO_CCSR, 0);
  973. /* Set 1x lane */
  974. setbits32(priv->regs_win + RIO_CCSR, 0x02000000);
  975. /* Enable ports */
  976. setbits32(priv->regs_win + RIO_CCSR, 0x00600000);
  977. break;
  978. case RIO_PHY_PARALLEL:
  979. /* Disable ports */
  980. out_be32(priv->regs_win + RIO_CCSR, 0x22000000);
  981. /* Enable ports */
  982. out_be32(priv->regs_win + RIO_CCSR, 0x44000000);
  983. break;
  984. }
  985. msleep(100);
  986. if (in_be32((priv->regs_win + RIO_ESCSR)) & 1) {
  987. dev_err(&dev->dev, "Port restart failed.\n");
  988. rc = -ENOLINK;
  989. goto err;
  990. }
  991. dev_info(&dev->dev, "Port restart success!\n");
  992. }
  993. fsl_rio_info(&dev->dev, ccsr);
  994. port->sys_size = (in_be32((priv->regs_win + RIO_PEF_CAR))
  995. & RIO_PEF_CTLS) >> 4;
  996. dev_info(&dev->dev, "RapidIO Common Transport System size: %d\n",
  997. port->sys_size ? 65536 : 256);
  998. priv->atmu_regs = (struct rio_atmu_regs *)(priv->regs_win
  999. + RIO_ATMU_REGS_OFFSET);
  1000. priv->maint_atmu_regs = priv->atmu_regs + 1;
  1001. priv->dbell_atmu_regs = priv->atmu_regs + 2;
  1002. priv->msg_regs = (struct rio_msg_regs *)(priv->regs_win +
  1003. ((port->phy_type == RIO_PHY_SERIAL) ?
  1004. RIO_S_MSG_REGS_OFFSET : RIO_P_MSG_REGS_OFFSET));
  1005. /* Set to receive any dist ID for serial RapidIO controller. */
  1006. if (port->phy_type == RIO_PHY_SERIAL)
  1007. out_be32((priv->regs_win + RIO_ISR_AACR), RIO_ISR_AACR_AA);
  1008. /* Configure maintenance transaction window */
  1009. out_be32(&priv->maint_atmu_regs->rowbar, law_start >> 12);
  1010. out_be32(&priv->maint_atmu_regs->rowar, 0x80077015); /* 4M */
  1011. priv->maint_win = ioremap(law_start, RIO_MAINT_WIN_SIZE);
  1012. /* Configure outbound doorbell window */
  1013. out_be32(&priv->dbell_atmu_regs->rowbar,
  1014. (law_start + RIO_MAINT_WIN_SIZE) >> 12);
  1015. out_be32(&priv->dbell_atmu_regs->rowar, 0x8004200b); /* 4k */
  1016. fsl_rio_doorbell_init(port);
  1017. return 0;
  1018. err:
  1019. if (priv)
  1020. iounmap(priv->regs_win);
  1021. kfree(ops);
  1022. kfree(priv);
  1023. kfree(port);
  1024. return rc;
  1025. }
  1026. /* The probe function for RapidIO peer-to-peer network.
  1027. */
  1028. static int __devinit fsl_of_rio_rpn_probe(struct of_device *dev,
  1029. const struct of_device_id *match)
  1030. {
  1031. int rc;
  1032. printk(KERN_INFO "Setting up RapidIO peer-to-peer network %s\n",
  1033. dev->node->full_name);
  1034. rc = fsl_rio_setup(dev);
  1035. if (rc)
  1036. goto out;
  1037. /* Enumerate all registered ports */
  1038. rc = rio_init_mports();
  1039. out:
  1040. return rc;
  1041. };
  1042. static const struct of_device_id fsl_of_rio_rpn_ids[] = {
  1043. {
  1044. .compatible = "fsl,rapidio-delta",
  1045. },
  1046. {},
  1047. };
  1048. static struct of_platform_driver fsl_of_rio_rpn_driver = {
  1049. .name = "fsl-of-rio",
  1050. .match_table = fsl_of_rio_rpn_ids,
  1051. .probe = fsl_of_rio_rpn_probe,
  1052. };
  1053. static __init int fsl_of_rio_rpn_init(void)
  1054. {
  1055. return of_register_platform_driver(&fsl_of_rio_rpn_driver);
  1056. }
  1057. subsys_initcall(fsl_of_rio_rpn_init);