fsl_rio.c 32 KB

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