vme_ca91cx42.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932
  1. /*
  2. * Support for the Tundra Universe I/II VME-PCI Bridge Chips
  3. *
  4. * Author: Martyn Welch <martyn.welch@ge.com>
  5. * Copyright 2008 GE Intelligent Platforms Embedded Systems, Inc.
  6. *
  7. * Based on work by Tom Armistead and Ajit Prem
  8. * Copyright 2004 Motorola Inc.
  9. *
  10. * Derived from ca91c042.c by Michael Wyrick
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/mm.h>
  19. #include <linux/types.h>
  20. #include <linux/errno.h>
  21. #include <linux/pci.h>
  22. #include <linux/dma-mapping.h>
  23. #include <linux/poll.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/sched.h>
  27. #include <linux/slab.h>
  28. #include <linux/time.h>
  29. #include <linux/io.h>
  30. #include <linux/uaccess.h>
  31. #include <linux/vme.h>
  32. #include "../vme_bridge.h"
  33. #include "vme_ca91cx42.h"
  34. static int ca91cx42_probe(struct pci_dev *, const struct pci_device_id *);
  35. static void ca91cx42_remove(struct pci_dev *);
  36. /* Module parameters */
  37. static int geoid;
  38. static const char driver_name[] = "vme_ca91cx42";
  39. static const struct pci_device_id ca91cx42_ids[] = {
  40. { PCI_DEVICE(PCI_VENDOR_ID_TUNDRA, PCI_DEVICE_ID_TUNDRA_CA91C142) },
  41. { },
  42. };
  43. MODULE_DEVICE_TABLE(pci, ca91cx42_ids);
  44. static struct pci_driver ca91cx42_driver = {
  45. .name = driver_name,
  46. .id_table = ca91cx42_ids,
  47. .probe = ca91cx42_probe,
  48. .remove = ca91cx42_remove,
  49. };
  50. static u32 ca91cx42_DMA_irqhandler(struct ca91cx42_driver *bridge)
  51. {
  52. wake_up(&bridge->dma_queue);
  53. return CA91CX42_LINT_DMA;
  54. }
  55. static u32 ca91cx42_LM_irqhandler(struct ca91cx42_driver *bridge, u32 stat)
  56. {
  57. int i;
  58. u32 serviced = 0;
  59. for (i = 0; i < 4; i++) {
  60. if (stat & CA91CX42_LINT_LM[i]) {
  61. /* We only enable interrupts if the callback is set */
  62. bridge->lm_callback[i](bridge->lm_data[i]);
  63. serviced |= CA91CX42_LINT_LM[i];
  64. }
  65. }
  66. return serviced;
  67. }
  68. /* XXX This needs to be split into 4 queues */
  69. static u32 ca91cx42_MB_irqhandler(struct ca91cx42_driver *bridge, int mbox_mask)
  70. {
  71. wake_up(&bridge->mbox_queue);
  72. return CA91CX42_LINT_MBOX;
  73. }
  74. static u32 ca91cx42_IACK_irqhandler(struct ca91cx42_driver *bridge)
  75. {
  76. wake_up(&bridge->iack_queue);
  77. return CA91CX42_LINT_SW_IACK;
  78. }
  79. static u32 ca91cx42_VERR_irqhandler(struct vme_bridge *ca91cx42_bridge)
  80. {
  81. int val;
  82. struct ca91cx42_driver *bridge;
  83. bridge = ca91cx42_bridge->driver_priv;
  84. val = ioread32(bridge->base + DGCS);
  85. if (!(val & 0x00000800)) {
  86. dev_err(ca91cx42_bridge->parent, "ca91cx42_VERR_irqhandler DMA "
  87. "Read Error DGCS=%08X\n", val);
  88. }
  89. return CA91CX42_LINT_VERR;
  90. }
  91. static u32 ca91cx42_LERR_irqhandler(struct vme_bridge *ca91cx42_bridge)
  92. {
  93. int val;
  94. struct ca91cx42_driver *bridge;
  95. bridge = ca91cx42_bridge->driver_priv;
  96. val = ioread32(bridge->base + DGCS);
  97. if (!(val & 0x00000800))
  98. dev_err(ca91cx42_bridge->parent, "ca91cx42_LERR_irqhandler DMA "
  99. "Read Error DGCS=%08X\n", val);
  100. return CA91CX42_LINT_LERR;
  101. }
  102. static u32 ca91cx42_VIRQ_irqhandler(struct vme_bridge *ca91cx42_bridge,
  103. int stat)
  104. {
  105. int vec, i, serviced = 0;
  106. struct ca91cx42_driver *bridge;
  107. bridge = ca91cx42_bridge->driver_priv;
  108. for (i = 7; i > 0; i--) {
  109. if (stat & (1 << i)) {
  110. vec = ioread32(bridge->base +
  111. CA91CX42_V_STATID[i]) & 0xff;
  112. vme_irq_handler(ca91cx42_bridge, i, vec);
  113. serviced |= (1 << i);
  114. }
  115. }
  116. return serviced;
  117. }
  118. static irqreturn_t ca91cx42_irqhandler(int irq, void *ptr)
  119. {
  120. u32 stat, enable, serviced = 0;
  121. struct vme_bridge *ca91cx42_bridge;
  122. struct ca91cx42_driver *bridge;
  123. ca91cx42_bridge = ptr;
  124. bridge = ca91cx42_bridge->driver_priv;
  125. enable = ioread32(bridge->base + LINT_EN);
  126. stat = ioread32(bridge->base + LINT_STAT);
  127. /* Only look at unmasked interrupts */
  128. stat &= enable;
  129. if (unlikely(!stat))
  130. return IRQ_NONE;
  131. if (stat & CA91CX42_LINT_DMA)
  132. serviced |= ca91cx42_DMA_irqhandler(bridge);
  133. if (stat & (CA91CX42_LINT_LM0 | CA91CX42_LINT_LM1 | CA91CX42_LINT_LM2 |
  134. CA91CX42_LINT_LM3))
  135. serviced |= ca91cx42_LM_irqhandler(bridge, stat);
  136. if (stat & CA91CX42_LINT_MBOX)
  137. serviced |= ca91cx42_MB_irqhandler(bridge, stat);
  138. if (stat & CA91CX42_LINT_SW_IACK)
  139. serviced |= ca91cx42_IACK_irqhandler(bridge);
  140. if (stat & CA91CX42_LINT_VERR)
  141. serviced |= ca91cx42_VERR_irqhandler(ca91cx42_bridge);
  142. if (stat & CA91CX42_LINT_LERR)
  143. serviced |= ca91cx42_LERR_irqhandler(ca91cx42_bridge);
  144. if (stat & (CA91CX42_LINT_VIRQ1 | CA91CX42_LINT_VIRQ2 |
  145. CA91CX42_LINT_VIRQ3 | CA91CX42_LINT_VIRQ4 |
  146. CA91CX42_LINT_VIRQ5 | CA91CX42_LINT_VIRQ6 |
  147. CA91CX42_LINT_VIRQ7))
  148. serviced |= ca91cx42_VIRQ_irqhandler(ca91cx42_bridge, stat);
  149. /* Clear serviced interrupts */
  150. iowrite32(serviced, bridge->base + LINT_STAT);
  151. return IRQ_HANDLED;
  152. }
  153. static int ca91cx42_irq_init(struct vme_bridge *ca91cx42_bridge)
  154. {
  155. int result, tmp;
  156. struct pci_dev *pdev;
  157. struct ca91cx42_driver *bridge;
  158. bridge = ca91cx42_bridge->driver_priv;
  159. /* Need pdev */
  160. pdev = to_pci_dev(ca91cx42_bridge->parent);
  161. /* Disable interrupts from PCI to VME */
  162. iowrite32(0, bridge->base + VINT_EN);
  163. /* Disable PCI interrupts */
  164. iowrite32(0, bridge->base + LINT_EN);
  165. /* Clear Any Pending PCI Interrupts */
  166. iowrite32(0x00FFFFFF, bridge->base + LINT_STAT);
  167. result = request_irq(pdev->irq, ca91cx42_irqhandler, IRQF_SHARED,
  168. driver_name, ca91cx42_bridge);
  169. if (result) {
  170. dev_err(&pdev->dev, "Can't get assigned pci irq vector %02X\n",
  171. pdev->irq);
  172. return result;
  173. }
  174. /* Ensure all interrupts are mapped to PCI Interrupt 0 */
  175. iowrite32(0, bridge->base + LINT_MAP0);
  176. iowrite32(0, bridge->base + LINT_MAP1);
  177. iowrite32(0, bridge->base + LINT_MAP2);
  178. /* Enable DMA, mailbox & LM Interrupts */
  179. tmp = CA91CX42_LINT_MBOX3 | CA91CX42_LINT_MBOX2 | CA91CX42_LINT_MBOX1 |
  180. CA91CX42_LINT_MBOX0 | CA91CX42_LINT_SW_IACK |
  181. CA91CX42_LINT_VERR | CA91CX42_LINT_LERR | CA91CX42_LINT_DMA;
  182. iowrite32(tmp, bridge->base + LINT_EN);
  183. return 0;
  184. }
  185. static void ca91cx42_irq_exit(struct ca91cx42_driver *bridge,
  186. struct pci_dev *pdev)
  187. {
  188. struct vme_bridge *ca91cx42_bridge;
  189. /* Disable interrupts from PCI to VME */
  190. iowrite32(0, bridge->base + VINT_EN);
  191. /* Disable PCI interrupts */
  192. iowrite32(0, bridge->base + LINT_EN);
  193. /* Clear Any Pending PCI Interrupts */
  194. iowrite32(0x00FFFFFF, bridge->base + LINT_STAT);
  195. ca91cx42_bridge = container_of((void *)bridge, struct vme_bridge,
  196. driver_priv);
  197. free_irq(pdev->irq, ca91cx42_bridge);
  198. }
  199. static int ca91cx42_iack_received(struct ca91cx42_driver *bridge, int level)
  200. {
  201. u32 tmp;
  202. tmp = ioread32(bridge->base + LINT_STAT);
  203. if (tmp & (1 << level))
  204. return 0;
  205. else
  206. return 1;
  207. }
  208. /*
  209. * Set up an VME interrupt
  210. */
  211. static void ca91cx42_irq_set(struct vme_bridge *ca91cx42_bridge, int level,
  212. int state, int sync)
  213. {
  214. struct pci_dev *pdev;
  215. u32 tmp;
  216. struct ca91cx42_driver *bridge;
  217. bridge = ca91cx42_bridge->driver_priv;
  218. /* Enable IRQ level */
  219. tmp = ioread32(bridge->base + LINT_EN);
  220. if (state == 0)
  221. tmp &= ~CA91CX42_LINT_VIRQ[level];
  222. else
  223. tmp |= CA91CX42_LINT_VIRQ[level];
  224. iowrite32(tmp, bridge->base + LINT_EN);
  225. if ((state == 0) && (sync != 0)) {
  226. pdev = to_pci_dev(ca91cx42_bridge->parent);
  227. synchronize_irq(pdev->irq);
  228. }
  229. }
  230. static int ca91cx42_irq_generate(struct vme_bridge *ca91cx42_bridge, int level,
  231. int statid)
  232. {
  233. u32 tmp;
  234. struct ca91cx42_driver *bridge;
  235. bridge = ca91cx42_bridge->driver_priv;
  236. /* Universe can only generate even vectors */
  237. if (statid & 1)
  238. return -EINVAL;
  239. mutex_lock(&bridge->vme_int);
  240. tmp = ioread32(bridge->base + VINT_EN);
  241. /* Set Status/ID */
  242. iowrite32(statid << 24, bridge->base + STATID);
  243. /* Assert VMEbus IRQ */
  244. tmp = tmp | (1 << (level + 24));
  245. iowrite32(tmp, bridge->base + VINT_EN);
  246. /* Wait for IACK */
  247. wait_event_interruptible(bridge->iack_queue,
  248. ca91cx42_iack_received(bridge, level));
  249. /* Return interrupt to low state */
  250. tmp = ioread32(bridge->base + VINT_EN);
  251. tmp = tmp & ~(1 << (level + 24));
  252. iowrite32(tmp, bridge->base + VINT_EN);
  253. mutex_unlock(&bridge->vme_int);
  254. return 0;
  255. }
  256. static int ca91cx42_slave_set(struct vme_slave_resource *image, int enabled,
  257. unsigned long long vme_base, unsigned long long size,
  258. dma_addr_t pci_base, u32 aspace, u32 cycle)
  259. {
  260. unsigned int i, addr = 0, granularity;
  261. unsigned int temp_ctl = 0;
  262. unsigned int vme_bound, pci_offset;
  263. struct vme_bridge *ca91cx42_bridge;
  264. struct ca91cx42_driver *bridge;
  265. ca91cx42_bridge = image->parent;
  266. bridge = ca91cx42_bridge->driver_priv;
  267. i = image->number;
  268. switch (aspace) {
  269. case VME_A16:
  270. addr |= CA91CX42_VSI_CTL_VAS_A16;
  271. break;
  272. case VME_A24:
  273. addr |= CA91CX42_VSI_CTL_VAS_A24;
  274. break;
  275. case VME_A32:
  276. addr |= CA91CX42_VSI_CTL_VAS_A32;
  277. break;
  278. case VME_USER1:
  279. addr |= CA91CX42_VSI_CTL_VAS_USER1;
  280. break;
  281. case VME_USER2:
  282. addr |= CA91CX42_VSI_CTL_VAS_USER2;
  283. break;
  284. case VME_A64:
  285. case VME_CRCSR:
  286. case VME_USER3:
  287. case VME_USER4:
  288. default:
  289. dev_err(ca91cx42_bridge->parent, "Invalid address space\n");
  290. return -EINVAL;
  291. break;
  292. }
  293. /*
  294. * Bound address is a valid address for the window, adjust
  295. * accordingly
  296. */
  297. vme_bound = vme_base + size;
  298. pci_offset = pci_base - vme_base;
  299. if ((i == 0) || (i == 4))
  300. granularity = 0x1000;
  301. else
  302. granularity = 0x10000;
  303. if (vme_base & (granularity - 1)) {
  304. dev_err(ca91cx42_bridge->parent, "Invalid VME base "
  305. "alignment\n");
  306. return -EINVAL;
  307. }
  308. if (vme_bound & (granularity - 1)) {
  309. dev_err(ca91cx42_bridge->parent, "Invalid VME bound "
  310. "alignment\n");
  311. return -EINVAL;
  312. }
  313. if (pci_offset & (granularity - 1)) {
  314. dev_err(ca91cx42_bridge->parent, "Invalid PCI Offset "
  315. "alignment\n");
  316. return -EINVAL;
  317. }
  318. /* Disable while we are mucking around */
  319. temp_ctl = ioread32(bridge->base + CA91CX42_VSI_CTL[i]);
  320. temp_ctl &= ~CA91CX42_VSI_CTL_EN;
  321. iowrite32(temp_ctl, bridge->base + CA91CX42_VSI_CTL[i]);
  322. /* Setup mapping */
  323. iowrite32(vme_base, bridge->base + CA91CX42_VSI_BS[i]);
  324. iowrite32(vme_bound, bridge->base + CA91CX42_VSI_BD[i]);
  325. iowrite32(pci_offset, bridge->base + CA91CX42_VSI_TO[i]);
  326. /* Setup address space */
  327. temp_ctl &= ~CA91CX42_VSI_CTL_VAS_M;
  328. temp_ctl |= addr;
  329. /* Setup cycle types */
  330. temp_ctl &= ~(CA91CX42_VSI_CTL_PGM_M | CA91CX42_VSI_CTL_SUPER_M);
  331. if (cycle & VME_SUPER)
  332. temp_ctl |= CA91CX42_VSI_CTL_SUPER_SUPR;
  333. if (cycle & VME_USER)
  334. temp_ctl |= CA91CX42_VSI_CTL_SUPER_NPRIV;
  335. if (cycle & VME_PROG)
  336. temp_ctl |= CA91CX42_VSI_CTL_PGM_PGM;
  337. if (cycle & VME_DATA)
  338. temp_ctl |= CA91CX42_VSI_CTL_PGM_DATA;
  339. /* Write ctl reg without enable */
  340. iowrite32(temp_ctl, bridge->base + CA91CX42_VSI_CTL[i]);
  341. if (enabled)
  342. temp_ctl |= CA91CX42_VSI_CTL_EN;
  343. iowrite32(temp_ctl, bridge->base + CA91CX42_VSI_CTL[i]);
  344. return 0;
  345. }
  346. static int ca91cx42_slave_get(struct vme_slave_resource *image, int *enabled,
  347. unsigned long long *vme_base, unsigned long long *size,
  348. dma_addr_t *pci_base, u32 *aspace, u32 *cycle)
  349. {
  350. unsigned int i, granularity = 0, ctl = 0;
  351. unsigned long long vme_bound, pci_offset;
  352. struct ca91cx42_driver *bridge;
  353. bridge = image->parent->driver_priv;
  354. i = image->number;
  355. if ((i == 0) || (i == 4))
  356. granularity = 0x1000;
  357. else
  358. granularity = 0x10000;
  359. /* Read Registers */
  360. ctl = ioread32(bridge->base + CA91CX42_VSI_CTL[i]);
  361. *vme_base = ioread32(bridge->base + CA91CX42_VSI_BS[i]);
  362. vme_bound = ioread32(bridge->base + CA91CX42_VSI_BD[i]);
  363. pci_offset = ioread32(bridge->base + CA91CX42_VSI_TO[i]);
  364. *pci_base = (dma_addr_t)*vme_base + pci_offset;
  365. *size = (unsigned long long)((vme_bound - *vme_base) + granularity);
  366. *enabled = 0;
  367. *aspace = 0;
  368. *cycle = 0;
  369. if (ctl & CA91CX42_VSI_CTL_EN)
  370. *enabled = 1;
  371. if ((ctl & CA91CX42_VSI_CTL_VAS_M) == CA91CX42_VSI_CTL_VAS_A16)
  372. *aspace = VME_A16;
  373. if ((ctl & CA91CX42_VSI_CTL_VAS_M) == CA91CX42_VSI_CTL_VAS_A24)
  374. *aspace = VME_A24;
  375. if ((ctl & CA91CX42_VSI_CTL_VAS_M) == CA91CX42_VSI_CTL_VAS_A32)
  376. *aspace = VME_A32;
  377. if ((ctl & CA91CX42_VSI_CTL_VAS_M) == CA91CX42_VSI_CTL_VAS_USER1)
  378. *aspace = VME_USER1;
  379. if ((ctl & CA91CX42_VSI_CTL_VAS_M) == CA91CX42_VSI_CTL_VAS_USER2)
  380. *aspace = VME_USER2;
  381. if (ctl & CA91CX42_VSI_CTL_SUPER_SUPR)
  382. *cycle |= VME_SUPER;
  383. if (ctl & CA91CX42_VSI_CTL_SUPER_NPRIV)
  384. *cycle |= VME_USER;
  385. if (ctl & CA91CX42_VSI_CTL_PGM_PGM)
  386. *cycle |= VME_PROG;
  387. if (ctl & CA91CX42_VSI_CTL_PGM_DATA)
  388. *cycle |= VME_DATA;
  389. return 0;
  390. }
  391. /*
  392. * Allocate and map PCI Resource
  393. */
  394. static int ca91cx42_alloc_resource(struct vme_master_resource *image,
  395. unsigned long long size)
  396. {
  397. unsigned long long existing_size;
  398. int retval = 0;
  399. struct pci_dev *pdev;
  400. struct vme_bridge *ca91cx42_bridge;
  401. ca91cx42_bridge = image->parent;
  402. /* Find pci_dev container of dev */
  403. if (!ca91cx42_bridge->parent) {
  404. dev_err(ca91cx42_bridge->parent, "Dev entry NULL\n");
  405. return -EINVAL;
  406. }
  407. pdev = to_pci_dev(ca91cx42_bridge->parent);
  408. existing_size = (unsigned long long)(image->bus_resource.end -
  409. image->bus_resource.start);
  410. /* If the existing size is OK, return */
  411. if (existing_size == (size - 1))
  412. return 0;
  413. if (existing_size != 0) {
  414. iounmap(image->kern_base);
  415. image->kern_base = NULL;
  416. kfree(image->bus_resource.name);
  417. release_resource(&image->bus_resource);
  418. memset(&image->bus_resource, 0, sizeof(image->bus_resource));
  419. }
  420. if (!image->bus_resource.name) {
  421. image->bus_resource.name = kmalloc(VMENAMSIZ+3, GFP_ATOMIC);
  422. if (!image->bus_resource.name) {
  423. retval = -ENOMEM;
  424. goto err_name;
  425. }
  426. }
  427. sprintf((char *)image->bus_resource.name, "%s.%d",
  428. ca91cx42_bridge->name, image->number);
  429. image->bus_resource.start = 0;
  430. image->bus_resource.end = (unsigned long)size;
  431. image->bus_resource.flags = IORESOURCE_MEM;
  432. retval = pci_bus_alloc_resource(pdev->bus,
  433. &image->bus_resource, size, 0x10000, PCIBIOS_MIN_MEM,
  434. 0, NULL, NULL);
  435. if (retval) {
  436. dev_err(ca91cx42_bridge->parent, "Failed to allocate mem "
  437. "resource for window %d size 0x%lx start 0x%lx\n",
  438. image->number, (unsigned long)size,
  439. (unsigned long)image->bus_resource.start);
  440. goto err_resource;
  441. }
  442. image->kern_base = ioremap_nocache(
  443. image->bus_resource.start, size);
  444. if (!image->kern_base) {
  445. dev_err(ca91cx42_bridge->parent, "Failed to remap resource\n");
  446. retval = -ENOMEM;
  447. goto err_remap;
  448. }
  449. return 0;
  450. err_remap:
  451. release_resource(&image->bus_resource);
  452. err_resource:
  453. kfree(image->bus_resource.name);
  454. memset(&image->bus_resource, 0, sizeof(image->bus_resource));
  455. err_name:
  456. return retval;
  457. }
  458. /*
  459. * Free and unmap PCI Resource
  460. */
  461. static void ca91cx42_free_resource(struct vme_master_resource *image)
  462. {
  463. iounmap(image->kern_base);
  464. image->kern_base = NULL;
  465. release_resource(&image->bus_resource);
  466. kfree(image->bus_resource.name);
  467. memset(&image->bus_resource, 0, sizeof(image->bus_resource));
  468. }
  469. static int ca91cx42_master_set(struct vme_master_resource *image, int enabled,
  470. unsigned long long vme_base, unsigned long long size, u32 aspace,
  471. u32 cycle, u32 dwidth)
  472. {
  473. int retval = 0;
  474. unsigned int i, granularity = 0;
  475. unsigned int temp_ctl = 0;
  476. unsigned long long pci_bound, vme_offset, pci_base;
  477. struct vme_bridge *ca91cx42_bridge;
  478. struct ca91cx42_driver *bridge;
  479. ca91cx42_bridge = image->parent;
  480. bridge = ca91cx42_bridge->driver_priv;
  481. i = image->number;
  482. if ((i == 0) || (i == 4))
  483. granularity = 0x1000;
  484. else
  485. granularity = 0x10000;
  486. /* Verify input data */
  487. if (vme_base & (granularity - 1)) {
  488. dev_err(ca91cx42_bridge->parent, "Invalid VME Window "
  489. "alignment\n");
  490. retval = -EINVAL;
  491. goto err_window;
  492. }
  493. if (size & (granularity - 1)) {
  494. dev_err(ca91cx42_bridge->parent, "Invalid VME Window "
  495. "alignment\n");
  496. retval = -EINVAL;
  497. goto err_window;
  498. }
  499. spin_lock(&image->lock);
  500. /*
  501. * Let's allocate the resource here rather than further up the stack as
  502. * it avoids pushing loads of bus dependent stuff up the stack
  503. */
  504. retval = ca91cx42_alloc_resource(image, size);
  505. if (retval) {
  506. spin_unlock(&image->lock);
  507. dev_err(ca91cx42_bridge->parent, "Unable to allocate memory "
  508. "for resource name\n");
  509. retval = -ENOMEM;
  510. goto err_res;
  511. }
  512. pci_base = (unsigned long long)image->bus_resource.start;
  513. /*
  514. * Bound address is a valid address for the window, adjust
  515. * according to window granularity.
  516. */
  517. pci_bound = pci_base + size;
  518. vme_offset = vme_base - pci_base;
  519. /* Disable while we are mucking around */
  520. temp_ctl = ioread32(bridge->base + CA91CX42_LSI_CTL[i]);
  521. temp_ctl &= ~CA91CX42_LSI_CTL_EN;
  522. iowrite32(temp_ctl, bridge->base + CA91CX42_LSI_CTL[i]);
  523. /* Setup cycle types */
  524. temp_ctl &= ~CA91CX42_LSI_CTL_VCT_M;
  525. if (cycle & VME_BLT)
  526. temp_ctl |= CA91CX42_LSI_CTL_VCT_BLT;
  527. if (cycle & VME_MBLT)
  528. temp_ctl |= CA91CX42_LSI_CTL_VCT_MBLT;
  529. /* Setup data width */
  530. temp_ctl &= ~CA91CX42_LSI_CTL_VDW_M;
  531. switch (dwidth) {
  532. case VME_D8:
  533. temp_ctl |= CA91CX42_LSI_CTL_VDW_D8;
  534. break;
  535. case VME_D16:
  536. temp_ctl |= CA91CX42_LSI_CTL_VDW_D16;
  537. break;
  538. case VME_D32:
  539. temp_ctl |= CA91CX42_LSI_CTL_VDW_D32;
  540. break;
  541. case VME_D64:
  542. temp_ctl |= CA91CX42_LSI_CTL_VDW_D64;
  543. break;
  544. default:
  545. spin_unlock(&image->lock);
  546. dev_err(ca91cx42_bridge->parent, "Invalid data width\n");
  547. retval = -EINVAL;
  548. goto err_dwidth;
  549. break;
  550. }
  551. /* Setup address space */
  552. temp_ctl &= ~CA91CX42_LSI_CTL_VAS_M;
  553. switch (aspace) {
  554. case VME_A16:
  555. temp_ctl |= CA91CX42_LSI_CTL_VAS_A16;
  556. break;
  557. case VME_A24:
  558. temp_ctl |= CA91CX42_LSI_CTL_VAS_A24;
  559. break;
  560. case VME_A32:
  561. temp_ctl |= CA91CX42_LSI_CTL_VAS_A32;
  562. break;
  563. case VME_CRCSR:
  564. temp_ctl |= CA91CX42_LSI_CTL_VAS_CRCSR;
  565. break;
  566. case VME_USER1:
  567. temp_ctl |= CA91CX42_LSI_CTL_VAS_USER1;
  568. break;
  569. case VME_USER2:
  570. temp_ctl |= CA91CX42_LSI_CTL_VAS_USER2;
  571. break;
  572. case VME_A64:
  573. case VME_USER3:
  574. case VME_USER4:
  575. default:
  576. spin_unlock(&image->lock);
  577. dev_err(ca91cx42_bridge->parent, "Invalid address space\n");
  578. retval = -EINVAL;
  579. goto err_aspace;
  580. break;
  581. }
  582. temp_ctl &= ~(CA91CX42_LSI_CTL_PGM_M | CA91CX42_LSI_CTL_SUPER_M);
  583. if (cycle & VME_SUPER)
  584. temp_ctl |= CA91CX42_LSI_CTL_SUPER_SUPR;
  585. if (cycle & VME_PROG)
  586. temp_ctl |= CA91CX42_LSI_CTL_PGM_PGM;
  587. /* Setup mapping */
  588. iowrite32(pci_base, bridge->base + CA91CX42_LSI_BS[i]);
  589. iowrite32(pci_bound, bridge->base + CA91CX42_LSI_BD[i]);
  590. iowrite32(vme_offset, bridge->base + CA91CX42_LSI_TO[i]);
  591. /* Write ctl reg without enable */
  592. iowrite32(temp_ctl, bridge->base + CA91CX42_LSI_CTL[i]);
  593. if (enabled)
  594. temp_ctl |= CA91CX42_LSI_CTL_EN;
  595. iowrite32(temp_ctl, bridge->base + CA91CX42_LSI_CTL[i]);
  596. spin_unlock(&image->lock);
  597. return 0;
  598. err_aspace:
  599. err_dwidth:
  600. ca91cx42_free_resource(image);
  601. err_res:
  602. err_window:
  603. return retval;
  604. }
  605. static int __ca91cx42_master_get(struct vme_master_resource *image,
  606. int *enabled, unsigned long long *vme_base, unsigned long long *size,
  607. u32 *aspace, u32 *cycle, u32 *dwidth)
  608. {
  609. unsigned int i, ctl;
  610. unsigned long long pci_base, pci_bound, vme_offset;
  611. struct ca91cx42_driver *bridge;
  612. bridge = image->parent->driver_priv;
  613. i = image->number;
  614. ctl = ioread32(bridge->base + CA91CX42_LSI_CTL[i]);
  615. pci_base = ioread32(bridge->base + CA91CX42_LSI_BS[i]);
  616. vme_offset = ioread32(bridge->base + CA91CX42_LSI_TO[i]);
  617. pci_bound = ioread32(bridge->base + CA91CX42_LSI_BD[i]);
  618. *vme_base = pci_base + vme_offset;
  619. *size = (unsigned long long)(pci_bound - pci_base);
  620. *enabled = 0;
  621. *aspace = 0;
  622. *cycle = 0;
  623. *dwidth = 0;
  624. if (ctl & CA91CX42_LSI_CTL_EN)
  625. *enabled = 1;
  626. /* Setup address space */
  627. switch (ctl & CA91CX42_LSI_CTL_VAS_M) {
  628. case CA91CX42_LSI_CTL_VAS_A16:
  629. *aspace = VME_A16;
  630. break;
  631. case CA91CX42_LSI_CTL_VAS_A24:
  632. *aspace = VME_A24;
  633. break;
  634. case CA91CX42_LSI_CTL_VAS_A32:
  635. *aspace = VME_A32;
  636. break;
  637. case CA91CX42_LSI_CTL_VAS_CRCSR:
  638. *aspace = VME_CRCSR;
  639. break;
  640. case CA91CX42_LSI_CTL_VAS_USER1:
  641. *aspace = VME_USER1;
  642. break;
  643. case CA91CX42_LSI_CTL_VAS_USER2:
  644. *aspace = VME_USER2;
  645. break;
  646. }
  647. /* XXX Not sure howto check for MBLT */
  648. /* Setup cycle types */
  649. if (ctl & CA91CX42_LSI_CTL_VCT_BLT)
  650. *cycle |= VME_BLT;
  651. else
  652. *cycle |= VME_SCT;
  653. if (ctl & CA91CX42_LSI_CTL_SUPER_SUPR)
  654. *cycle |= VME_SUPER;
  655. else
  656. *cycle |= VME_USER;
  657. if (ctl & CA91CX42_LSI_CTL_PGM_PGM)
  658. *cycle = VME_PROG;
  659. else
  660. *cycle = VME_DATA;
  661. /* Setup data width */
  662. switch (ctl & CA91CX42_LSI_CTL_VDW_M) {
  663. case CA91CX42_LSI_CTL_VDW_D8:
  664. *dwidth = VME_D8;
  665. break;
  666. case CA91CX42_LSI_CTL_VDW_D16:
  667. *dwidth = VME_D16;
  668. break;
  669. case CA91CX42_LSI_CTL_VDW_D32:
  670. *dwidth = VME_D32;
  671. break;
  672. case CA91CX42_LSI_CTL_VDW_D64:
  673. *dwidth = VME_D64;
  674. break;
  675. }
  676. return 0;
  677. }
  678. static int ca91cx42_master_get(struct vme_master_resource *image, int *enabled,
  679. unsigned long long *vme_base, unsigned long long *size, u32 *aspace,
  680. u32 *cycle, u32 *dwidth)
  681. {
  682. int retval;
  683. spin_lock(&image->lock);
  684. retval = __ca91cx42_master_get(image, enabled, vme_base, size, aspace,
  685. cycle, dwidth);
  686. spin_unlock(&image->lock);
  687. return retval;
  688. }
  689. static ssize_t ca91cx42_master_read(struct vme_master_resource *image,
  690. void *buf, size_t count, loff_t offset)
  691. {
  692. ssize_t retval;
  693. void __iomem *addr = image->kern_base + offset;
  694. unsigned int done = 0;
  695. unsigned int count32;
  696. if (count == 0)
  697. return 0;
  698. spin_lock(&image->lock);
  699. /* The following code handles VME address alignment. We cannot use
  700. * memcpy_xxx here because it may cut data transfers in to 8-bit
  701. * cycles when D16 or D32 cycles are required on the VME bus.
  702. * On the other hand, the bridge itself assures that the maximum data
  703. * cycle configured for the transfer is used and splits it
  704. * automatically for non-aligned addresses, so we don't want the
  705. * overhead of needlessly forcing small transfers for the entire cycle.
  706. */
  707. if ((uintptr_t)addr & 0x1) {
  708. *(u8 *)buf = ioread8(addr);
  709. done += 1;
  710. if (done == count)
  711. goto out;
  712. }
  713. if ((uintptr_t)(addr + done) & 0x2) {
  714. if ((count - done) < 2) {
  715. *(u8 *)(buf + done) = ioread8(addr + done);
  716. done += 1;
  717. goto out;
  718. } else {
  719. *(u16 *)(buf + done) = ioread16(addr + done);
  720. done += 2;
  721. }
  722. }
  723. count32 = (count - done) & ~0x3;
  724. while (done < count32) {
  725. *(u32 *)(buf + done) = ioread32(addr + done);
  726. done += 4;
  727. }
  728. if ((count - done) & 0x2) {
  729. *(u16 *)(buf + done) = ioread16(addr + done);
  730. done += 2;
  731. }
  732. if ((count - done) & 0x1) {
  733. *(u8 *)(buf + done) = ioread8(addr + done);
  734. done += 1;
  735. }
  736. out:
  737. retval = count;
  738. spin_unlock(&image->lock);
  739. return retval;
  740. }
  741. static ssize_t ca91cx42_master_write(struct vme_master_resource *image,
  742. void *buf, size_t count, loff_t offset)
  743. {
  744. ssize_t retval;
  745. void __iomem *addr = image->kern_base + offset;
  746. unsigned int done = 0;
  747. unsigned int count32;
  748. if (count == 0)
  749. return 0;
  750. spin_lock(&image->lock);
  751. /* Here we apply for the same strategy we do in master_read
  752. * function in order to assure the correct cycles.
  753. */
  754. if ((uintptr_t)addr & 0x1) {
  755. iowrite8(*(u8 *)buf, addr);
  756. done += 1;
  757. if (done == count)
  758. goto out;
  759. }
  760. if ((uintptr_t)(addr + done) & 0x2) {
  761. if ((count - done) < 2) {
  762. iowrite8(*(u8 *)(buf + done), addr + done);
  763. done += 1;
  764. goto out;
  765. } else {
  766. iowrite16(*(u16 *)(buf + done), addr + done);
  767. done += 2;
  768. }
  769. }
  770. count32 = (count - done) & ~0x3;
  771. while (done < count32) {
  772. iowrite32(*(u32 *)(buf + done), addr + done);
  773. done += 4;
  774. }
  775. if ((count - done) & 0x2) {
  776. iowrite16(*(u16 *)(buf + done), addr + done);
  777. done += 2;
  778. }
  779. if ((count - done) & 0x1) {
  780. iowrite8(*(u8 *)(buf + done), addr + done);
  781. done += 1;
  782. }
  783. out:
  784. retval = count;
  785. spin_unlock(&image->lock);
  786. return retval;
  787. }
  788. static unsigned int ca91cx42_master_rmw(struct vme_master_resource *image,
  789. unsigned int mask, unsigned int compare, unsigned int swap,
  790. loff_t offset)
  791. {
  792. u32 result;
  793. uintptr_t pci_addr;
  794. struct ca91cx42_driver *bridge;
  795. struct device *dev;
  796. bridge = image->parent->driver_priv;
  797. dev = image->parent->parent;
  798. /* Find the PCI address that maps to the desired VME address */
  799. /* Locking as we can only do one of these at a time */
  800. mutex_lock(&bridge->vme_rmw);
  801. /* Lock image */
  802. spin_lock(&image->lock);
  803. pci_addr = (uintptr_t)image->kern_base + offset;
  804. /* Address must be 4-byte aligned */
  805. if (pci_addr & 0x3) {
  806. dev_err(dev, "RMW Address not 4-byte aligned\n");
  807. result = -EINVAL;
  808. goto out;
  809. }
  810. /* Ensure RMW Disabled whilst configuring */
  811. iowrite32(0, bridge->base + SCYC_CTL);
  812. /* Configure registers */
  813. iowrite32(mask, bridge->base + SCYC_EN);
  814. iowrite32(compare, bridge->base + SCYC_CMP);
  815. iowrite32(swap, bridge->base + SCYC_SWP);
  816. iowrite32(pci_addr, bridge->base + SCYC_ADDR);
  817. /* Enable RMW */
  818. iowrite32(CA91CX42_SCYC_CTL_CYC_RMW, bridge->base + SCYC_CTL);
  819. /* Kick process off with a read to the required address. */
  820. result = ioread32(image->kern_base + offset);
  821. /* Disable RMW */
  822. iowrite32(0, bridge->base + SCYC_CTL);
  823. out:
  824. spin_unlock(&image->lock);
  825. mutex_unlock(&bridge->vme_rmw);
  826. return result;
  827. }
  828. static int ca91cx42_dma_list_add(struct vme_dma_list *list,
  829. struct vme_dma_attr *src, struct vme_dma_attr *dest, size_t count)
  830. {
  831. struct ca91cx42_dma_entry *entry, *prev;
  832. struct vme_dma_pci *pci_attr;
  833. struct vme_dma_vme *vme_attr;
  834. dma_addr_t desc_ptr;
  835. int retval = 0;
  836. struct device *dev;
  837. dev = list->parent->parent->parent;
  838. /* XXX descriptor must be aligned on 64-bit boundaries */
  839. entry = kmalloc(sizeof(*entry), GFP_KERNEL);
  840. if (!entry) {
  841. retval = -ENOMEM;
  842. goto err_mem;
  843. }
  844. /* Test descriptor alignment */
  845. if ((unsigned long)&entry->descriptor & CA91CX42_DCPP_M) {
  846. dev_err(dev, "Descriptor not aligned to 16 byte boundary as "
  847. "required: %p\n", &entry->descriptor);
  848. retval = -EINVAL;
  849. goto err_align;
  850. }
  851. memset(&entry->descriptor, 0, sizeof(entry->descriptor));
  852. if (dest->type == VME_DMA_VME) {
  853. entry->descriptor.dctl |= CA91CX42_DCTL_L2V;
  854. vme_attr = dest->private;
  855. pci_attr = src->private;
  856. } else {
  857. vme_attr = src->private;
  858. pci_attr = dest->private;
  859. }
  860. /* Check we can do fulfill required attributes */
  861. if ((vme_attr->aspace & ~(VME_A16 | VME_A24 | VME_A32 | VME_USER1 |
  862. VME_USER2)) != 0) {
  863. dev_err(dev, "Unsupported cycle type\n");
  864. retval = -EINVAL;
  865. goto err_aspace;
  866. }
  867. if ((vme_attr->cycle & ~(VME_SCT | VME_BLT | VME_SUPER | VME_USER |
  868. VME_PROG | VME_DATA)) != 0) {
  869. dev_err(dev, "Unsupported cycle type\n");
  870. retval = -EINVAL;
  871. goto err_cycle;
  872. }
  873. /* Check to see if we can fulfill source and destination */
  874. if (!(((src->type == VME_DMA_PCI) && (dest->type == VME_DMA_VME)) ||
  875. ((src->type == VME_DMA_VME) && (dest->type == VME_DMA_PCI)))) {
  876. dev_err(dev, "Cannot perform transfer with this "
  877. "source-destination combination\n");
  878. retval = -EINVAL;
  879. goto err_direct;
  880. }
  881. /* Setup cycle types */
  882. if (vme_attr->cycle & VME_BLT)
  883. entry->descriptor.dctl |= CA91CX42_DCTL_VCT_BLT;
  884. /* Setup data width */
  885. switch (vme_attr->dwidth) {
  886. case VME_D8:
  887. entry->descriptor.dctl |= CA91CX42_DCTL_VDW_D8;
  888. break;
  889. case VME_D16:
  890. entry->descriptor.dctl |= CA91CX42_DCTL_VDW_D16;
  891. break;
  892. case VME_D32:
  893. entry->descriptor.dctl |= CA91CX42_DCTL_VDW_D32;
  894. break;
  895. case VME_D64:
  896. entry->descriptor.dctl |= CA91CX42_DCTL_VDW_D64;
  897. break;
  898. default:
  899. dev_err(dev, "Invalid data width\n");
  900. return -EINVAL;
  901. }
  902. /* Setup address space */
  903. switch (vme_attr->aspace) {
  904. case VME_A16:
  905. entry->descriptor.dctl |= CA91CX42_DCTL_VAS_A16;
  906. break;
  907. case VME_A24:
  908. entry->descriptor.dctl |= CA91CX42_DCTL_VAS_A24;
  909. break;
  910. case VME_A32:
  911. entry->descriptor.dctl |= CA91CX42_DCTL_VAS_A32;
  912. break;
  913. case VME_USER1:
  914. entry->descriptor.dctl |= CA91CX42_DCTL_VAS_USER1;
  915. break;
  916. case VME_USER2:
  917. entry->descriptor.dctl |= CA91CX42_DCTL_VAS_USER2;
  918. break;
  919. default:
  920. dev_err(dev, "Invalid address space\n");
  921. return -EINVAL;
  922. break;
  923. }
  924. if (vme_attr->cycle & VME_SUPER)
  925. entry->descriptor.dctl |= CA91CX42_DCTL_SUPER_SUPR;
  926. if (vme_attr->cycle & VME_PROG)
  927. entry->descriptor.dctl |= CA91CX42_DCTL_PGM_PGM;
  928. entry->descriptor.dtbc = count;
  929. entry->descriptor.dla = pci_attr->address;
  930. entry->descriptor.dva = vme_attr->address;
  931. entry->descriptor.dcpp = CA91CX42_DCPP_NULL;
  932. /* Add to list */
  933. list_add_tail(&entry->list, &list->entries);
  934. /* Fill out previous descriptors "Next Address" */
  935. if (entry->list.prev != &list->entries) {
  936. prev = list_entry(entry->list.prev, struct ca91cx42_dma_entry,
  937. list);
  938. /* We need the bus address for the pointer */
  939. desc_ptr = virt_to_bus(&entry->descriptor);
  940. prev->descriptor.dcpp = desc_ptr & ~CA91CX42_DCPP_M;
  941. }
  942. return 0;
  943. err_cycle:
  944. err_aspace:
  945. err_direct:
  946. err_align:
  947. kfree(entry);
  948. err_mem:
  949. return retval;
  950. }
  951. static int ca91cx42_dma_busy(struct vme_bridge *ca91cx42_bridge)
  952. {
  953. u32 tmp;
  954. struct ca91cx42_driver *bridge;
  955. bridge = ca91cx42_bridge->driver_priv;
  956. tmp = ioread32(bridge->base + DGCS);
  957. if (tmp & CA91CX42_DGCS_ACT)
  958. return 0;
  959. else
  960. return 1;
  961. }
  962. static int ca91cx42_dma_list_exec(struct vme_dma_list *list)
  963. {
  964. struct vme_dma_resource *ctrlr;
  965. struct ca91cx42_dma_entry *entry;
  966. int retval;
  967. dma_addr_t bus_addr;
  968. u32 val;
  969. struct device *dev;
  970. struct ca91cx42_driver *bridge;
  971. ctrlr = list->parent;
  972. bridge = ctrlr->parent->driver_priv;
  973. dev = ctrlr->parent->parent;
  974. mutex_lock(&ctrlr->mtx);
  975. if (!(list_empty(&ctrlr->running))) {
  976. /*
  977. * XXX We have an active DMA transfer and currently haven't
  978. * sorted out the mechanism for "pending" DMA transfers.
  979. * Return busy.
  980. */
  981. /* Need to add to pending here */
  982. mutex_unlock(&ctrlr->mtx);
  983. return -EBUSY;
  984. } else {
  985. list_add(&list->list, &ctrlr->running);
  986. }
  987. /* Get first bus address and write into registers */
  988. entry = list_first_entry(&list->entries, struct ca91cx42_dma_entry,
  989. list);
  990. bus_addr = virt_to_bus(&entry->descriptor);
  991. mutex_unlock(&ctrlr->mtx);
  992. iowrite32(0, bridge->base + DTBC);
  993. iowrite32(bus_addr & ~CA91CX42_DCPP_M, bridge->base + DCPP);
  994. /* Start the operation */
  995. val = ioread32(bridge->base + DGCS);
  996. /* XXX Could set VMEbus On and Off Counters here */
  997. val &= (CA91CX42_DGCS_VON_M | CA91CX42_DGCS_VOFF_M);
  998. val |= (CA91CX42_DGCS_CHAIN | CA91CX42_DGCS_STOP | CA91CX42_DGCS_HALT |
  999. CA91CX42_DGCS_DONE | CA91CX42_DGCS_LERR | CA91CX42_DGCS_VERR |
  1000. CA91CX42_DGCS_PERR);
  1001. iowrite32(val, bridge->base + DGCS);
  1002. val |= CA91CX42_DGCS_GO;
  1003. iowrite32(val, bridge->base + DGCS);
  1004. retval = wait_event_interruptible(bridge->dma_queue,
  1005. ca91cx42_dma_busy(ctrlr->parent));
  1006. if (retval) {
  1007. val = ioread32(bridge->base + DGCS);
  1008. iowrite32(val | CA91CX42_DGCS_STOP_REQ, bridge->base + DGCS);
  1009. /* Wait for the operation to abort */
  1010. wait_event(bridge->dma_queue,
  1011. ca91cx42_dma_busy(ctrlr->parent));
  1012. retval = -EINTR;
  1013. goto exit;
  1014. }
  1015. /*
  1016. * Read status register, this register is valid until we kick off a
  1017. * new transfer.
  1018. */
  1019. val = ioread32(bridge->base + DGCS);
  1020. if (val & (CA91CX42_DGCS_LERR | CA91CX42_DGCS_VERR |
  1021. CA91CX42_DGCS_PERR)) {
  1022. dev_err(dev, "ca91c042: DMA Error. DGCS=%08X\n", val);
  1023. val = ioread32(bridge->base + DCTL);
  1024. retval = -EIO;
  1025. }
  1026. exit:
  1027. /* Remove list from running list */
  1028. mutex_lock(&ctrlr->mtx);
  1029. list_del(&list->list);
  1030. mutex_unlock(&ctrlr->mtx);
  1031. return retval;
  1032. }
  1033. static int ca91cx42_dma_list_empty(struct vme_dma_list *list)
  1034. {
  1035. struct list_head *pos, *temp;
  1036. struct ca91cx42_dma_entry *entry;
  1037. /* detach and free each entry */
  1038. list_for_each_safe(pos, temp, &list->entries) {
  1039. list_del(pos);
  1040. entry = list_entry(pos, struct ca91cx42_dma_entry, list);
  1041. kfree(entry);
  1042. }
  1043. return 0;
  1044. }
  1045. /*
  1046. * All 4 location monitors reside at the same base - this is therefore a
  1047. * system wide configuration.
  1048. *
  1049. * This does not enable the LM monitor - that should be done when the first
  1050. * callback is attached and disabled when the last callback is removed.
  1051. */
  1052. static int ca91cx42_lm_set(struct vme_lm_resource *lm,
  1053. unsigned long long lm_base, u32 aspace, u32 cycle)
  1054. {
  1055. u32 temp_base, lm_ctl = 0;
  1056. int i;
  1057. struct ca91cx42_driver *bridge;
  1058. struct device *dev;
  1059. bridge = lm->parent->driver_priv;
  1060. dev = lm->parent->parent;
  1061. /* Check the alignment of the location monitor */
  1062. temp_base = (u32)lm_base;
  1063. if (temp_base & 0xffff) {
  1064. dev_err(dev, "Location monitor must be aligned to 64KB "
  1065. "boundary");
  1066. return -EINVAL;
  1067. }
  1068. mutex_lock(&lm->mtx);
  1069. /* If we already have a callback attached, we can't move it! */
  1070. for (i = 0; i < lm->monitors; i++) {
  1071. if (bridge->lm_callback[i]) {
  1072. mutex_unlock(&lm->mtx);
  1073. dev_err(dev, "Location monitor callback attached, "
  1074. "can't reset\n");
  1075. return -EBUSY;
  1076. }
  1077. }
  1078. switch (aspace) {
  1079. case VME_A16:
  1080. lm_ctl |= CA91CX42_LM_CTL_AS_A16;
  1081. break;
  1082. case VME_A24:
  1083. lm_ctl |= CA91CX42_LM_CTL_AS_A24;
  1084. break;
  1085. case VME_A32:
  1086. lm_ctl |= CA91CX42_LM_CTL_AS_A32;
  1087. break;
  1088. default:
  1089. mutex_unlock(&lm->mtx);
  1090. dev_err(dev, "Invalid address space\n");
  1091. return -EINVAL;
  1092. break;
  1093. }
  1094. if (cycle & VME_SUPER)
  1095. lm_ctl |= CA91CX42_LM_CTL_SUPR;
  1096. if (cycle & VME_USER)
  1097. lm_ctl |= CA91CX42_LM_CTL_NPRIV;
  1098. if (cycle & VME_PROG)
  1099. lm_ctl |= CA91CX42_LM_CTL_PGM;
  1100. if (cycle & VME_DATA)
  1101. lm_ctl |= CA91CX42_LM_CTL_DATA;
  1102. iowrite32(lm_base, bridge->base + LM_BS);
  1103. iowrite32(lm_ctl, bridge->base + LM_CTL);
  1104. mutex_unlock(&lm->mtx);
  1105. return 0;
  1106. }
  1107. /* Get configuration of the callback monitor and return whether it is enabled
  1108. * or disabled.
  1109. */
  1110. static int ca91cx42_lm_get(struct vme_lm_resource *lm,
  1111. unsigned long long *lm_base, u32 *aspace, u32 *cycle)
  1112. {
  1113. u32 lm_ctl, enabled = 0;
  1114. struct ca91cx42_driver *bridge;
  1115. bridge = lm->parent->driver_priv;
  1116. mutex_lock(&lm->mtx);
  1117. *lm_base = (unsigned long long)ioread32(bridge->base + LM_BS);
  1118. lm_ctl = ioread32(bridge->base + LM_CTL);
  1119. if (lm_ctl & CA91CX42_LM_CTL_EN)
  1120. enabled = 1;
  1121. if ((lm_ctl & CA91CX42_LM_CTL_AS_M) == CA91CX42_LM_CTL_AS_A16)
  1122. *aspace = VME_A16;
  1123. if ((lm_ctl & CA91CX42_LM_CTL_AS_M) == CA91CX42_LM_CTL_AS_A24)
  1124. *aspace = VME_A24;
  1125. if ((lm_ctl & CA91CX42_LM_CTL_AS_M) == CA91CX42_LM_CTL_AS_A32)
  1126. *aspace = VME_A32;
  1127. *cycle = 0;
  1128. if (lm_ctl & CA91CX42_LM_CTL_SUPR)
  1129. *cycle |= VME_SUPER;
  1130. if (lm_ctl & CA91CX42_LM_CTL_NPRIV)
  1131. *cycle |= VME_USER;
  1132. if (lm_ctl & CA91CX42_LM_CTL_PGM)
  1133. *cycle |= VME_PROG;
  1134. if (lm_ctl & CA91CX42_LM_CTL_DATA)
  1135. *cycle |= VME_DATA;
  1136. mutex_unlock(&lm->mtx);
  1137. return enabled;
  1138. }
  1139. /*
  1140. * Attach a callback to a specific location monitor.
  1141. *
  1142. * Callback will be passed the monitor triggered.
  1143. */
  1144. static int ca91cx42_lm_attach(struct vme_lm_resource *lm, int monitor,
  1145. void (*callback)(void *), void *data)
  1146. {
  1147. u32 lm_ctl, tmp;
  1148. struct ca91cx42_driver *bridge;
  1149. struct device *dev;
  1150. bridge = lm->parent->driver_priv;
  1151. dev = lm->parent->parent;
  1152. mutex_lock(&lm->mtx);
  1153. /* Ensure that the location monitor is configured - need PGM or DATA */
  1154. lm_ctl = ioread32(bridge->base + LM_CTL);
  1155. if ((lm_ctl & (CA91CX42_LM_CTL_PGM | CA91CX42_LM_CTL_DATA)) == 0) {
  1156. mutex_unlock(&lm->mtx);
  1157. dev_err(dev, "Location monitor not properly configured\n");
  1158. return -EINVAL;
  1159. }
  1160. /* Check that a callback isn't already attached */
  1161. if (bridge->lm_callback[monitor]) {
  1162. mutex_unlock(&lm->mtx);
  1163. dev_err(dev, "Existing callback attached\n");
  1164. return -EBUSY;
  1165. }
  1166. /* Attach callback */
  1167. bridge->lm_callback[monitor] = callback;
  1168. bridge->lm_data[monitor] = data;
  1169. /* Enable Location Monitor interrupt */
  1170. tmp = ioread32(bridge->base + LINT_EN);
  1171. tmp |= CA91CX42_LINT_LM[monitor];
  1172. iowrite32(tmp, bridge->base + LINT_EN);
  1173. /* Ensure that global Location Monitor Enable set */
  1174. if ((lm_ctl & CA91CX42_LM_CTL_EN) == 0) {
  1175. lm_ctl |= CA91CX42_LM_CTL_EN;
  1176. iowrite32(lm_ctl, bridge->base + LM_CTL);
  1177. }
  1178. mutex_unlock(&lm->mtx);
  1179. return 0;
  1180. }
  1181. /*
  1182. * Detach a callback function forn a specific location monitor.
  1183. */
  1184. static int ca91cx42_lm_detach(struct vme_lm_resource *lm, int monitor)
  1185. {
  1186. u32 tmp;
  1187. struct ca91cx42_driver *bridge;
  1188. bridge = lm->parent->driver_priv;
  1189. mutex_lock(&lm->mtx);
  1190. /* Disable Location Monitor and ensure previous interrupts are clear */
  1191. tmp = ioread32(bridge->base + LINT_EN);
  1192. tmp &= ~CA91CX42_LINT_LM[monitor];
  1193. iowrite32(tmp, bridge->base + LINT_EN);
  1194. iowrite32(CA91CX42_LINT_LM[monitor],
  1195. bridge->base + LINT_STAT);
  1196. /* Detach callback */
  1197. bridge->lm_callback[monitor] = NULL;
  1198. bridge->lm_data[monitor] = NULL;
  1199. /* If all location monitors disabled, disable global Location Monitor */
  1200. if ((tmp & (CA91CX42_LINT_LM0 | CA91CX42_LINT_LM1 | CA91CX42_LINT_LM2 |
  1201. CA91CX42_LINT_LM3)) == 0) {
  1202. tmp = ioread32(bridge->base + LM_CTL);
  1203. tmp &= ~CA91CX42_LM_CTL_EN;
  1204. iowrite32(tmp, bridge->base + LM_CTL);
  1205. }
  1206. mutex_unlock(&lm->mtx);
  1207. return 0;
  1208. }
  1209. static int ca91cx42_slot_get(struct vme_bridge *ca91cx42_bridge)
  1210. {
  1211. u32 slot = 0;
  1212. struct ca91cx42_driver *bridge;
  1213. bridge = ca91cx42_bridge->driver_priv;
  1214. if (!geoid) {
  1215. slot = ioread32(bridge->base + VCSR_BS);
  1216. slot = ((slot & CA91CX42_VCSR_BS_SLOT_M) >> 27);
  1217. } else
  1218. slot = geoid;
  1219. return (int)slot;
  1220. }
  1221. static void *ca91cx42_alloc_consistent(struct device *parent, size_t size,
  1222. dma_addr_t *dma)
  1223. {
  1224. struct pci_dev *pdev;
  1225. /* Find pci_dev container of dev */
  1226. pdev = to_pci_dev(parent);
  1227. return pci_alloc_consistent(pdev, size, dma);
  1228. }
  1229. static void ca91cx42_free_consistent(struct device *parent, size_t size,
  1230. void *vaddr, dma_addr_t dma)
  1231. {
  1232. struct pci_dev *pdev;
  1233. /* Find pci_dev container of dev */
  1234. pdev = to_pci_dev(parent);
  1235. pci_free_consistent(pdev, size, vaddr, dma);
  1236. }
  1237. /*
  1238. * Configure CR/CSR space
  1239. *
  1240. * Access to the CR/CSR can be configured at power-up. The location of the
  1241. * CR/CSR registers in the CR/CSR address space is determined by the boards
  1242. * Auto-ID or Geographic address. This function ensures that the window is
  1243. * enabled at an offset consistent with the boards geopgraphic address.
  1244. */
  1245. static int ca91cx42_crcsr_init(struct vme_bridge *ca91cx42_bridge,
  1246. struct pci_dev *pdev)
  1247. {
  1248. unsigned int crcsr_addr;
  1249. int tmp, slot;
  1250. struct ca91cx42_driver *bridge;
  1251. bridge = ca91cx42_bridge->driver_priv;
  1252. slot = ca91cx42_slot_get(ca91cx42_bridge);
  1253. /* Write CSR Base Address if slot ID is supplied as a module param */
  1254. if (geoid)
  1255. iowrite32(geoid << 27, bridge->base + VCSR_BS);
  1256. dev_info(&pdev->dev, "CR/CSR Offset: %d\n", slot);
  1257. if (slot == 0) {
  1258. dev_err(&pdev->dev, "Slot number is unset, not configuring "
  1259. "CR/CSR space\n");
  1260. return -EINVAL;
  1261. }
  1262. /* Allocate mem for CR/CSR image */
  1263. bridge->crcsr_kernel = pci_zalloc_consistent(pdev, VME_CRCSR_BUF_SIZE,
  1264. &bridge->crcsr_bus);
  1265. if (!bridge->crcsr_kernel) {
  1266. dev_err(&pdev->dev, "Failed to allocate memory for CR/CSR "
  1267. "image\n");
  1268. return -ENOMEM;
  1269. }
  1270. crcsr_addr = slot * (512 * 1024);
  1271. iowrite32(bridge->crcsr_bus - crcsr_addr, bridge->base + VCSR_TO);
  1272. tmp = ioread32(bridge->base + VCSR_CTL);
  1273. tmp |= CA91CX42_VCSR_CTL_EN;
  1274. iowrite32(tmp, bridge->base + VCSR_CTL);
  1275. return 0;
  1276. }
  1277. static void ca91cx42_crcsr_exit(struct vme_bridge *ca91cx42_bridge,
  1278. struct pci_dev *pdev)
  1279. {
  1280. u32 tmp;
  1281. struct ca91cx42_driver *bridge;
  1282. bridge = ca91cx42_bridge->driver_priv;
  1283. /* Turn off CR/CSR space */
  1284. tmp = ioread32(bridge->base + VCSR_CTL);
  1285. tmp &= ~CA91CX42_VCSR_CTL_EN;
  1286. iowrite32(tmp, bridge->base + VCSR_CTL);
  1287. /* Free image */
  1288. iowrite32(0, bridge->base + VCSR_TO);
  1289. pci_free_consistent(pdev, VME_CRCSR_BUF_SIZE, bridge->crcsr_kernel,
  1290. bridge->crcsr_bus);
  1291. }
  1292. static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  1293. {
  1294. int retval, i;
  1295. u32 data;
  1296. struct list_head *pos = NULL, *n;
  1297. struct vme_bridge *ca91cx42_bridge;
  1298. struct ca91cx42_driver *ca91cx42_device;
  1299. struct vme_master_resource *master_image;
  1300. struct vme_slave_resource *slave_image;
  1301. struct vme_dma_resource *dma_ctrlr;
  1302. struct vme_lm_resource *lm;
  1303. /* We want to support more than one of each bridge so we need to
  1304. * dynamically allocate the bridge structure
  1305. */
  1306. ca91cx42_bridge = kzalloc(sizeof(*ca91cx42_bridge), GFP_KERNEL);
  1307. if (!ca91cx42_bridge) {
  1308. retval = -ENOMEM;
  1309. goto err_struct;
  1310. }
  1311. vme_init_bridge(ca91cx42_bridge);
  1312. ca91cx42_device = kzalloc(sizeof(*ca91cx42_device), GFP_KERNEL);
  1313. if (!ca91cx42_device) {
  1314. retval = -ENOMEM;
  1315. goto err_driver;
  1316. }
  1317. ca91cx42_bridge->driver_priv = ca91cx42_device;
  1318. /* Enable the device */
  1319. retval = pci_enable_device(pdev);
  1320. if (retval) {
  1321. dev_err(&pdev->dev, "Unable to enable device\n");
  1322. goto err_enable;
  1323. }
  1324. /* Map Registers */
  1325. retval = pci_request_regions(pdev, driver_name);
  1326. if (retval) {
  1327. dev_err(&pdev->dev, "Unable to reserve resources\n");
  1328. goto err_resource;
  1329. }
  1330. /* map registers in BAR 0 */
  1331. ca91cx42_device->base = ioremap_nocache(pci_resource_start(pdev, 0),
  1332. 4096);
  1333. if (!ca91cx42_device->base) {
  1334. dev_err(&pdev->dev, "Unable to remap CRG region\n");
  1335. retval = -EIO;
  1336. goto err_remap;
  1337. }
  1338. /* Check to see if the mapping worked out */
  1339. data = ioread32(ca91cx42_device->base + CA91CX42_PCI_ID) & 0x0000FFFF;
  1340. if (data != PCI_VENDOR_ID_TUNDRA) {
  1341. dev_err(&pdev->dev, "PCI_ID check failed\n");
  1342. retval = -EIO;
  1343. goto err_test;
  1344. }
  1345. /* Initialize wait queues & mutual exclusion flags */
  1346. init_waitqueue_head(&ca91cx42_device->dma_queue);
  1347. init_waitqueue_head(&ca91cx42_device->iack_queue);
  1348. mutex_init(&ca91cx42_device->vme_int);
  1349. mutex_init(&ca91cx42_device->vme_rmw);
  1350. ca91cx42_bridge->parent = &pdev->dev;
  1351. strcpy(ca91cx42_bridge->name, driver_name);
  1352. /* Setup IRQ */
  1353. retval = ca91cx42_irq_init(ca91cx42_bridge);
  1354. if (retval != 0) {
  1355. dev_err(&pdev->dev, "Chip Initialization failed.\n");
  1356. goto err_irq;
  1357. }
  1358. /* Add master windows to list */
  1359. for (i = 0; i < CA91C142_MAX_MASTER; i++) {
  1360. master_image = kmalloc(sizeof(*master_image), GFP_KERNEL);
  1361. if (!master_image) {
  1362. retval = -ENOMEM;
  1363. goto err_master;
  1364. }
  1365. master_image->parent = ca91cx42_bridge;
  1366. spin_lock_init(&master_image->lock);
  1367. master_image->locked = 0;
  1368. master_image->number = i;
  1369. master_image->address_attr = VME_A16 | VME_A24 | VME_A32 |
  1370. VME_CRCSR | VME_USER1 | VME_USER2;
  1371. master_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT |
  1372. VME_SUPER | VME_USER | VME_PROG | VME_DATA;
  1373. master_image->width_attr = VME_D8 | VME_D16 | VME_D32 | VME_D64;
  1374. memset(&master_image->bus_resource, 0,
  1375. sizeof(master_image->bus_resource));
  1376. master_image->kern_base = NULL;
  1377. list_add_tail(&master_image->list,
  1378. &ca91cx42_bridge->master_resources);
  1379. }
  1380. /* Add slave windows to list */
  1381. for (i = 0; i < CA91C142_MAX_SLAVE; i++) {
  1382. slave_image = kmalloc(sizeof(*slave_image), GFP_KERNEL);
  1383. if (!slave_image) {
  1384. retval = -ENOMEM;
  1385. goto err_slave;
  1386. }
  1387. slave_image->parent = ca91cx42_bridge;
  1388. mutex_init(&slave_image->mtx);
  1389. slave_image->locked = 0;
  1390. slave_image->number = i;
  1391. slave_image->address_attr = VME_A24 | VME_A32 | VME_USER1 |
  1392. VME_USER2;
  1393. /* Only windows 0 and 4 support A16 */
  1394. if (i == 0 || i == 4)
  1395. slave_image->address_attr |= VME_A16;
  1396. slave_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT |
  1397. VME_SUPER | VME_USER | VME_PROG | VME_DATA;
  1398. list_add_tail(&slave_image->list,
  1399. &ca91cx42_bridge->slave_resources);
  1400. }
  1401. /* Add dma engines to list */
  1402. for (i = 0; i < CA91C142_MAX_DMA; i++) {
  1403. dma_ctrlr = kmalloc(sizeof(*dma_ctrlr), GFP_KERNEL);
  1404. if (!dma_ctrlr) {
  1405. retval = -ENOMEM;
  1406. goto err_dma;
  1407. }
  1408. dma_ctrlr->parent = ca91cx42_bridge;
  1409. mutex_init(&dma_ctrlr->mtx);
  1410. dma_ctrlr->locked = 0;
  1411. dma_ctrlr->number = i;
  1412. dma_ctrlr->route_attr = VME_DMA_VME_TO_MEM |
  1413. VME_DMA_MEM_TO_VME;
  1414. INIT_LIST_HEAD(&dma_ctrlr->pending);
  1415. INIT_LIST_HEAD(&dma_ctrlr->running);
  1416. list_add_tail(&dma_ctrlr->list,
  1417. &ca91cx42_bridge->dma_resources);
  1418. }
  1419. /* Add location monitor to list */
  1420. lm = kmalloc(sizeof(*lm), GFP_KERNEL);
  1421. if (!lm) {
  1422. retval = -ENOMEM;
  1423. goto err_lm;
  1424. }
  1425. lm->parent = ca91cx42_bridge;
  1426. mutex_init(&lm->mtx);
  1427. lm->locked = 0;
  1428. lm->number = 1;
  1429. lm->monitors = 4;
  1430. list_add_tail(&lm->list, &ca91cx42_bridge->lm_resources);
  1431. ca91cx42_bridge->slave_get = ca91cx42_slave_get;
  1432. ca91cx42_bridge->slave_set = ca91cx42_slave_set;
  1433. ca91cx42_bridge->master_get = ca91cx42_master_get;
  1434. ca91cx42_bridge->master_set = ca91cx42_master_set;
  1435. ca91cx42_bridge->master_read = ca91cx42_master_read;
  1436. ca91cx42_bridge->master_write = ca91cx42_master_write;
  1437. ca91cx42_bridge->master_rmw = ca91cx42_master_rmw;
  1438. ca91cx42_bridge->dma_list_add = ca91cx42_dma_list_add;
  1439. ca91cx42_bridge->dma_list_exec = ca91cx42_dma_list_exec;
  1440. ca91cx42_bridge->dma_list_empty = ca91cx42_dma_list_empty;
  1441. ca91cx42_bridge->irq_set = ca91cx42_irq_set;
  1442. ca91cx42_bridge->irq_generate = ca91cx42_irq_generate;
  1443. ca91cx42_bridge->lm_set = ca91cx42_lm_set;
  1444. ca91cx42_bridge->lm_get = ca91cx42_lm_get;
  1445. ca91cx42_bridge->lm_attach = ca91cx42_lm_attach;
  1446. ca91cx42_bridge->lm_detach = ca91cx42_lm_detach;
  1447. ca91cx42_bridge->slot_get = ca91cx42_slot_get;
  1448. ca91cx42_bridge->alloc_consistent = ca91cx42_alloc_consistent;
  1449. ca91cx42_bridge->free_consistent = ca91cx42_free_consistent;
  1450. data = ioread32(ca91cx42_device->base + MISC_CTL);
  1451. dev_info(&pdev->dev, "Board is%s the VME system controller\n",
  1452. (data & CA91CX42_MISC_CTL_SYSCON) ? "" : " not");
  1453. dev_info(&pdev->dev, "Slot ID is %d\n",
  1454. ca91cx42_slot_get(ca91cx42_bridge));
  1455. if (ca91cx42_crcsr_init(ca91cx42_bridge, pdev))
  1456. dev_err(&pdev->dev, "CR/CSR configuration failed.\n");
  1457. /* Need to save ca91cx42_bridge pointer locally in link list for use in
  1458. * ca91cx42_remove()
  1459. */
  1460. retval = vme_register_bridge(ca91cx42_bridge);
  1461. if (retval != 0) {
  1462. dev_err(&pdev->dev, "Chip Registration failed.\n");
  1463. goto err_reg;
  1464. }
  1465. pci_set_drvdata(pdev, ca91cx42_bridge);
  1466. return 0;
  1467. err_reg:
  1468. ca91cx42_crcsr_exit(ca91cx42_bridge, pdev);
  1469. err_lm:
  1470. /* resources are stored in link list */
  1471. list_for_each_safe(pos, n, &ca91cx42_bridge->lm_resources) {
  1472. lm = list_entry(pos, struct vme_lm_resource, list);
  1473. list_del(pos);
  1474. kfree(lm);
  1475. }
  1476. err_dma:
  1477. /* resources are stored in link list */
  1478. list_for_each_safe(pos, n, &ca91cx42_bridge->dma_resources) {
  1479. dma_ctrlr = list_entry(pos, struct vme_dma_resource, list);
  1480. list_del(pos);
  1481. kfree(dma_ctrlr);
  1482. }
  1483. err_slave:
  1484. /* resources are stored in link list */
  1485. list_for_each_safe(pos, n, &ca91cx42_bridge->slave_resources) {
  1486. slave_image = list_entry(pos, struct vme_slave_resource, list);
  1487. list_del(pos);
  1488. kfree(slave_image);
  1489. }
  1490. err_master:
  1491. /* resources are stored in link list */
  1492. list_for_each_safe(pos, n, &ca91cx42_bridge->master_resources) {
  1493. master_image = list_entry(pos, struct vme_master_resource,
  1494. list);
  1495. list_del(pos);
  1496. kfree(master_image);
  1497. }
  1498. ca91cx42_irq_exit(ca91cx42_device, pdev);
  1499. err_irq:
  1500. err_test:
  1501. iounmap(ca91cx42_device->base);
  1502. err_remap:
  1503. pci_release_regions(pdev);
  1504. err_resource:
  1505. pci_disable_device(pdev);
  1506. err_enable:
  1507. kfree(ca91cx42_device);
  1508. err_driver:
  1509. kfree(ca91cx42_bridge);
  1510. err_struct:
  1511. return retval;
  1512. }
  1513. static void ca91cx42_remove(struct pci_dev *pdev)
  1514. {
  1515. struct list_head *pos = NULL, *n;
  1516. struct vme_master_resource *master_image;
  1517. struct vme_slave_resource *slave_image;
  1518. struct vme_dma_resource *dma_ctrlr;
  1519. struct vme_lm_resource *lm;
  1520. struct ca91cx42_driver *bridge;
  1521. struct vme_bridge *ca91cx42_bridge = pci_get_drvdata(pdev);
  1522. bridge = ca91cx42_bridge->driver_priv;
  1523. /* Turn off Ints */
  1524. iowrite32(0, bridge->base + LINT_EN);
  1525. /* Turn off the windows */
  1526. iowrite32(0x00800000, bridge->base + LSI0_CTL);
  1527. iowrite32(0x00800000, bridge->base + LSI1_CTL);
  1528. iowrite32(0x00800000, bridge->base + LSI2_CTL);
  1529. iowrite32(0x00800000, bridge->base + LSI3_CTL);
  1530. iowrite32(0x00800000, bridge->base + LSI4_CTL);
  1531. iowrite32(0x00800000, bridge->base + LSI5_CTL);
  1532. iowrite32(0x00800000, bridge->base + LSI6_CTL);
  1533. iowrite32(0x00800000, bridge->base + LSI7_CTL);
  1534. iowrite32(0x00F00000, bridge->base + VSI0_CTL);
  1535. iowrite32(0x00F00000, bridge->base + VSI1_CTL);
  1536. iowrite32(0x00F00000, bridge->base + VSI2_CTL);
  1537. iowrite32(0x00F00000, bridge->base + VSI3_CTL);
  1538. iowrite32(0x00F00000, bridge->base + VSI4_CTL);
  1539. iowrite32(0x00F00000, bridge->base + VSI5_CTL);
  1540. iowrite32(0x00F00000, bridge->base + VSI6_CTL);
  1541. iowrite32(0x00F00000, bridge->base + VSI7_CTL);
  1542. vme_unregister_bridge(ca91cx42_bridge);
  1543. ca91cx42_crcsr_exit(ca91cx42_bridge, pdev);
  1544. /* resources are stored in link list */
  1545. list_for_each_safe(pos, n, &ca91cx42_bridge->lm_resources) {
  1546. lm = list_entry(pos, struct vme_lm_resource, list);
  1547. list_del(pos);
  1548. kfree(lm);
  1549. }
  1550. /* resources are stored in link list */
  1551. list_for_each_safe(pos, n, &ca91cx42_bridge->dma_resources) {
  1552. dma_ctrlr = list_entry(pos, struct vme_dma_resource, list);
  1553. list_del(pos);
  1554. kfree(dma_ctrlr);
  1555. }
  1556. /* resources are stored in link list */
  1557. list_for_each_safe(pos, n, &ca91cx42_bridge->slave_resources) {
  1558. slave_image = list_entry(pos, struct vme_slave_resource, list);
  1559. list_del(pos);
  1560. kfree(slave_image);
  1561. }
  1562. /* resources are stored in link list */
  1563. list_for_each_safe(pos, n, &ca91cx42_bridge->master_resources) {
  1564. master_image = list_entry(pos, struct vme_master_resource,
  1565. list);
  1566. list_del(pos);
  1567. kfree(master_image);
  1568. }
  1569. ca91cx42_irq_exit(bridge, pdev);
  1570. iounmap(bridge->base);
  1571. pci_release_regions(pdev);
  1572. pci_disable_device(pdev);
  1573. kfree(ca91cx42_bridge);
  1574. }
  1575. module_pci_driver(ca91cx42_driver);
  1576. MODULE_PARM_DESC(geoid, "Override geographical addressing");
  1577. module_param(geoid, int, 0);
  1578. MODULE_DESCRIPTION("VME driver for the Tundra Universe II VME bridge");
  1579. MODULE_LICENSE("GPL");