omap_dma.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079
  1. /*
  2. * TI OMAP DMA gigacell.
  3. *
  4. * Copyright (C) 2006-2008 Andrzej Zaborowski <balrog@zabor.org>
  5. * Copyright (C) 2007-2008 Lauro Ramos Venancio <lauro.venancio@indt.org.br>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. */
  21. #include "qemu-common.h"
  22. #include "qemu-timer.h"
  23. #include "omap.h"
  24. #include "irq.h"
  25. #include "soc_dma.h"
  26. struct omap_dma_channel_s {
  27. /* transfer data */
  28. int burst[2];
  29. int pack[2];
  30. int endian[2];
  31. int endian_lock[2];
  32. int translate[2];
  33. enum omap_dma_port port[2];
  34. target_phys_addr_t addr[2];
  35. omap_dma_addressing_t mode[2];
  36. uint32_t elements;
  37. uint16_t frames;
  38. int32_t frame_index[2];
  39. int16_t element_index[2];
  40. int data_type;
  41. /* transfer type */
  42. int transparent_copy;
  43. int constant_fill;
  44. uint32_t color;
  45. int prefetch;
  46. /* auto init and linked channel data */
  47. int end_prog;
  48. int repeat;
  49. int auto_init;
  50. int link_enabled;
  51. int link_next_ch;
  52. /* interruption data */
  53. int interrupts;
  54. int status;
  55. int cstatus;
  56. /* state data */
  57. int active;
  58. int enable;
  59. int sync;
  60. int src_sync;
  61. int pending_request;
  62. int waiting_end_prog;
  63. uint16_t cpc;
  64. int set_update;
  65. /* sync type */
  66. int fs;
  67. int bs;
  68. /* compatibility */
  69. int omap_3_1_compatible_disable;
  70. qemu_irq irq;
  71. struct omap_dma_channel_s *sibling;
  72. struct omap_dma_reg_set_s {
  73. target_phys_addr_t src, dest;
  74. int frame;
  75. int element;
  76. int pck_element;
  77. int frame_delta[2];
  78. int elem_delta[2];
  79. int frames;
  80. int elements;
  81. int pck_elements;
  82. } active_set;
  83. struct soc_dma_ch_s *dma;
  84. /* unused parameters */
  85. int write_mode;
  86. int priority;
  87. int interleave_disabled;
  88. int type;
  89. int suspend;
  90. int buf_disable;
  91. };
  92. struct omap_dma_s {
  93. struct soc_dma_s *dma;
  94. struct omap_mpu_state_s *mpu;
  95. omap_clk clk;
  96. qemu_irq irq[4];
  97. void (*intr_update)(struct omap_dma_s *s);
  98. enum omap_dma_model model;
  99. int omap_3_1_mapping_disabled;
  100. uint32_t gcr;
  101. uint32_t ocp;
  102. uint32_t caps[5];
  103. uint32_t irqen[4];
  104. uint32_t irqstat[4];
  105. int chans;
  106. struct omap_dma_channel_s ch[32];
  107. struct omap_dma_lcd_channel_s lcd_ch;
  108. };
  109. /* Interrupts */
  110. #define TIMEOUT_INTR (1 << 0)
  111. #define EVENT_DROP_INTR (1 << 1)
  112. #define HALF_FRAME_INTR (1 << 2)
  113. #define END_FRAME_INTR (1 << 3)
  114. #define LAST_FRAME_INTR (1 << 4)
  115. #define END_BLOCK_INTR (1 << 5)
  116. #define SYNC (1 << 6)
  117. #define END_PKT_INTR (1 << 7)
  118. #define TRANS_ERR_INTR (1 << 8)
  119. #define MISALIGN_INTR (1 << 11)
  120. static inline void omap_dma_interrupts_update(struct omap_dma_s *s)
  121. {
  122. return s->intr_update(s);
  123. }
  124. static void omap_dma_channel_load(struct omap_dma_channel_s *ch)
  125. {
  126. struct omap_dma_reg_set_s *a = &ch->active_set;
  127. int i, normal;
  128. int omap_3_1 = !ch->omap_3_1_compatible_disable;
  129. /*
  130. * TODO: verify address ranges and alignment
  131. * TODO: port endianness
  132. */
  133. a->src = ch->addr[0];
  134. a->dest = ch->addr[1];
  135. a->frames = ch->frames;
  136. a->elements = ch->elements;
  137. a->pck_elements = ch->frame_index[!ch->src_sync];
  138. a->frame = 0;
  139. a->element = 0;
  140. a->pck_element = 0;
  141. if (unlikely(!ch->elements || !ch->frames)) {
  142. printf("%s: bad DMA request\n", __FUNCTION__);
  143. return;
  144. }
  145. for (i = 0; i < 2; i ++)
  146. switch (ch->mode[i]) {
  147. case constant:
  148. a->elem_delta[i] = 0;
  149. a->frame_delta[i] = 0;
  150. break;
  151. case post_incremented:
  152. a->elem_delta[i] = ch->data_type;
  153. a->frame_delta[i] = 0;
  154. break;
  155. case single_index:
  156. a->elem_delta[i] = ch->data_type +
  157. ch->element_index[omap_3_1 ? 0 : i] - 1;
  158. a->frame_delta[i] = 0;
  159. break;
  160. case double_index:
  161. a->elem_delta[i] = ch->data_type +
  162. ch->element_index[omap_3_1 ? 0 : i] - 1;
  163. a->frame_delta[i] = ch->frame_index[omap_3_1 ? 0 : i] -
  164. ch->element_index[omap_3_1 ? 0 : i];
  165. break;
  166. default:
  167. break;
  168. }
  169. normal = !ch->transparent_copy && !ch->constant_fill &&
  170. /* FIFO is big-endian so either (ch->endian[n] == 1) OR
  171. * (ch->endian_lock[n] == 1) mean no endianism conversion. */
  172. (ch->endian[0] | ch->endian_lock[0]) ==
  173. (ch->endian[1] | ch->endian_lock[1]);
  174. for (i = 0; i < 2; i ++) {
  175. /* TODO: for a->frame_delta[i] > 0 still use the fast path, just
  176. * limit min_elems in omap_dma_transfer_setup to the nearest frame
  177. * end. */
  178. if (!a->elem_delta[i] && normal &&
  179. (a->frames == 1 || !a->frame_delta[i]))
  180. ch->dma->type[i] = soc_dma_access_const;
  181. else if (a->elem_delta[i] == ch->data_type && normal &&
  182. (a->frames == 1 || !a->frame_delta[i]))
  183. ch->dma->type[i] = soc_dma_access_linear;
  184. else
  185. ch->dma->type[i] = soc_dma_access_other;
  186. ch->dma->vaddr[i] = ch->addr[i];
  187. }
  188. soc_dma_ch_update(ch->dma);
  189. }
  190. static void omap_dma_activate_channel(struct omap_dma_s *s,
  191. struct omap_dma_channel_s *ch)
  192. {
  193. if (!ch->active) {
  194. if (ch->set_update) {
  195. /* It's not clear when the active set is supposed to be
  196. * loaded from registers. We're already loading it when the
  197. * channel is enabled, and for some guests this is not enough
  198. * but that may be also because of a race condition (no
  199. * delays in qemu) in the guest code, which we're just
  200. * working around here. */
  201. omap_dma_channel_load(ch);
  202. ch->set_update = 0;
  203. }
  204. ch->active = 1;
  205. soc_dma_set_request(ch->dma, 1);
  206. if (ch->sync)
  207. ch->status |= SYNC;
  208. }
  209. }
  210. static void omap_dma_deactivate_channel(struct omap_dma_s *s,
  211. struct omap_dma_channel_s *ch)
  212. {
  213. /* Update cpc */
  214. ch->cpc = ch->active_set.dest & 0xffff;
  215. if (ch->pending_request && !ch->waiting_end_prog && ch->enable) {
  216. /* Don't deactivate the channel */
  217. ch->pending_request = 0;
  218. return;
  219. }
  220. /* Don't deactive the channel if it is synchronized and the DMA request is
  221. active */
  222. if (ch->sync && ch->enable && (s->dma->drqbmp & (1 << ch->sync)))
  223. return;
  224. if (ch->active) {
  225. ch->active = 0;
  226. ch->status &= ~SYNC;
  227. soc_dma_set_request(ch->dma, 0);
  228. }
  229. }
  230. static void omap_dma_enable_channel(struct omap_dma_s *s,
  231. struct omap_dma_channel_s *ch)
  232. {
  233. if (!ch->enable) {
  234. ch->enable = 1;
  235. ch->waiting_end_prog = 0;
  236. omap_dma_channel_load(ch);
  237. /* TODO: theoretically if ch->sync && ch->prefetch &&
  238. * !s->dma->drqbmp[ch->sync], we should also activate and fetch
  239. * from source and then stall until signalled. */
  240. if ((!ch->sync) || (s->dma->drqbmp & (1 << ch->sync)))
  241. omap_dma_activate_channel(s, ch);
  242. }
  243. }
  244. static void omap_dma_disable_channel(struct omap_dma_s *s,
  245. struct omap_dma_channel_s *ch)
  246. {
  247. if (ch->enable) {
  248. ch->enable = 0;
  249. /* Discard any pending request */
  250. ch->pending_request = 0;
  251. omap_dma_deactivate_channel(s, ch);
  252. }
  253. }
  254. static void omap_dma_channel_end_prog(struct omap_dma_s *s,
  255. struct omap_dma_channel_s *ch)
  256. {
  257. if (ch->waiting_end_prog) {
  258. ch->waiting_end_prog = 0;
  259. if (!ch->sync || ch->pending_request) {
  260. ch->pending_request = 0;
  261. omap_dma_activate_channel(s, ch);
  262. }
  263. }
  264. }
  265. static void omap_dma_interrupts_3_1_update(struct omap_dma_s *s)
  266. {
  267. struct omap_dma_channel_s *ch = s->ch;
  268. /* First three interrupts are shared between two channels each. */
  269. if (ch[0].status | ch[6].status)
  270. qemu_irq_raise(ch[0].irq);
  271. if (ch[1].status | ch[7].status)
  272. qemu_irq_raise(ch[1].irq);
  273. if (ch[2].status | ch[8].status)
  274. qemu_irq_raise(ch[2].irq);
  275. if (ch[3].status)
  276. qemu_irq_raise(ch[3].irq);
  277. if (ch[4].status)
  278. qemu_irq_raise(ch[4].irq);
  279. if (ch[5].status)
  280. qemu_irq_raise(ch[5].irq);
  281. }
  282. static void omap_dma_interrupts_3_2_update(struct omap_dma_s *s)
  283. {
  284. struct omap_dma_channel_s *ch = s->ch;
  285. int i;
  286. for (i = s->chans; i; ch ++, i --)
  287. if (ch->status)
  288. qemu_irq_raise(ch->irq);
  289. }
  290. static void omap_dma_enable_3_1_mapping(struct omap_dma_s *s)
  291. {
  292. s->omap_3_1_mapping_disabled = 0;
  293. s->chans = 9;
  294. s->intr_update = omap_dma_interrupts_3_1_update;
  295. }
  296. static void omap_dma_disable_3_1_mapping(struct omap_dma_s *s)
  297. {
  298. s->omap_3_1_mapping_disabled = 1;
  299. s->chans = 16;
  300. s->intr_update = omap_dma_interrupts_3_2_update;
  301. }
  302. static void omap_dma_process_request(struct omap_dma_s *s, int request)
  303. {
  304. int channel;
  305. int drop_event = 0;
  306. struct omap_dma_channel_s *ch = s->ch;
  307. for (channel = 0; channel < s->chans; channel ++, ch ++) {
  308. if (ch->enable && ch->sync == request) {
  309. if (!ch->active)
  310. omap_dma_activate_channel(s, ch);
  311. else if (!ch->pending_request)
  312. ch->pending_request = 1;
  313. else {
  314. /* Request collision */
  315. /* Second request received while processing other request */
  316. ch->status |= EVENT_DROP_INTR;
  317. drop_event = 1;
  318. }
  319. }
  320. }
  321. if (drop_event)
  322. omap_dma_interrupts_update(s);
  323. }
  324. static void omap_dma_transfer_generic(struct soc_dma_ch_s *dma)
  325. {
  326. uint8_t value[4];
  327. struct omap_dma_channel_s *ch = dma->opaque;
  328. struct omap_dma_reg_set_s *a = &ch->active_set;
  329. int bytes = dma->bytes;
  330. #ifdef MULTI_REQ
  331. uint16_t status = ch->status;
  332. #endif
  333. do {
  334. /* Transfer a single element */
  335. /* FIXME: check the endianness */
  336. if (!ch->constant_fill)
  337. cpu_physical_memory_read(a->src, value, ch->data_type);
  338. else
  339. *(uint32_t *) value = ch->color;
  340. if (!ch->transparent_copy || *(uint32_t *) value != ch->color)
  341. cpu_physical_memory_write(a->dest, value, ch->data_type);
  342. a->src += a->elem_delta[0];
  343. a->dest += a->elem_delta[1];
  344. a->element ++;
  345. #ifndef MULTI_REQ
  346. if (a->element == a->elements) {
  347. /* End of Frame */
  348. a->element = 0;
  349. a->src += a->frame_delta[0];
  350. a->dest += a->frame_delta[1];
  351. a->frame ++;
  352. /* If the channel is async, update cpc */
  353. if (!ch->sync)
  354. ch->cpc = a->dest & 0xffff;
  355. }
  356. } while ((bytes -= ch->data_type));
  357. #else
  358. /* If the channel is element synchronized, deactivate it */
  359. if (ch->sync && !ch->fs && !ch->bs)
  360. omap_dma_deactivate_channel(s, ch);
  361. /* If it is the last frame, set the LAST_FRAME interrupt */
  362. if (a->element == 1 && a->frame == a->frames - 1)
  363. if (ch->interrupts & LAST_FRAME_INTR)
  364. ch->status |= LAST_FRAME_INTR;
  365. /* If the half of the frame was reached, set the HALF_FRAME
  366. interrupt */
  367. if (a->element == (a->elements >> 1))
  368. if (ch->interrupts & HALF_FRAME_INTR)
  369. ch->status |= HALF_FRAME_INTR;
  370. if (ch->fs && ch->bs) {
  371. a->pck_element ++;
  372. /* Check if a full packet has beed transferred. */
  373. if (a->pck_element == a->pck_elements) {
  374. a->pck_element = 0;
  375. /* Set the END_PKT interrupt */
  376. if ((ch->interrupts & END_PKT_INTR) && !ch->src_sync)
  377. ch->status |= END_PKT_INTR;
  378. /* If the channel is packet-synchronized, deactivate it */
  379. if (ch->sync)
  380. omap_dma_deactivate_channel(s, ch);
  381. }
  382. }
  383. if (a->element == a->elements) {
  384. /* End of Frame */
  385. a->element = 0;
  386. a->src += a->frame_delta[0];
  387. a->dest += a->frame_delta[1];
  388. a->frame ++;
  389. /* If the channel is frame synchronized, deactivate it */
  390. if (ch->sync && ch->fs && !ch->bs)
  391. omap_dma_deactivate_channel(s, ch);
  392. /* If the channel is async, update cpc */
  393. if (!ch->sync)
  394. ch->cpc = a->dest & 0xffff;
  395. /* Set the END_FRAME interrupt */
  396. if (ch->interrupts & END_FRAME_INTR)
  397. ch->status |= END_FRAME_INTR;
  398. if (a->frame == a->frames) {
  399. /* End of Block */
  400. /* Disable the channel */
  401. if (ch->omap_3_1_compatible_disable) {
  402. omap_dma_disable_channel(s, ch);
  403. if (ch->link_enabled)
  404. omap_dma_enable_channel(s,
  405. &s->ch[ch->link_next_ch]);
  406. } else {
  407. if (!ch->auto_init)
  408. omap_dma_disable_channel(s, ch);
  409. else if (ch->repeat || ch->end_prog)
  410. omap_dma_channel_load(ch);
  411. else {
  412. ch->waiting_end_prog = 1;
  413. omap_dma_deactivate_channel(s, ch);
  414. }
  415. }
  416. if (ch->interrupts & END_BLOCK_INTR)
  417. ch->status |= END_BLOCK_INTR;
  418. }
  419. }
  420. } while (status == ch->status && ch->active);
  421. omap_dma_interrupts_update(s);
  422. #endif
  423. }
  424. enum {
  425. omap_dma_intr_element_sync,
  426. omap_dma_intr_last_frame,
  427. omap_dma_intr_half_frame,
  428. omap_dma_intr_frame,
  429. omap_dma_intr_frame_sync,
  430. omap_dma_intr_packet,
  431. omap_dma_intr_packet_sync,
  432. omap_dma_intr_block,
  433. __omap_dma_intr_last,
  434. };
  435. static void omap_dma_transfer_setup(struct soc_dma_ch_s *dma)
  436. {
  437. struct omap_dma_port_if_s *src_p, *dest_p;
  438. struct omap_dma_reg_set_s *a;
  439. struct omap_dma_channel_s *ch = dma->opaque;
  440. struct omap_dma_s *s = dma->dma->opaque;
  441. int frames, min_elems, elements[__omap_dma_intr_last];
  442. a = &ch->active_set;
  443. src_p = &s->mpu->port[ch->port[0]];
  444. dest_p = &s->mpu->port[ch->port[1]];
  445. if ((!ch->constant_fill && !src_p->addr_valid(s->mpu, a->src)) ||
  446. (!dest_p->addr_valid(s->mpu, a->dest))) {
  447. #if 0
  448. /* Bus time-out */
  449. if (ch->interrupts & TIMEOUT_INTR)
  450. ch->status |= TIMEOUT_INTR;
  451. omap_dma_deactivate_channel(s, ch);
  452. continue;
  453. #endif
  454. printf("%s: Bus time-out in DMA%i operation\n",
  455. __FUNCTION__, dma->num);
  456. }
  457. min_elems = INT_MAX;
  458. /* Check all the conditions that terminate the transfer starting
  459. * with those that can occur the soonest. */
  460. #define INTR_CHECK(cond, id, nelements) \
  461. if (cond) { \
  462. elements[id] = nelements; \
  463. if (elements[id] < min_elems) \
  464. min_elems = elements[id]; \
  465. } else \
  466. elements[id] = INT_MAX;
  467. /* Elements */
  468. INTR_CHECK(
  469. ch->sync && !ch->fs && !ch->bs,
  470. omap_dma_intr_element_sync,
  471. 1)
  472. /* Frames */
  473. /* TODO: for transfers where entire frames can be read and written
  474. * using memcpy() but a->frame_delta is non-zero, try to still do
  475. * transfers using soc_dma but limit min_elems to a->elements - ...
  476. * See also the TODO in omap_dma_channel_load. */
  477. INTR_CHECK(
  478. (ch->interrupts & LAST_FRAME_INTR) &&
  479. ((a->frame < a->frames - 1) || !a->element),
  480. omap_dma_intr_last_frame,
  481. (a->frames - a->frame - 2) * a->elements +
  482. (a->elements - a->element + 1))
  483. INTR_CHECK(
  484. ch->interrupts & HALF_FRAME_INTR,
  485. omap_dma_intr_half_frame,
  486. (a->elements >> 1) +
  487. (a->element >= (a->elements >> 1) ? a->elements : 0) -
  488. a->element)
  489. INTR_CHECK(
  490. ch->sync && ch->fs && (ch->interrupts & END_FRAME_INTR),
  491. omap_dma_intr_frame,
  492. a->elements - a->element)
  493. INTR_CHECK(
  494. ch->sync && ch->fs && !ch->bs,
  495. omap_dma_intr_frame_sync,
  496. a->elements - a->element)
  497. /* Packets */
  498. INTR_CHECK(
  499. ch->fs && ch->bs &&
  500. (ch->interrupts & END_PKT_INTR) && !ch->src_sync,
  501. omap_dma_intr_packet,
  502. a->pck_elements - a->pck_element)
  503. INTR_CHECK(
  504. ch->fs && ch->bs && ch->sync,
  505. omap_dma_intr_packet_sync,
  506. a->pck_elements - a->pck_element)
  507. /* Blocks */
  508. INTR_CHECK(
  509. 1,
  510. omap_dma_intr_block,
  511. (a->frames - a->frame - 1) * a->elements +
  512. (a->elements - a->element))
  513. dma->bytes = min_elems * ch->data_type;
  514. /* Set appropriate interrupts and/or deactivate channels */
  515. #ifdef MULTI_REQ
  516. /* TODO: should all of this only be done if dma->update, and otherwise
  517. * inside omap_dma_transfer_generic below - check what's faster. */
  518. if (dma->update) {
  519. #endif
  520. /* If the channel is element synchronized, deactivate it */
  521. if (min_elems == elements[omap_dma_intr_element_sync])
  522. omap_dma_deactivate_channel(s, ch);
  523. /* If it is the last frame, set the LAST_FRAME interrupt */
  524. if (min_elems == elements[omap_dma_intr_last_frame])
  525. ch->status |= LAST_FRAME_INTR;
  526. /* If exactly half of the frame was reached, set the HALF_FRAME
  527. interrupt */
  528. if (min_elems == elements[omap_dma_intr_half_frame])
  529. ch->status |= HALF_FRAME_INTR;
  530. /* If a full packet has been transferred, set the END_PKT interrupt */
  531. if (min_elems == elements[omap_dma_intr_packet])
  532. ch->status |= END_PKT_INTR;
  533. /* If the channel is packet-synchronized, deactivate it */
  534. if (min_elems == elements[omap_dma_intr_packet_sync])
  535. omap_dma_deactivate_channel(s, ch);
  536. /* If the channel is frame synchronized, deactivate it */
  537. if (min_elems == elements[omap_dma_intr_frame_sync])
  538. omap_dma_deactivate_channel(s, ch);
  539. /* Set the END_FRAME interrupt */
  540. if (min_elems == elements[omap_dma_intr_frame])
  541. ch->status |= END_FRAME_INTR;
  542. if (min_elems == elements[omap_dma_intr_block]) {
  543. /* End of Block */
  544. /* Disable the channel */
  545. if (ch->omap_3_1_compatible_disable) {
  546. omap_dma_disable_channel(s, ch);
  547. if (ch->link_enabled)
  548. omap_dma_enable_channel(s, &s->ch[ch->link_next_ch]);
  549. } else {
  550. if (!ch->auto_init)
  551. omap_dma_disable_channel(s, ch);
  552. else if (ch->repeat || ch->end_prog)
  553. omap_dma_channel_load(ch);
  554. else {
  555. ch->waiting_end_prog = 1;
  556. omap_dma_deactivate_channel(s, ch);
  557. }
  558. }
  559. if (ch->interrupts & END_BLOCK_INTR)
  560. ch->status |= END_BLOCK_INTR;
  561. }
  562. /* Update packet number */
  563. if (ch->fs && ch->bs) {
  564. a->pck_element += min_elems;
  565. a->pck_element %= a->pck_elements;
  566. }
  567. /* TODO: check if we really need to update anything here or perhaps we
  568. * can skip part of this. */
  569. #ifndef MULTI_REQ
  570. if (dma->update) {
  571. #endif
  572. a->element += min_elems;
  573. frames = a->element / a->elements;
  574. a->element = a->element % a->elements;
  575. a->frame += frames;
  576. a->src += min_elems * a->elem_delta[0] + frames * a->frame_delta[0];
  577. a->dest += min_elems * a->elem_delta[1] + frames * a->frame_delta[1];
  578. /* If the channel is async, update cpc */
  579. if (!ch->sync && frames)
  580. ch->cpc = a->dest & 0xffff;
  581. /* TODO: if the destination port is IMIF or EMIFF, set the dirty
  582. * bits on it. */
  583. }
  584. omap_dma_interrupts_update(s);
  585. }
  586. void omap_dma_reset(struct soc_dma_s *dma)
  587. {
  588. int i;
  589. struct omap_dma_s *s = dma->opaque;
  590. soc_dma_reset(s->dma);
  591. if (s->model < omap_dma_4)
  592. s->gcr = 0x0004;
  593. else
  594. s->gcr = 0x00010010;
  595. s->ocp = 0x00000000;
  596. memset(&s->irqstat, 0, sizeof(s->irqstat));
  597. memset(&s->irqen, 0, sizeof(s->irqen));
  598. s->lcd_ch.src = emiff;
  599. s->lcd_ch.condition = 0;
  600. s->lcd_ch.interrupts = 0;
  601. s->lcd_ch.dual = 0;
  602. if (s->model < omap_dma_4)
  603. omap_dma_enable_3_1_mapping(s);
  604. for (i = 0; i < s->chans; i ++) {
  605. s->ch[i].suspend = 0;
  606. s->ch[i].prefetch = 0;
  607. s->ch[i].buf_disable = 0;
  608. s->ch[i].src_sync = 0;
  609. memset(&s->ch[i].burst, 0, sizeof(s->ch[i].burst));
  610. memset(&s->ch[i].port, 0, sizeof(s->ch[i].port));
  611. memset(&s->ch[i].mode, 0, sizeof(s->ch[i].mode));
  612. memset(&s->ch[i].frame_index, 0, sizeof(s->ch[i].frame_index));
  613. memset(&s->ch[i].element_index, 0, sizeof(s->ch[i].element_index));
  614. memset(&s->ch[i].endian, 0, sizeof(s->ch[i].endian));
  615. memset(&s->ch[i].endian_lock, 0, sizeof(s->ch[i].endian_lock));
  616. memset(&s->ch[i].translate, 0, sizeof(s->ch[i].translate));
  617. s->ch[i].write_mode = 0;
  618. s->ch[i].data_type = 0;
  619. s->ch[i].transparent_copy = 0;
  620. s->ch[i].constant_fill = 0;
  621. s->ch[i].color = 0x00000000;
  622. s->ch[i].end_prog = 0;
  623. s->ch[i].repeat = 0;
  624. s->ch[i].auto_init = 0;
  625. s->ch[i].link_enabled = 0;
  626. if (s->model < omap_dma_4)
  627. s->ch[i].interrupts = 0x0003;
  628. else
  629. s->ch[i].interrupts = 0x0000;
  630. s->ch[i].status = 0;
  631. s->ch[i].cstatus = 0;
  632. s->ch[i].active = 0;
  633. s->ch[i].enable = 0;
  634. s->ch[i].sync = 0;
  635. s->ch[i].pending_request = 0;
  636. s->ch[i].waiting_end_prog = 0;
  637. s->ch[i].cpc = 0x0000;
  638. s->ch[i].fs = 0;
  639. s->ch[i].bs = 0;
  640. s->ch[i].omap_3_1_compatible_disable = 0;
  641. memset(&s->ch[i].active_set, 0, sizeof(s->ch[i].active_set));
  642. s->ch[i].priority = 0;
  643. s->ch[i].interleave_disabled = 0;
  644. s->ch[i].type = 0;
  645. }
  646. }
  647. static int omap_dma_ch_reg_read(struct omap_dma_s *s,
  648. struct omap_dma_channel_s *ch, int reg, uint16_t *value)
  649. {
  650. switch (reg) {
  651. case 0x00: /* SYS_DMA_CSDP_CH0 */
  652. *value = (ch->burst[1] << 14) |
  653. (ch->pack[1] << 13) |
  654. (ch->port[1] << 9) |
  655. (ch->burst[0] << 7) |
  656. (ch->pack[0] << 6) |
  657. (ch->port[0] << 2) |
  658. (ch->data_type >> 1);
  659. break;
  660. case 0x02: /* SYS_DMA_CCR_CH0 */
  661. if (s->model <= omap_dma_3_1)
  662. *value = 0 << 10; /* FIFO_FLUSH reads as 0 */
  663. else
  664. *value = ch->omap_3_1_compatible_disable << 10;
  665. *value |= (ch->mode[1] << 14) |
  666. (ch->mode[0] << 12) |
  667. (ch->end_prog << 11) |
  668. (ch->repeat << 9) |
  669. (ch->auto_init << 8) |
  670. (ch->enable << 7) |
  671. (ch->priority << 6) |
  672. (ch->fs << 5) | ch->sync;
  673. break;
  674. case 0x04: /* SYS_DMA_CICR_CH0 */
  675. *value = ch->interrupts;
  676. break;
  677. case 0x06: /* SYS_DMA_CSR_CH0 */
  678. *value = ch->status;
  679. ch->status &= SYNC;
  680. if (!ch->omap_3_1_compatible_disable && ch->sibling) {
  681. *value |= (ch->sibling->status & 0x3f) << 6;
  682. ch->sibling->status &= SYNC;
  683. }
  684. qemu_irq_lower(ch->irq);
  685. break;
  686. case 0x08: /* SYS_DMA_CSSA_L_CH0 */
  687. *value = ch->addr[0] & 0x0000ffff;
  688. break;
  689. case 0x0a: /* SYS_DMA_CSSA_U_CH0 */
  690. *value = ch->addr[0] >> 16;
  691. break;
  692. case 0x0c: /* SYS_DMA_CDSA_L_CH0 */
  693. *value = ch->addr[1] & 0x0000ffff;
  694. break;
  695. case 0x0e: /* SYS_DMA_CDSA_U_CH0 */
  696. *value = ch->addr[1] >> 16;
  697. break;
  698. case 0x10: /* SYS_DMA_CEN_CH0 */
  699. *value = ch->elements;
  700. break;
  701. case 0x12: /* SYS_DMA_CFN_CH0 */
  702. *value = ch->frames;
  703. break;
  704. case 0x14: /* SYS_DMA_CFI_CH0 */
  705. *value = ch->frame_index[0];
  706. break;
  707. case 0x16: /* SYS_DMA_CEI_CH0 */
  708. *value = ch->element_index[0];
  709. break;
  710. case 0x18: /* SYS_DMA_CPC_CH0 or DMA_CSAC */
  711. if (ch->omap_3_1_compatible_disable)
  712. *value = ch->active_set.src & 0xffff; /* CSAC */
  713. else
  714. *value = ch->cpc;
  715. break;
  716. case 0x1a: /* DMA_CDAC */
  717. *value = ch->active_set.dest & 0xffff; /* CDAC */
  718. break;
  719. case 0x1c: /* DMA_CDEI */
  720. *value = ch->element_index[1];
  721. break;
  722. case 0x1e: /* DMA_CDFI */
  723. *value = ch->frame_index[1];
  724. break;
  725. case 0x20: /* DMA_COLOR_L */
  726. *value = ch->color & 0xffff;
  727. break;
  728. case 0x22: /* DMA_COLOR_U */
  729. *value = ch->color >> 16;
  730. break;
  731. case 0x24: /* DMA_CCR2 */
  732. *value = (ch->bs << 2) |
  733. (ch->transparent_copy << 1) |
  734. ch->constant_fill;
  735. break;
  736. case 0x28: /* DMA_CLNK_CTRL */
  737. *value = (ch->link_enabled << 15) |
  738. (ch->link_next_ch & 0xf);
  739. break;
  740. case 0x2a: /* DMA_LCH_CTRL */
  741. *value = (ch->interleave_disabled << 15) |
  742. ch->type;
  743. break;
  744. default:
  745. return 1;
  746. }
  747. return 0;
  748. }
  749. static int omap_dma_ch_reg_write(struct omap_dma_s *s,
  750. struct omap_dma_channel_s *ch, int reg, uint16_t value)
  751. {
  752. switch (reg) {
  753. case 0x00: /* SYS_DMA_CSDP_CH0 */
  754. ch->burst[1] = (value & 0xc000) >> 14;
  755. ch->pack[1] = (value & 0x2000) >> 13;
  756. ch->port[1] = (enum omap_dma_port) ((value & 0x1e00) >> 9);
  757. ch->burst[0] = (value & 0x0180) >> 7;
  758. ch->pack[0] = (value & 0x0040) >> 6;
  759. ch->port[0] = (enum omap_dma_port) ((value & 0x003c) >> 2);
  760. ch->data_type = 1 << (value & 3);
  761. if (ch->port[0] >= __omap_dma_port_last)
  762. printf("%s: invalid DMA port %i\n", __FUNCTION__,
  763. ch->port[0]);
  764. if (ch->port[1] >= __omap_dma_port_last)
  765. printf("%s: invalid DMA port %i\n", __FUNCTION__,
  766. ch->port[1]);
  767. if ((value & 3) == 3)
  768. printf("%s: bad data_type for DMA channel\n", __FUNCTION__);
  769. break;
  770. case 0x02: /* SYS_DMA_CCR_CH0 */
  771. ch->mode[1] = (omap_dma_addressing_t) ((value & 0xc000) >> 14);
  772. ch->mode[0] = (omap_dma_addressing_t) ((value & 0x3000) >> 12);
  773. ch->end_prog = (value & 0x0800) >> 11;
  774. if (s->model >= omap_dma_3_2)
  775. ch->omap_3_1_compatible_disable = (value >> 10) & 0x1;
  776. ch->repeat = (value & 0x0200) >> 9;
  777. ch->auto_init = (value & 0x0100) >> 8;
  778. ch->priority = (value & 0x0040) >> 6;
  779. ch->fs = (value & 0x0020) >> 5;
  780. ch->sync = value & 0x001f;
  781. if (value & 0x0080)
  782. omap_dma_enable_channel(s, ch);
  783. else
  784. omap_dma_disable_channel(s, ch);
  785. if (ch->end_prog)
  786. omap_dma_channel_end_prog(s, ch);
  787. break;
  788. case 0x04: /* SYS_DMA_CICR_CH0 */
  789. ch->interrupts = value & 0x3f;
  790. break;
  791. case 0x06: /* SYS_DMA_CSR_CH0 */
  792. OMAP_RO_REG((target_phys_addr_t) reg);
  793. break;
  794. case 0x08: /* SYS_DMA_CSSA_L_CH0 */
  795. ch->addr[0] &= 0xffff0000;
  796. ch->addr[0] |= value;
  797. break;
  798. case 0x0a: /* SYS_DMA_CSSA_U_CH0 */
  799. ch->addr[0] &= 0x0000ffff;
  800. ch->addr[0] |= (uint32_t) value << 16;
  801. break;
  802. case 0x0c: /* SYS_DMA_CDSA_L_CH0 */
  803. ch->addr[1] &= 0xffff0000;
  804. ch->addr[1] |= value;
  805. break;
  806. case 0x0e: /* SYS_DMA_CDSA_U_CH0 */
  807. ch->addr[1] &= 0x0000ffff;
  808. ch->addr[1] |= (uint32_t) value << 16;
  809. break;
  810. case 0x10: /* SYS_DMA_CEN_CH0 */
  811. ch->elements = value;
  812. break;
  813. case 0x12: /* SYS_DMA_CFN_CH0 */
  814. ch->frames = value;
  815. break;
  816. case 0x14: /* SYS_DMA_CFI_CH0 */
  817. ch->frame_index[0] = (int16_t) value;
  818. break;
  819. case 0x16: /* SYS_DMA_CEI_CH0 */
  820. ch->element_index[0] = (int16_t) value;
  821. break;
  822. case 0x18: /* SYS_DMA_CPC_CH0 or DMA_CSAC */
  823. OMAP_RO_REG((target_phys_addr_t) reg);
  824. break;
  825. case 0x1c: /* DMA_CDEI */
  826. ch->element_index[1] = (int16_t) value;
  827. break;
  828. case 0x1e: /* DMA_CDFI */
  829. ch->frame_index[1] = (int16_t) value;
  830. break;
  831. case 0x20: /* DMA_COLOR_L */
  832. ch->color &= 0xffff0000;
  833. ch->color |= value;
  834. break;
  835. case 0x22: /* DMA_COLOR_U */
  836. ch->color &= 0xffff;
  837. ch->color |= value << 16;
  838. break;
  839. case 0x24: /* DMA_CCR2 */
  840. ch->bs = (value >> 2) & 0x1;
  841. ch->transparent_copy = (value >> 1) & 0x1;
  842. ch->constant_fill = value & 0x1;
  843. break;
  844. case 0x28: /* DMA_CLNK_CTRL */
  845. ch->link_enabled = (value >> 15) & 0x1;
  846. if (value & (1 << 14)) { /* Stop_Lnk */
  847. ch->link_enabled = 0;
  848. omap_dma_disable_channel(s, ch);
  849. }
  850. ch->link_next_ch = value & 0x1f;
  851. break;
  852. case 0x2a: /* DMA_LCH_CTRL */
  853. ch->interleave_disabled = (value >> 15) & 0x1;
  854. ch->type = value & 0xf;
  855. break;
  856. default:
  857. return 1;
  858. }
  859. return 0;
  860. }
  861. static int omap_dma_3_2_lcd_write(struct omap_dma_lcd_channel_s *s, int offset,
  862. uint16_t value)
  863. {
  864. switch (offset) {
  865. case 0xbc0: /* DMA_LCD_CSDP */
  866. s->brust_f2 = (value >> 14) & 0x3;
  867. s->pack_f2 = (value >> 13) & 0x1;
  868. s->data_type_f2 = (1 << ((value >> 11) & 0x3));
  869. s->brust_f1 = (value >> 7) & 0x3;
  870. s->pack_f1 = (value >> 6) & 0x1;
  871. s->data_type_f1 = (1 << ((value >> 0) & 0x3));
  872. break;
  873. case 0xbc2: /* DMA_LCD_CCR */
  874. s->mode_f2 = (value >> 14) & 0x3;
  875. s->mode_f1 = (value >> 12) & 0x3;
  876. s->end_prog = (value >> 11) & 0x1;
  877. s->omap_3_1_compatible_disable = (value >> 10) & 0x1;
  878. s->repeat = (value >> 9) & 0x1;
  879. s->auto_init = (value >> 8) & 0x1;
  880. s->running = (value >> 7) & 0x1;
  881. s->priority = (value >> 6) & 0x1;
  882. s->bs = (value >> 4) & 0x1;
  883. break;
  884. case 0xbc4: /* DMA_LCD_CTRL */
  885. s->dst = (value >> 8) & 0x1;
  886. s->src = ((value >> 6) & 0x3) << 1;
  887. s->condition = 0;
  888. /* Assume no bus errors and thus no BUS_ERROR irq bits. */
  889. s->interrupts = (value >> 1) & 1;
  890. s->dual = value & 1;
  891. break;
  892. case 0xbc8: /* TOP_B1_L */
  893. s->src_f1_top &= 0xffff0000;
  894. s->src_f1_top |= 0x0000ffff & value;
  895. break;
  896. case 0xbca: /* TOP_B1_U */
  897. s->src_f1_top &= 0x0000ffff;
  898. s->src_f1_top |= value << 16;
  899. break;
  900. case 0xbcc: /* BOT_B1_L */
  901. s->src_f1_bottom &= 0xffff0000;
  902. s->src_f1_bottom |= 0x0000ffff & value;
  903. break;
  904. case 0xbce: /* BOT_B1_U */
  905. s->src_f1_bottom &= 0x0000ffff;
  906. s->src_f1_bottom |= (uint32_t) value << 16;
  907. break;
  908. case 0xbd0: /* TOP_B2_L */
  909. s->src_f2_top &= 0xffff0000;
  910. s->src_f2_top |= 0x0000ffff & value;
  911. break;
  912. case 0xbd2: /* TOP_B2_U */
  913. s->src_f2_top &= 0x0000ffff;
  914. s->src_f2_top |= (uint32_t) value << 16;
  915. break;
  916. case 0xbd4: /* BOT_B2_L */
  917. s->src_f2_bottom &= 0xffff0000;
  918. s->src_f2_bottom |= 0x0000ffff & value;
  919. break;
  920. case 0xbd6: /* BOT_B2_U */
  921. s->src_f2_bottom &= 0x0000ffff;
  922. s->src_f2_bottom |= (uint32_t) value << 16;
  923. break;
  924. case 0xbd8: /* DMA_LCD_SRC_EI_B1 */
  925. s->element_index_f1 = value;
  926. break;
  927. case 0xbda: /* DMA_LCD_SRC_FI_B1_L */
  928. s->frame_index_f1 &= 0xffff0000;
  929. s->frame_index_f1 |= 0x0000ffff & value;
  930. break;
  931. case 0xbf4: /* DMA_LCD_SRC_FI_B1_U */
  932. s->frame_index_f1 &= 0x0000ffff;
  933. s->frame_index_f1 |= (uint32_t) value << 16;
  934. break;
  935. case 0xbdc: /* DMA_LCD_SRC_EI_B2 */
  936. s->element_index_f2 = value;
  937. break;
  938. case 0xbde: /* DMA_LCD_SRC_FI_B2_L */
  939. s->frame_index_f2 &= 0xffff0000;
  940. s->frame_index_f2 |= 0x0000ffff & value;
  941. break;
  942. case 0xbf6: /* DMA_LCD_SRC_FI_B2_U */
  943. s->frame_index_f2 &= 0x0000ffff;
  944. s->frame_index_f2 |= (uint32_t) value << 16;
  945. break;
  946. case 0xbe0: /* DMA_LCD_SRC_EN_B1 */
  947. s->elements_f1 = value;
  948. break;
  949. case 0xbe4: /* DMA_LCD_SRC_FN_B1 */
  950. s->frames_f1 = value;
  951. break;
  952. case 0xbe2: /* DMA_LCD_SRC_EN_B2 */
  953. s->elements_f2 = value;
  954. break;
  955. case 0xbe6: /* DMA_LCD_SRC_FN_B2 */
  956. s->frames_f2 = value;
  957. break;
  958. case 0xbea: /* DMA_LCD_LCH_CTRL */
  959. s->lch_type = value & 0xf;
  960. break;
  961. default:
  962. return 1;
  963. }
  964. return 0;
  965. }
  966. static int omap_dma_3_2_lcd_read(struct omap_dma_lcd_channel_s *s, int offset,
  967. uint16_t *ret)
  968. {
  969. switch (offset) {
  970. case 0xbc0: /* DMA_LCD_CSDP */
  971. *ret = (s->brust_f2 << 14) |
  972. (s->pack_f2 << 13) |
  973. ((s->data_type_f2 >> 1) << 11) |
  974. (s->brust_f1 << 7) |
  975. (s->pack_f1 << 6) |
  976. ((s->data_type_f1 >> 1) << 0);
  977. break;
  978. case 0xbc2: /* DMA_LCD_CCR */
  979. *ret = (s->mode_f2 << 14) |
  980. (s->mode_f1 << 12) |
  981. (s->end_prog << 11) |
  982. (s->omap_3_1_compatible_disable << 10) |
  983. (s->repeat << 9) |
  984. (s->auto_init << 8) |
  985. (s->running << 7) |
  986. (s->priority << 6) |
  987. (s->bs << 4);
  988. break;
  989. case 0xbc4: /* DMA_LCD_CTRL */
  990. qemu_irq_lower(s->irq);
  991. *ret = (s->dst << 8) |
  992. ((s->src & 0x6) << 5) |
  993. (s->condition << 3) |
  994. (s->interrupts << 1) |
  995. s->dual;
  996. break;
  997. case 0xbc8: /* TOP_B1_L */
  998. *ret = s->src_f1_top & 0xffff;
  999. break;
  1000. case 0xbca: /* TOP_B1_U */
  1001. *ret = s->src_f1_top >> 16;
  1002. break;
  1003. case 0xbcc: /* BOT_B1_L */
  1004. *ret = s->src_f1_bottom & 0xffff;
  1005. break;
  1006. case 0xbce: /* BOT_B1_U */
  1007. *ret = s->src_f1_bottom >> 16;
  1008. break;
  1009. case 0xbd0: /* TOP_B2_L */
  1010. *ret = s->src_f2_top & 0xffff;
  1011. break;
  1012. case 0xbd2: /* TOP_B2_U */
  1013. *ret = s->src_f2_top >> 16;
  1014. break;
  1015. case 0xbd4: /* BOT_B2_L */
  1016. *ret = s->src_f2_bottom & 0xffff;
  1017. break;
  1018. case 0xbd6: /* BOT_B2_U */
  1019. *ret = s->src_f2_bottom >> 16;
  1020. break;
  1021. case 0xbd8: /* DMA_LCD_SRC_EI_B1 */
  1022. *ret = s->element_index_f1;
  1023. break;
  1024. case 0xbda: /* DMA_LCD_SRC_FI_B1_L */
  1025. *ret = s->frame_index_f1 & 0xffff;
  1026. break;
  1027. case 0xbf4: /* DMA_LCD_SRC_FI_B1_U */
  1028. *ret = s->frame_index_f1 >> 16;
  1029. break;
  1030. case 0xbdc: /* DMA_LCD_SRC_EI_B2 */
  1031. *ret = s->element_index_f2;
  1032. break;
  1033. case 0xbde: /* DMA_LCD_SRC_FI_B2_L */
  1034. *ret = s->frame_index_f2 & 0xffff;
  1035. break;
  1036. case 0xbf6: /* DMA_LCD_SRC_FI_B2_U */
  1037. *ret = s->frame_index_f2 >> 16;
  1038. break;
  1039. case 0xbe0: /* DMA_LCD_SRC_EN_B1 */
  1040. *ret = s->elements_f1;
  1041. break;
  1042. case 0xbe4: /* DMA_LCD_SRC_FN_B1 */
  1043. *ret = s->frames_f1;
  1044. break;
  1045. case 0xbe2: /* DMA_LCD_SRC_EN_B2 */
  1046. *ret = s->elements_f2;
  1047. break;
  1048. case 0xbe6: /* DMA_LCD_SRC_FN_B2 */
  1049. *ret = s->frames_f2;
  1050. break;
  1051. case 0xbea: /* DMA_LCD_LCH_CTRL */
  1052. *ret = s->lch_type;
  1053. break;
  1054. default:
  1055. return 1;
  1056. }
  1057. return 0;
  1058. }
  1059. static int omap_dma_3_1_lcd_write(struct omap_dma_lcd_channel_s *s, int offset,
  1060. uint16_t value)
  1061. {
  1062. switch (offset) {
  1063. case 0x300: /* SYS_DMA_LCD_CTRL */
  1064. s->src = (value & 0x40) ? imif : emiff;
  1065. s->condition = 0;
  1066. /* Assume no bus errors and thus no BUS_ERROR irq bits. */
  1067. s->interrupts = (value >> 1) & 1;
  1068. s->dual = value & 1;
  1069. break;
  1070. case 0x302: /* SYS_DMA_LCD_TOP_F1_L */
  1071. s->src_f1_top &= 0xffff0000;
  1072. s->src_f1_top |= 0x0000ffff & value;
  1073. break;
  1074. case 0x304: /* SYS_DMA_LCD_TOP_F1_U */
  1075. s->src_f1_top &= 0x0000ffff;
  1076. s->src_f1_top |= value << 16;
  1077. break;
  1078. case 0x306: /* SYS_DMA_LCD_BOT_F1_L */
  1079. s->src_f1_bottom &= 0xffff0000;
  1080. s->src_f1_bottom |= 0x0000ffff & value;
  1081. break;
  1082. case 0x308: /* SYS_DMA_LCD_BOT_F1_U */
  1083. s->src_f1_bottom &= 0x0000ffff;
  1084. s->src_f1_bottom |= value << 16;
  1085. break;
  1086. case 0x30a: /* SYS_DMA_LCD_TOP_F2_L */
  1087. s->src_f2_top &= 0xffff0000;
  1088. s->src_f2_top |= 0x0000ffff & value;
  1089. break;
  1090. case 0x30c: /* SYS_DMA_LCD_TOP_F2_U */
  1091. s->src_f2_top &= 0x0000ffff;
  1092. s->src_f2_top |= value << 16;
  1093. break;
  1094. case 0x30e: /* SYS_DMA_LCD_BOT_F2_L */
  1095. s->src_f2_bottom &= 0xffff0000;
  1096. s->src_f2_bottom |= 0x0000ffff & value;
  1097. break;
  1098. case 0x310: /* SYS_DMA_LCD_BOT_F2_U */
  1099. s->src_f2_bottom &= 0x0000ffff;
  1100. s->src_f2_bottom |= value << 16;
  1101. break;
  1102. default:
  1103. return 1;
  1104. }
  1105. return 0;
  1106. }
  1107. static int omap_dma_3_1_lcd_read(struct omap_dma_lcd_channel_s *s, int offset,
  1108. uint16_t *ret)
  1109. {
  1110. int i;
  1111. switch (offset) {
  1112. case 0x300: /* SYS_DMA_LCD_CTRL */
  1113. i = s->condition;
  1114. s->condition = 0;
  1115. qemu_irq_lower(s->irq);
  1116. *ret = ((s->src == imif) << 6) | (i << 3) |
  1117. (s->interrupts << 1) | s->dual;
  1118. break;
  1119. case 0x302: /* SYS_DMA_LCD_TOP_F1_L */
  1120. *ret = s->src_f1_top & 0xffff;
  1121. break;
  1122. case 0x304: /* SYS_DMA_LCD_TOP_F1_U */
  1123. *ret = s->src_f1_top >> 16;
  1124. break;
  1125. case 0x306: /* SYS_DMA_LCD_BOT_F1_L */
  1126. *ret = s->src_f1_bottom & 0xffff;
  1127. break;
  1128. case 0x308: /* SYS_DMA_LCD_BOT_F1_U */
  1129. *ret = s->src_f1_bottom >> 16;
  1130. break;
  1131. case 0x30a: /* SYS_DMA_LCD_TOP_F2_L */
  1132. *ret = s->src_f2_top & 0xffff;
  1133. break;
  1134. case 0x30c: /* SYS_DMA_LCD_TOP_F2_U */
  1135. *ret = s->src_f2_top >> 16;
  1136. break;
  1137. case 0x30e: /* SYS_DMA_LCD_BOT_F2_L */
  1138. *ret = s->src_f2_bottom & 0xffff;
  1139. break;
  1140. case 0x310: /* SYS_DMA_LCD_BOT_F2_U */
  1141. *ret = s->src_f2_bottom >> 16;
  1142. break;
  1143. default:
  1144. return 1;
  1145. }
  1146. return 0;
  1147. }
  1148. static int omap_dma_sys_write(struct omap_dma_s *s, int offset, uint16_t value)
  1149. {
  1150. switch (offset) {
  1151. case 0x400: /* SYS_DMA_GCR */
  1152. s->gcr = value;
  1153. break;
  1154. case 0x404: /* DMA_GSCR */
  1155. if (value & 0x8)
  1156. omap_dma_disable_3_1_mapping(s);
  1157. else
  1158. omap_dma_enable_3_1_mapping(s);
  1159. break;
  1160. case 0x408: /* DMA_GRST */
  1161. if (value & 0x1)
  1162. omap_dma_reset(s->dma);
  1163. break;
  1164. default:
  1165. return 1;
  1166. }
  1167. return 0;
  1168. }
  1169. static int omap_dma_sys_read(struct omap_dma_s *s, int offset,
  1170. uint16_t *ret)
  1171. {
  1172. switch (offset) {
  1173. case 0x400: /* SYS_DMA_GCR */
  1174. *ret = s->gcr;
  1175. break;
  1176. case 0x404: /* DMA_GSCR */
  1177. *ret = s->omap_3_1_mapping_disabled << 3;
  1178. break;
  1179. case 0x408: /* DMA_GRST */
  1180. *ret = 0;
  1181. break;
  1182. case 0x442: /* DMA_HW_ID */
  1183. case 0x444: /* DMA_PCh2_ID */
  1184. case 0x446: /* DMA_PCh0_ID */
  1185. case 0x448: /* DMA_PCh1_ID */
  1186. case 0x44a: /* DMA_PChG_ID */
  1187. case 0x44c: /* DMA_PChD_ID */
  1188. *ret = 1;
  1189. break;
  1190. case 0x44e: /* DMA_CAPS_0_U */
  1191. *ret = (s->caps[0] >> 16) & 0xffff;
  1192. break;
  1193. case 0x450: /* DMA_CAPS_0_L */
  1194. *ret = (s->caps[0] >> 0) & 0xffff;
  1195. break;
  1196. case 0x452: /* DMA_CAPS_1_U */
  1197. *ret = (s->caps[1] >> 16) & 0xffff;
  1198. break;
  1199. case 0x454: /* DMA_CAPS_1_L */
  1200. *ret = (s->caps[1] >> 0) & 0xffff;
  1201. break;
  1202. case 0x456: /* DMA_CAPS_2 */
  1203. *ret = s->caps[2];
  1204. break;
  1205. case 0x458: /* DMA_CAPS_3 */
  1206. *ret = s->caps[3];
  1207. break;
  1208. case 0x45a: /* DMA_CAPS_4 */
  1209. *ret = s->caps[4];
  1210. break;
  1211. case 0x460: /* DMA_PCh2_SR */
  1212. case 0x480: /* DMA_PCh0_SR */
  1213. case 0x482: /* DMA_PCh1_SR */
  1214. case 0x4c0: /* DMA_PChD_SR_0 */
  1215. printf("%s: Physical Channel Status Registers not implemented.\n",
  1216. __FUNCTION__);
  1217. *ret = 0xff;
  1218. break;
  1219. default:
  1220. return 1;
  1221. }
  1222. return 0;
  1223. }
  1224. static uint32_t omap_dma_read(void *opaque, target_phys_addr_t addr)
  1225. {
  1226. struct omap_dma_s *s = (struct omap_dma_s *) opaque;
  1227. int reg, ch;
  1228. uint16_t ret;
  1229. switch (addr) {
  1230. case 0x300 ... 0x3fe:
  1231. if (s->model <= omap_dma_3_1 || !s->omap_3_1_mapping_disabled) {
  1232. if (omap_dma_3_1_lcd_read(&s->lcd_ch, addr, &ret))
  1233. break;
  1234. return ret;
  1235. }
  1236. /* Fall through. */
  1237. case 0x000 ... 0x2fe:
  1238. reg = addr & 0x3f;
  1239. ch = (addr >> 6) & 0x0f;
  1240. if (omap_dma_ch_reg_read(s, &s->ch[ch], reg, &ret))
  1241. break;
  1242. return ret;
  1243. case 0x404 ... 0x4fe:
  1244. if (s->model <= omap_dma_3_1)
  1245. break;
  1246. /* Fall through. */
  1247. case 0x400:
  1248. if (omap_dma_sys_read(s, addr, &ret))
  1249. break;
  1250. return ret;
  1251. case 0xb00 ... 0xbfe:
  1252. if (s->model == omap_dma_3_2 && s->omap_3_1_mapping_disabled) {
  1253. if (omap_dma_3_2_lcd_read(&s->lcd_ch, addr, &ret))
  1254. break;
  1255. return ret;
  1256. }
  1257. break;
  1258. }
  1259. OMAP_BAD_REG(addr);
  1260. return 0;
  1261. }
  1262. static void omap_dma_write(void *opaque, target_phys_addr_t addr,
  1263. uint32_t value)
  1264. {
  1265. struct omap_dma_s *s = (struct omap_dma_s *) opaque;
  1266. int reg, ch;
  1267. switch (addr) {
  1268. case 0x300 ... 0x3fe:
  1269. if (s->model <= omap_dma_3_1 || !s->omap_3_1_mapping_disabled) {
  1270. if (omap_dma_3_1_lcd_write(&s->lcd_ch, addr, value))
  1271. break;
  1272. return;
  1273. }
  1274. /* Fall through. */
  1275. case 0x000 ... 0x2fe:
  1276. reg = addr & 0x3f;
  1277. ch = (addr >> 6) & 0x0f;
  1278. if (omap_dma_ch_reg_write(s, &s->ch[ch], reg, value))
  1279. break;
  1280. return;
  1281. case 0x404 ... 0x4fe:
  1282. if (s->model <= omap_dma_3_1)
  1283. break;
  1284. case 0x400:
  1285. /* Fall through. */
  1286. if (omap_dma_sys_write(s, addr, value))
  1287. break;
  1288. return;
  1289. case 0xb00 ... 0xbfe:
  1290. if (s->model == omap_dma_3_2 && s->omap_3_1_mapping_disabled) {
  1291. if (omap_dma_3_2_lcd_write(&s->lcd_ch, addr, value))
  1292. break;
  1293. return;
  1294. }
  1295. break;
  1296. }
  1297. OMAP_BAD_REG(addr);
  1298. }
  1299. static CPUReadMemoryFunc *omap_dma_readfn[] = {
  1300. omap_badwidth_read16,
  1301. omap_dma_read,
  1302. omap_badwidth_read16,
  1303. };
  1304. static CPUWriteMemoryFunc *omap_dma_writefn[] = {
  1305. omap_badwidth_write16,
  1306. omap_dma_write,
  1307. omap_badwidth_write16,
  1308. };
  1309. static void omap_dma_request(void *opaque, int drq, int req)
  1310. {
  1311. struct omap_dma_s *s = (struct omap_dma_s *) opaque;
  1312. /* The request pins are level triggered in QEMU. */
  1313. if (req) {
  1314. if (~s->dma->drqbmp & (1 << drq)) {
  1315. s->dma->drqbmp |= 1 << drq;
  1316. omap_dma_process_request(s, drq);
  1317. }
  1318. } else
  1319. s->dma->drqbmp &= ~(1 << drq);
  1320. }
  1321. /* XXX: this won't be needed once soc_dma knows about clocks. */
  1322. static void omap_dma_clk_update(void *opaque, int line, int on)
  1323. {
  1324. struct omap_dma_s *s = (struct omap_dma_s *) opaque;
  1325. int i;
  1326. s->dma->freq = omap_clk_getrate(s->clk);
  1327. for (i = 0; i < s->chans; i ++)
  1328. if (s->ch[i].active)
  1329. soc_dma_set_request(s->ch[i].dma, on);
  1330. }
  1331. static void omap_dma_setcaps(struct omap_dma_s *s)
  1332. {
  1333. switch (s->model) {
  1334. default:
  1335. case omap_dma_3_1:
  1336. break;
  1337. case omap_dma_3_2:
  1338. case omap_dma_4:
  1339. /* XXX Only available for sDMA */
  1340. s->caps[0] =
  1341. (1 << 19) | /* Constant Fill Capability */
  1342. (1 << 18); /* Transparent BLT Capability */
  1343. s->caps[1] =
  1344. (1 << 1); /* 1-bit palettized capability (DMA 3.2 only) */
  1345. s->caps[2] =
  1346. (1 << 8) | /* SEPARATE_SRC_AND_DST_INDEX_CPBLTY */
  1347. (1 << 7) | /* DST_DOUBLE_INDEX_ADRS_CPBLTY */
  1348. (1 << 6) | /* DST_SINGLE_INDEX_ADRS_CPBLTY */
  1349. (1 << 5) | /* DST_POST_INCRMNT_ADRS_CPBLTY */
  1350. (1 << 4) | /* DST_CONST_ADRS_CPBLTY */
  1351. (1 << 3) | /* SRC_DOUBLE_INDEX_ADRS_CPBLTY */
  1352. (1 << 2) | /* SRC_SINGLE_INDEX_ADRS_CPBLTY */
  1353. (1 << 1) | /* SRC_POST_INCRMNT_ADRS_CPBLTY */
  1354. (1 << 0); /* SRC_CONST_ADRS_CPBLTY */
  1355. s->caps[3] =
  1356. (1 << 6) | /* BLOCK_SYNCHR_CPBLTY (DMA 4 only) */
  1357. (1 << 7) | /* PKT_SYNCHR_CPBLTY (DMA 4 only) */
  1358. (1 << 5) | /* CHANNEL_CHAINING_CPBLTY */
  1359. (1 << 4) | /* LCh_INTERLEAVE_CPBLTY */
  1360. (1 << 3) | /* AUTOINIT_REPEAT_CPBLTY (DMA 3.2 only) */
  1361. (1 << 2) | /* AUTOINIT_ENDPROG_CPBLTY (DMA 3.2 only) */
  1362. (1 << 1) | /* FRAME_SYNCHR_CPBLTY */
  1363. (1 << 0); /* ELMNT_SYNCHR_CPBLTY */
  1364. s->caps[4] =
  1365. (1 << 7) | /* PKT_INTERRUPT_CPBLTY (DMA 4 only) */
  1366. (1 << 6) | /* SYNC_STATUS_CPBLTY */
  1367. (1 << 5) | /* BLOCK_INTERRUPT_CPBLTY */
  1368. (1 << 4) | /* LAST_FRAME_INTERRUPT_CPBLTY */
  1369. (1 << 3) | /* FRAME_INTERRUPT_CPBLTY */
  1370. (1 << 2) | /* HALF_FRAME_INTERRUPT_CPBLTY */
  1371. (1 << 1) | /* EVENT_DROP_INTERRUPT_CPBLTY */
  1372. (1 << 0); /* TIMEOUT_INTERRUPT_CPBLTY (DMA 3.2 only) */
  1373. break;
  1374. }
  1375. }
  1376. struct soc_dma_s *omap_dma_init(target_phys_addr_t base, qemu_irq *irqs,
  1377. qemu_irq lcd_irq, struct omap_mpu_state_s *mpu, omap_clk clk,
  1378. enum omap_dma_model model)
  1379. {
  1380. int iomemtype, num_irqs, memsize, i;
  1381. struct omap_dma_s *s = (struct omap_dma_s *)
  1382. qemu_mallocz(sizeof(struct omap_dma_s));
  1383. if (model <= omap_dma_3_1) {
  1384. num_irqs = 6;
  1385. memsize = 0x800;
  1386. } else {
  1387. num_irqs = 16;
  1388. memsize = 0xc00;
  1389. }
  1390. s->model = model;
  1391. s->mpu = mpu;
  1392. s->clk = clk;
  1393. s->lcd_ch.irq = lcd_irq;
  1394. s->lcd_ch.mpu = mpu;
  1395. s->dma = soc_dma_init((model <= omap_dma_3_1) ? 9 : 16);
  1396. s->dma->freq = omap_clk_getrate(clk);
  1397. s->dma->transfer_fn = omap_dma_transfer_generic;
  1398. s->dma->setup_fn = omap_dma_transfer_setup;
  1399. s->dma->drq = qemu_allocate_irqs(omap_dma_request, s, 32);
  1400. s->dma->opaque = s;
  1401. while (num_irqs --)
  1402. s->ch[num_irqs].irq = irqs[num_irqs];
  1403. for (i = 0; i < 3; i ++) {
  1404. s->ch[i].sibling = &s->ch[i + 6];
  1405. s->ch[i + 6].sibling = &s->ch[i];
  1406. }
  1407. for (i = (model <= omap_dma_3_1) ? 8 : 15; i >= 0; i --) {
  1408. s->ch[i].dma = &s->dma->ch[i];
  1409. s->dma->ch[i].opaque = &s->ch[i];
  1410. }
  1411. omap_dma_setcaps(s);
  1412. omap_clk_adduser(s->clk, qemu_allocate_irqs(omap_dma_clk_update, s, 1)[0]);
  1413. omap_dma_reset(s->dma);
  1414. omap_dma_clk_update(s, 0, 1);
  1415. iomemtype = cpu_register_io_memory(0, omap_dma_readfn,
  1416. omap_dma_writefn, s);
  1417. cpu_register_physical_memory(base, memsize, iomemtype);
  1418. mpu->drq = s->dma->drq;
  1419. return s->dma;
  1420. }
  1421. static void omap_dma_interrupts_4_update(struct omap_dma_s *s)
  1422. {
  1423. struct omap_dma_channel_s *ch = s->ch;
  1424. uint32_t bmp, bit;
  1425. for (bmp = 0, bit = 1; bit; ch ++, bit <<= 1)
  1426. if (ch->status) {
  1427. bmp |= bit;
  1428. ch->cstatus |= ch->status;
  1429. ch->status = 0;
  1430. }
  1431. if ((s->irqstat[0] |= s->irqen[0] & bmp))
  1432. qemu_irq_raise(s->irq[0]);
  1433. if ((s->irqstat[1] |= s->irqen[1] & bmp))
  1434. qemu_irq_raise(s->irq[1]);
  1435. if ((s->irqstat[2] |= s->irqen[2] & bmp))
  1436. qemu_irq_raise(s->irq[2]);
  1437. if ((s->irqstat[3] |= s->irqen[3] & bmp))
  1438. qemu_irq_raise(s->irq[3]);
  1439. }
  1440. static uint32_t omap_dma4_read(void *opaque, target_phys_addr_t addr)
  1441. {
  1442. struct omap_dma_s *s = (struct omap_dma_s *) opaque;
  1443. int irqn = 0, chnum;
  1444. struct omap_dma_channel_s *ch;
  1445. switch (addr) {
  1446. case 0x00: /* DMA4_REVISION */
  1447. return 0x40;
  1448. case 0x14: /* DMA4_IRQSTATUS_L3 */
  1449. irqn ++;
  1450. case 0x10: /* DMA4_IRQSTATUS_L2 */
  1451. irqn ++;
  1452. case 0x0c: /* DMA4_IRQSTATUS_L1 */
  1453. irqn ++;
  1454. case 0x08: /* DMA4_IRQSTATUS_L0 */
  1455. return s->irqstat[irqn];
  1456. case 0x24: /* DMA4_IRQENABLE_L3 */
  1457. irqn ++;
  1458. case 0x20: /* DMA4_IRQENABLE_L2 */
  1459. irqn ++;
  1460. case 0x1c: /* DMA4_IRQENABLE_L1 */
  1461. irqn ++;
  1462. case 0x18: /* DMA4_IRQENABLE_L0 */
  1463. return s->irqen[irqn];
  1464. case 0x28: /* DMA4_SYSSTATUS */
  1465. return 1; /* RESETDONE */
  1466. case 0x2c: /* DMA4_OCP_SYSCONFIG */
  1467. return s->ocp;
  1468. case 0x64: /* DMA4_CAPS_0 */
  1469. return s->caps[0];
  1470. case 0x6c: /* DMA4_CAPS_2 */
  1471. return s->caps[2];
  1472. case 0x70: /* DMA4_CAPS_3 */
  1473. return s->caps[3];
  1474. case 0x74: /* DMA4_CAPS_4 */
  1475. return s->caps[4];
  1476. case 0x78: /* DMA4_GCR */
  1477. return s->gcr;
  1478. case 0x80 ... 0xfff:
  1479. addr -= 0x80;
  1480. chnum = addr / 0x60;
  1481. ch = s->ch + chnum;
  1482. addr -= chnum * 0x60;
  1483. break;
  1484. default:
  1485. OMAP_BAD_REG(addr);
  1486. return 0;
  1487. }
  1488. /* Per-channel registers */
  1489. switch (addr) {
  1490. case 0x00: /* DMA4_CCR */
  1491. return (ch->buf_disable << 25) |
  1492. (ch->src_sync << 24) |
  1493. (ch->prefetch << 23) |
  1494. ((ch->sync & 0x60) << 14) |
  1495. (ch->bs << 18) |
  1496. (ch->transparent_copy << 17) |
  1497. (ch->constant_fill << 16) |
  1498. (ch->mode[1] << 14) |
  1499. (ch->mode[0] << 12) |
  1500. (0 << 10) | (0 << 9) |
  1501. (ch->suspend << 8) |
  1502. (ch->enable << 7) |
  1503. (ch->priority << 6) |
  1504. (ch->fs << 5) | (ch->sync & 0x1f);
  1505. case 0x04: /* DMA4_CLNK_CTRL */
  1506. return (ch->link_enabled << 15) | ch->link_next_ch;
  1507. case 0x08: /* DMA4_CICR */
  1508. return ch->interrupts;
  1509. case 0x0c: /* DMA4_CSR */
  1510. return ch->cstatus;
  1511. case 0x10: /* DMA4_CSDP */
  1512. return (ch->endian[0] << 21) |
  1513. (ch->endian_lock[0] << 20) |
  1514. (ch->endian[1] << 19) |
  1515. (ch->endian_lock[1] << 18) |
  1516. (ch->write_mode << 16) |
  1517. (ch->burst[1] << 14) |
  1518. (ch->pack[1] << 13) |
  1519. (ch->translate[1] << 9) |
  1520. (ch->burst[0] << 7) |
  1521. (ch->pack[0] << 6) |
  1522. (ch->translate[0] << 2) |
  1523. (ch->data_type >> 1);
  1524. case 0x14: /* DMA4_CEN */
  1525. return ch->elements;
  1526. case 0x18: /* DMA4_CFN */
  1527. return ch->frames;
  1528. case 0x1c: /* DMA4_CSSA */
  1529. return ch->addr[0];
  1530. case 0x20: /* DMA4_CDSA */
  1531. return ch->addr[1];
  1532. case 0x24: /* DMA4_CSEI */
  1533. return ch->element_index[0];
  1534. case 0x28: /* DMA4_CSFI */
  1535. return ch->frame_index[0];
  1536. case 0x2c: /* DMA4_CDEI */
  1537. return ch->element_index[1];
  1538. case 0x30: /* DMA4_CDFI */
  1539. return ch->frame_index[1];
  1540. case 0x34: /* DMA4_CSAC */
  1541. return ch->active_set.src & 0xffff;
  1542. case 0x38: /* DMA4_CDAC */
  1543. return ch->active_set.dest & 0xffff;
  1544. case 0x3c: /* DMA4_CCEN */
  1545. return ch->active_set.element;
  1546. case 0x40: /* DMA4_CCFN */
  1547. return ch->active_set.frame;
  1548. case 0x44: /* DMA4_COLOR */
  1549. /* XXX only in sDMA */
  1550. return ch->color;
  1551. default:
  1552. OMAP_BAD_REG(addr);
  1553. return 0;
  1554. }
  1555. }
  1556. static void omap_dma4_write(void *opaque, target_phys_addr_t addr,
  1557. uint32_t value)
  1558. {
  1559. struct omap_dma_s *s = (struct omap_dma_s *) opaque;
  1560. int chnum, irqn = 0;
  1561. struct omap_dma_channel_s *ch;
  1562. switch (addr) {
  1563. case 0x14: /* DMA4_IRQSTATUS_L3 */
  1564. irqn ++;
  1565. case 0x10: /* DMA4_IRQSTATUS_L2 */
  1566. irqn ++;
  1567. case 0x0c: /* DMA4_IRQSTATUS_L1 */
  1568. irqn ++;
  1569. case 0x08: /* DMA4_IRQSTATUS_L0 */
  1570. s->irqstat[irqn] &= ~value;
  1571. if (!s->irqstat[irqn])
  1572. qemu_irq_lower(s->irq[irqn]);
  1573. return;
  1574. case 0x24: /* DMA4_IRQENABLE_L3 */
  1575. irqn ++;
  1576. case 0x20: /* DMA4_IRQENABLE_L2 */
  1577. irqn ++;
  1578. case 0x1c: /* DMA4_IRQENABLE_L1 */
  1579. irqn ++;
  1580. case 0x18: /* DMA4_IRQENABLE_L0 */
  1581. s->irqen[irqn] = value;
  1582. return;
  1583. case 0x2c: /* DMA4_OCP_SYSCONFIG */
  1584. if (value & 2) /* SOFTRESET */
  1585. omap_dma_reset(s->dma);
  1586. s->ocp = value & 0x3321;
  1587. if (((s->ocp >> 12) & 3) == 3) /* MIDLEMODE */
  1588. fprintf(stderr, "%s: invalid DMA power mode\n", __FUNCTION__);
  1589. return;
  1590. case 0x78: /* DMA4_GCR */
  1591. s->gcr = value & 0x00ff00ff;
  1592. if ((value & 0xff) == 0x00) /* MAX_CHANNEL_FIFO_DEPTH */
  1593. fprintf(stderr, "%s: wrong FIFO depth in GCR\n", __FUNCTION__);
  1594. return;
  1595. case 0x80 ... 0xfff:
  1596. addr -= 0x80;
  1597. chnum = addr / 0x60;
  1598. ch = s->ch + chnum;
  1599. addr -= chnum * 0x60;
  1600. break;
  1601. case 0x00: /* DMA4_REVISION */
  1602. case 0x28: /* DMA4_SYSSTATUS */
  1603. case 0x64: /* DMA4_CAPS_0 */
  1604. case 0x6c: /* DMA4_CAPS_2 */
  1605. case 0x70: /* DMA4_CAPS_3 */
  1606. case 0x74: /* DMA4_CAPS_4 */
  1607. OMAP_RO_REG(addr);
  1608. return;
  1609. default:
  1610. OMAP_BAD_REG(addr);
  1611. return;
  1612. }
  1613. /* Per-channel registers */
  1614. switch (addr) {
  1615. case 0x00: /* DMA4_CCR */
  1616. ch->buf_disable = (value >> 25) & 1;
  1617. ch->src_sync = (value >> 24) & 1; /* XXX For CamDMA must be 1 */
  1618. if (ch->buf_disable && !ch->src_sync)
  1619. fprintf(stderr, "%s: Buffering disable is not allowed in "
  1620. "destination synchronised mode\n", __FUNCTION__);
  1621. ch->prefetch = (value >> 23) & 1;
  1622. ch->bs = (value >> 18) & 1;
  1623. ch->transparent_copy = (value >> 17) & 1;
  1624. ch->constant_fill = (value >> 16) & 1;
  1625. ch->mode[1] = (omap_dma_addressing_t) ((value & 0xc000) >> 14);
  1626. ch->mode[0] = (omap_dma_addressing_t) ((value & 0x3000) >> 12);
  1627. ch->suspend = (value & 0x0100) >> 8;
  1628. ch->priority = (value & 0x0040) >> 6;
  1629. ch->fs = (value & 0x0020) >> 5;
  1630. if (ch->fs && ch->bs && ch->mode[0] && ch->mode[1])
  1631. fprintf(stderr, "%s: For a packet transfer at least one port "
  1632. "must be constant-addressed\n", __FUNCTION__);
  1633. ch->sync = (value & 0x001f) | ((value >> 14) & 0x0060);
  1634. /* XXX must be 0x01 for CamDMA */
  1635. if (value & 0x0080)
  1636. omap_dma_enable_channel(s, ch);
  1637. else
  1638. omap_dma_disable_channel(s, ch);
  1639. break;
  1640. case 0x04: /* DMA4_CLNK_CTRL */
  1641. ch->link_enabled = (value >> 15) & 0x1;
  1642. ch->link_next_ch = value & 0x1f;
  1643. break;
  1644. case 0x08: /* DMA4_CICR */
  1645. ch->interrupts = value & 0x09be;
  1646. break;
  1647. case 0x0c: /* DMA4_CSR */
  1648. ch->cstatus &= ~value;
  1649. break;
  1650. case 0x10: /* DMA4_CSDP */
  1651. ch->endian[0] =(value >> 21) & 1;
  1652. ch->endian_lock[0] =(value >> 20) & 1;
  1653. ch->endian[1] =(value >> 19) & 1;
  1654. ch->endian_lock[1] =(value >> 18) & 1;
  1655. if (ch->endian[0] != ch->endian[1])
  1656. fprintf(stderr, "%s: DMA endiannes conversion enable attempt\n",
  1657. __FUNCTION__);
  1658. ch->write_mode = (value >> 16) & 3;
  1659. ch->burst[1] = (value & 0xc000) >> 14;
  1660. ch->pack[1] = (value & 0x2000) >> 13;
  1661. ch->translate[1] = (value & 0x1e00) >> 9;
  1662. ch->burst[0] = (value & 0x0180) >> 7;
  1663. ch->pack[0] = (value & 0x0040) >> 6;
  1664. ch->translate[0] = (value & 0x003c) >> 2;
  1665. if (ch->translate[0] | ch->translate[1])
  1666. fprintf(stderr, "%s: bad MReqAddressTranslate sideband signal\n",
  1667. __FUNCTION__);
  1668. ch->data_type = 1 << (value & 3);
  1669. if ((value & 3) == 3)
  1670. printf("%s: bad data_type for DMA channel\n", __FUNCTION__);
  1671. break;
  1672. case 0x14: /* DMA4_CEN */
  1673. ch->set_update = 1;
  1674. ch->elements = value & 0xffffff;
  1675. break;
  1676. case 0x18: /* DMA4_CFN */
  1677. ch->frames = value & 0xffff;
  1678. ch->set_update = 1;
  1679. break;
  1680. case 0x1c: /* DMA4_CSSA */
  1681. ch->addr[0] = (target_phys_addr_t) (uint32_t) value;
  1682. ch->set_update = 1;
  1683. break;
  1684. case 0x20: /* DMA4_CDSA */
  1685. ch->addr[1] = (target_phys_addr_t) (uint32_t) value;
  1686. ch->set_update = 1;
  1687. break;
  1688. case 0x24: /* DMA4_CSEI */
  1689. ch->element_index[0] = (int16_t) value;
  1690. ch->set_update = 1;
  1691. break;
  1692. case 0x28: /* DMA4_CSFI */
  1693. ch->frame_index[0] = (int32_t) value;
  1694. ch->set_update = 1;
  1695. break;
  1696. case 0x2c: /* DMA4_CDEI */
  1697. ch->element_index[1] = (int16_t) value;
  1698. ch->set_update = 1;
  1699. break;
  1700. case 0x30: /* DMA4_CDFI */
  1701. ch->frame_index[1] = (int32_t) value;
  1702. ch->set_update = 1;
  1703. break;
  1704. case 0x44: /* DMA4_COLOR */
  1705. /* XXX only in sDMA */
  1706. ch->color = value;
  1707. break;
  1708. case 0x34: /* DMA4_CSAC */
  1709. case 0x38: /* DMA4_CDAC */
  1710. case 0x3c: /* DMA4_CCEN */
  1711. case 0x40: /* DMA4_CCFN */
  1712. OMAP_RO_REG(addr);
  1713. break;
  1714. default:
  1715. OMAP_BAD_REG(addr);
  1716. }
  1717. }
  1718. static CPUReadMemoryFunc *omap_dma4_readfn[] = {
  1719. omap_badwidth_read16,
  1720. omap_dma4_read,
  1721. omap_dma4_read,
  1722. };
  1723. static CPUWriteMemoryFunc *omap_dma4_writefn[] = {
  1724. omap_badwidth_write16,
  1725. omap_dma4_write,
  1726. omap_dma4_write,
  1727. };
  1728. struct soc_dma_s *omap_dma4_init(target_phys_addr_t base, qemu_irq *irqs,
  1729. struct omap_mpu_state_s *mpu, int fifo,
  1730. int chans, omap_clk iclk, omap_clk fclk)
  1731. {
  1732. int iomemtype, i;
  1733. struct omap_dma_s *s = (struct omap_dma_s *)
  1734. qemu_mallocz(sizeof(struct omap_dma_s));
  1735. s->model = omap_dma_4;
  1736. s->chans = chans;
  1737. s->mpu = mpu;
  1738. s->clk = fclk;
  1739. s->dma = soc_dma_init(s->chans);
  1740. s->dma->freq = omap_clk_getrate(fclk);
  1741. s->dma->transfer_fn = omap_dma_transfer_generic;
  1742. s->dma->setup_fn = omap_dma_transfer_setup;
  1743. s->dma->drq = qemu_allocate_irqs(omap_dma_request, s, 64);
  1744. s->dma->opaque = s;
  1745. for (i = 0; i < s->chans; i ++) {
  1746. s->ch[i].dma = &s->dma->ch[i];
  1747. s->dma->ch[i].opaque = &s->ch[i];
  1748. }
  1749. memcpy(&s->irq, irqs, sizeof(s->irq));
  1750. s->intr_update = omap_dma_interrupts_4_update;
  1751. omap_dma_setcaps(s);
  1752. omap_clk_adduser(s->clk, qemu_allocate_irqs(omap_dma_clk_update, s, 1)[0]);
  1753. omap_dma_reset(s->dma);
  1754. omap_dma_clk_update(s, 0, !!s->dma->freq);
  1755. iomemtype = cpu_register_io_memory(0, omap_dma4_readfn,
  1756. omap_dma4_writefn, s);
  1757. cpu_register_physical_memory(base, 0x1000, iomemtype);
  1758. mpu->drq = s->dma->drq;
  1759. return s->dma;
  1760. }
  1761. struct omap_dma_lcd_channel_s *omap_dma_get_lcdch(struct soc_dma_s *dma)
  1762. {
  1763. struct omap_dma_s *s = dma->opaque;
  1764. return &s->lcd_ch;
  1765. }