page.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2003, 04, 05 Ralf Baechle (ralf@linux-mips.org)
  7. * Copyright (C) 2007 Maciej W. Rozycki
  8. * Copyright (C) 2008 Thiemo Seufer
  9. * Copyright (C) 2012 MIPS Technologies, Inc.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/kernel.h>
  13. #include <linux/sched.h>
  14. #include <linux/smp.h>
  15. #include <linux/mm.h>
  16. #include <linux/module.h>
  17. #include <linux/proc_fs.h>
  18. #include <asm/bugs.h>
  19. #include <asm/cacheops.h>
  20. #include <asm/inst.h>
  21. #include <asm/io.h>
  22. #include <asm/page.h>
  23. #include <asm/pgtable.h>
  24. #include <asm/prefetch.h>
  25. #include <asm/bootinfo.h>
  26. #include <asm/mipsregs.h>
  27. #include <asm/mmu_context.h>
  28. #include <asm/cpu.h>
  29. #include <asm/war.h>
  30. #ifdef CONFIG_SIBYTE_DMA_PAGEOPS
  31. #include <asm/sibyte/sb1250.h>
  32. #include <asm/sibyte/sb1250_regs.h>
  33. #include <asm/sibyte/sb1250_dma.h>
  34. #endif
  35. #include <asm/uasm.h>
  36. /* Registers used in the assembled routines. */
  37. #define ZERO 0
  38. #define AT 2
  39. #define A0 4
  40. #define A1 5
  41. #define A2 6
  42. #define T0 8
  43. #define T1 9
  44. #define T2 10
  45. #define T3 11
  46. #define T9 25
  47. #define RA 31
  48. /* Handle labels (which must be positive integers). */
  49. enum label_id {
  50. label_clear_nopref = 1,
  51. label_clear_pref,
  52. label_copy_nopref,
  53. label_copy_pref_both,
  54. label_copy_pref_store,
  55. };
  56. UASM_L_LA(_clear_nopref)
  57. UASM_L_LA(_clear_pref)
  58. UASM_L_LA(_copy_nopref)
  59. UASM_L_LA(_copy_pref_both)
  60. UASM_L_LA(_copy_pref_store)
  61. /* We need one branch and therefore one relocation per target label. */
  62. static struct uasm_label __cpuinitdata labels[5];
  63. static struct uasm_reloc __cpuinitdata relocs[5];
  64. #define cpu_is_r4600_v1_x() ((read_c0_prid() & 0xfffffff0) == 0x00002010)
  65. #define cpu_is_r4600_v2_x() ((read_c0_prid() & 0xfffffff0) == 0x00002020)
  66. static int pref_bias_clear_store __cpuinitdata;
  67. static int pref_bias_copy_load __cpuinitdata;
  68. static int pref_bias_copy_store __cpuinitdata;
  69. static u32 pref_src_mode __cpuinitdata;
  70. static u32 pref_dst_mode __cpuinitdata;
  71. static int clear_word_size __cpuinitdata;
  72. static int copy_word_size __cpuinitdata;
  73. static int half_clear_loop_size __cpuinitdata;
  74. static int half_copy_loop_size __cpuinitdata;
  75. static int cache_line_size __cpuinitdata;
  76. #define cache_line_mask() (cache_line_size - 1)
  77. static inline void __cpuinit
  78. pg_addiu(u32 **buf, unsigned int reg1, unsigned int reg2, unsigned int off)
  79. {
  80. if (cpu_has_64bit_gp_regs && DADDI_WAR && r4k_daddiu_bug()) {
  81. if (off > 0x7fff) {
  82. uasm_i_lui(buf, T9, uasm_rel_hi(off));
  83. uasm_i_addiu(buf, T9, T9, uasm_rel_lo(off));
  84. } else
  85. uasm_i_addiu(buf, T9, ZERO, off);
  86. uasm_i_daddu(buf, reg1, reg2, T9);
  87. } else {
  88. if (off > 0x7fff) {
  89. uasm_i_lui(buf, T9, uasm_rel_hi(off));
  90. uasm_i_addiu(buf, T9, T9, uasm_rel_lo(off));
  91. UASM_i_ADDU(buf, reg1, reg2, T9);
  92. } else
  93. UASM_i_ADDIU(buf, reg1, reg2, off);
  94. }
  95. }
  96. static void __cpuinit set_prefetch_parameters(void)
  97. {
  98. if (cpu_has_64bit_gp_regs || cpu_has_64bit_zero_reg)
  99. clear_word_size = 8;
  100. else
  101. clear_word_size = 4;
  102. if (cpu_has_64bit_gp_regs)
  103. copy_word_size = 8;
  104. else
  105. copy_word_size = 4;
  106. /*
  107. * The pref's used here are using "streaming" hints, which cause the
  108. * copied data to be kicked out of the cache sooner. A page copy often
  109. * ends up copying a lot more data than is commonly used, so this seems
  110. * to make sense in terms of reducing cache pollution, but I've no real
  111. * performance data to back this up.
  112. */
  113. if (cpu_has_prefetch) {
  114. /*
  115. * XXX: Most prefetch bias values in here are based on
  116. * guesswork.
  117. */
  118. cache_line_size = cpu_dcache_line_size();
  119. switch (current_cpu_type()) {
  120. case CPU_R5500:
  121. case CPU_TX49XX:
  122. /* These processors only support the Pref_Load. */
  123. pref_bias_copy_load = 256;
  124. break;
  125. case CPU_RM9000:
  126. /*
  127. * As a workaround for erratum G105 which make the
  128. * PrepareForStore hint unusable we fall back to
  129. * StoreRetained on the RM9000. Once it is known which
  130. * versions of the RM9000 we'll be able to condition-
  131. * alize this.
  132. */
  133. case CPU_R10000:
  134. case CPU_R12000:
  135. case CPU_R14000:
  136. /*
  137. * Those values have been experimentally tuned for an
  138. * Origin 200.
  139. */
  140. pref_bias_clear_store = 512;
  141. pref_bias_copy_load = 256;
  142. pref_bias_copy_store = 256;
  143. pref_src_mode = Pref_LoadStreamed;
  144. pref_dst_mode = Pref_StoreStreamed;
  145. break;
  146. case CPU_SB1:
  147. case CPU_SB1A:
  148. pref_bias_clear_store = 128;
  149. pref_bias_copy_load = 128;
  150. pref_bias_copy_store = 128;
  151. /*
  152. * SB1 pass1 Pref_LoadStreamed/Pref_StoreStreamed
  153. * hints are broken.
  154. */
  155. if (current_cpu_type() == CPU_SB1 &&
  156. (current_cpu_data.processor_id & 0xff) < 0x02) {
  157. pref_src_mode = Pref_Load;
  158. pref_dst_mode = Pref_Store;
  159. } else {
  160. pref_src_mode = Pref_LoadStreamed;
  161. pref_dst_mode = Pref_StoreStreamed;
  162. }
  163. break;
  164. default:
  165. pref_bias_clear_store = 128;
  166. pref_bias_copy_load = 256;
  167. pref_bias_copy_store = 128;
  168. pref_src_mode = Pref_LoadStreamed;
  169. pref_dst_mode = Pref_PrepareForStore;
  170. break;
  171. }
  172. } else {
  173. if (cpu_has_cache_cdex_s)
  174. cache_line_size = cpu_scache_line_size();
  175. else if (cpu_has_cache_cdex_p)
  176. cache_line_size = cpu_dcache_line_size();
  177. }
  178. /*
  179. * Too much unrolling will overflow the available space in
  180. * clear_space_array / copy_page_array.
  181. */
  182. half_clear_loop_size = min(16 * clear_word_size,
  183. max(cache_line_size >> 1,
  184. 4 * clear_word_size));
  185. half_copy_loop_size = min(16 * copy_word_size,
  186. max(cache_line_size >> 1,
  187. 4 * copy_word_size));
  188. }
  189. static void __cpuinit build_clear_store(u32 **buf, int off)
  190. {
  191. if (cpu_has_64bit_gp_regs || cpu_has_64bit_zero_reg) {
  192. uasm_i_sd(buf, ZERO, off, A0);
  193. } else {
  194. uasm_i_sw(buf, ZERO, off, A0);
  195. }
  196. }
  197. static inline void __cpuinit build_clear_pref(u32 **buf, int off)
  198. {
  199. if (off & cache_line_mask())
  200. return;
  201. if (pref_bias_clear_store) {
  202. uasm_i_pref(buf, pref_dst_mode, pref_bias_clear_store + off,
  203. A0);
  204. } else if (cache_line_size == (half_clear_loop_size << 1)) {
  205. if (cpu_has_cache_cdex_s) {
  206. uasm_i_cache(buf, Create_Dirty_Excl_SD, off, A0);
  207. } else if (cpu_has_cache_cdex_p) {
  208. if (R4600_V1_HIT_CACHEOP_WAR && cpu_is_r4600_v1_x()) {
  209. uasm_i_nop(buf);
  210. uasm_i_nop(buf);
  211. uasm_i_nop(buf);
  212. uasm_i_nop(buf);
  213. }
  214. if (R4600_V2_HIT_CACHEOP_WAR && cpu_is_r4600_v2_x())
  215. uasm_i_lw(buf, ZERO, ZERO, AT);
  216. uasm_i_cache(buf, Create_Dirty_Excl_D, off, A0);
  217. }
  218. }
  219. }
  220. extern u32 __clear_page_start;
  221. extern u32 __clear_page_end;
  222. extern u32 __copy_page_start;
  223. extern u32 __copy_page_end;
  224. void __cpuinit build_clear_page(void)
  225. {
  226. int off;
  227. u32 *buf = &__clear_page_start;
  228. struct uasm_label *l = labels;
  229. struct uasm_reloc *r = relocs;
  230. int i;
  231. memset(labels, 0, sizeof(labels));
  232. memset(relocs, 0, sizeof(relocs));
  233. set_prefetch_parameters();
  234. /*
  235. * This algorithm makes the following assumptions:
  236. * - The prefetch bias is a multiple of 2 words.
  237. * - The prefetch bias is less than one page.
  238. */
  239. BUG_ON(pref_bias_clear_store % (2 * clear_word_size));
  240. BUG_ON(PAGE_SIZE < pref_bias_clear_store);
  241. off = PAGE_SIZE - pref_bias_clear_store;
  242. if (off > 0xffff || !pref_bias_clear_store)
  243. pg_addiu(&buf, A2, A0, off);
  244. else
  245. uasm_i_ori(&buf, A2, A0, off);
  246. if (R4600_V2_HIT_CACHEOP_WAR && cpu_is_r4600_v2_x())
  247. uasm_i_lui(&buf, AT, 0xa000);
  248. off = cache_line_size ? min(8, pref_bias_clear_store / cache_line_size)
  249. * cache_line_size : 0;
  250. while (off) {
  251. build_clear_pref(&buf, -off);
  252. off -= cache_line_size;
  253. }
  254. uasm_l_clear_pref(&l, buf);
  255. do {
  256. build_clear_pref(&buf, off);
  257. build_clear_store(&buf, off);
  258. off += clear_word_size;
  259. } while (off < half_clear_loop_size);
  260. pg_addiu(&buf, A0, A0, 2 * off);
  261. off = -off;
  262. do {
  263. build_clear_pref(&buf, off);
  264. if (off == -clear_word_size)
  265. uasm_il_bne(&buf, &r, A0, A2, label_clear_pref);
  266. build_clear_store(&buf, off);
  267. off += clear_word_size;
  268. } while (off < 0);
  269. if (pref_bias_clear_store) {
  270. pg_addiu(&buf, A2, A0, pref_bias_clear_store);
  271. uasm_l_clear_nopref(&l, buf);
  272. off = 0;
  273. do {
  274. build_clear_store(&buf, off);
  275. off += clear_word_size;
  276. } while (off < half_clear_loop_size);
  277. pg_addiu(&buf, A0, A0, 2 * off);
  278. off = -off;
  279. do {
  280. if (off == -clear_word_size)
  281. uasm_il_bne(&buf, &r, A0, A2,
  282. label_clear_nopref);
  283. build_clear_store(&buf, off);
  284. off += clear_word_size;
  285. } while (off < 0);
  286. }
  287. uasm_i_jr(&buf, RA);
  288. uasm_i_nop(&buf);
  289. BUG_ON(buf > &__clear_page_end);
  290. uasm_resolve_relocs(relocs, labels);
  291. pr_debug("Synthesized clear page handler (%u instructions).\n",
  292. (u32)(buf - &__clear_page_start));
  293. pr_debug("\t.set push\n");
  294. pr_debug("\t.set noreorder\n");
  295. for (i = 0; i < (buf - &__clear_page_start); i++)
  296. pr_debug("\t.word 0x%08x\n", (&__clear_page_start)[i]);
  297. pr_debug("\t.set pop\n");
  298. }
  299. static void __cpuinit build_copy_load(u32 **buf, int reg, int off)
  300. {
  301. if (cpu_has_64bit_gp_regs) {
  302. uasm_i_ld(buf, reg, off, A1);
  303. } else {
  304. uasm_i_lw(buf, reg, off, A1);
  305. }
  306. }
  307. static void __cpuinit build_copy_store(u32 **buf, int reg, int off)
  308. {
  309. if (cpu_has_64bit_gp_regs) {
  310. uasm_i_sd(buf, reg, off, A0);
  311. } else {
  312. uasm_i_sw(buf, reg, off, A0);
  313. }
  314. }
  315. static inline void build_copy_load_pref(u32 **buf, int off)
  316. {
  317. if (off & cache_line_mask())
  318. return;
  319. if (pref_bias_copy_load)
  320. uasm_i_pref(buf, pref_src_mode, pref_bias_copy_load + off, A1);
  321. }
  322. static inline void build_copy_store_pref(u32 **buf, int off)
  323. {
  324. if (off & cache_line_mask())
  325. return;
  326. if (pref_bias_copy_store) {
  327. uasm_i_pref(buf, pref_dst_mode, pref_bias_copy_store + off,
  328. A0);
  329. } else if (cache_line_size == (half_copy_loop_size << 1)) {
  330. if (cpu_has_cache_cdex_s) {
  331. uasm_i_cache(buf, Create_Dirty_Excl_SD, off, A0);
  332. } else if (cpu_has_cache_cdex_p) {
  333. if (R4600_V1_HIT_CACHEOP_WAR && cpu_is_r4600_v1_x()) {
  334. uasm_i_nop(buf);
  335. uasm_i_nop(buf);
  336. uasm_i_nop(buf);
  337. uasm_i_nop(buf);
  338. }
  339. if (R4600_V2_HIT_CACHEOP_WAR && cpu_is_r4600_v2_x())
  340. uasm_i_lw(buf, ZERO, ZERO, AT);
  341. uasm_i_cache(buf, Create_Dirty_Excl_D, off, A0);
  342. }
  343. }
  344. }
  345. void __cpuinit build_copy_page(void)
  346. {
  347. int off;
  348. u32 *buf = &__copy_page_start;
  349. struct uasm_label *l = labels;
  350. struct uasm_reloc *r = relocs;
  351. int i;
  352. memset(labels, 0, sizeof(labels));
  353. memset(relocs, 0, sizeof(relocs));
  354. set_prefetch_parameters();
  355. /*
  356. * This algorithm makes the following assumptions:
  357. * - All prefetch biases are multiples of 8 words.
  358. * - The prefetch biases are less than one page.
  359. * - The store prefetch bias isn't greater than the load
  360. * prefetch bias.
  361. */
  362. BUG_ON(pref_bias_copy_load % (8 * copy_word_size));
  363. BUG_ON(pref_bias_copy_store % (8 * copy_word_size));
  364. BUG_ON(PAGE_SIZE < pref_bias_copy_load);
  365. BUG_ON(pref_bias_copy_store > pref_bias_copy_load);
  366. off = PAGE_SIZE - pref_bias_copy_load;
  367. if (off > 0xffff || !pref_bias_copy_load)
  368. pg_addiu(&buf, A2, A0, off);
  369. else
  370. uasm_i_ori(&buf, A2, A0, off);
  371. if (R4600_V2_HIT_CACHEOP_WAR && cpu_is_r4600_v2_x())
  372. uasm_i_lui(&buf, AT, 0xa000);
  373. off = cache_line_size ? min(8, pref_bias_copy_load / cache_line_size) *
  374. cache_line_size : 0;
  375. while (off) {
  376. build_copy_load_pref(&buf, -off);
  377. off -= cache_line_size;
  378. }
  379. off = cache_line_size ? min(8, pref_bias_copy_store / cache_line_size) *
  380. cache_line_size : 0;
  381. while (off) {
  382. build_copy_store_pref(&buf, -off);
  383. off -= cache_line_size;
  384. }
  385. uasm_l_copy_pref_both(&l, buf);
  386. do {
  387. build_copy_load_pref(&buf, off);
  388. build_copy_load(&buf, T0, off);
  389. build_copy_load_pref(&buf, off + copy_word_size);
  390. build_copy_load(&buf, T1, off + copy_word_size);
  391. build_copy_load_pref(&buf, off + 2 * copy_word_size);
  392. build_copy_load(&buf, T2, off + 2 * copy_word_size);
  393. build_copy_load_pref(&buf, off + 3 * copy_word_size);
  394. build_copy_load(&buf, T3, off + 3 * copy_word_size);
  395. build_copy_store_pref(&buf, off);
  396. build_copy_store(&buf, T0, off);
  397. build_copy_store_pref(&buf, off + copy_word_size);
  398. build_copy_store(&buf, T1, off + copy_word_size);
  399. build_copy_store_pref(&buf, off + 2 * copy_word_size);
  400. build_copy_store(&buf, T2, off + 2 * copy_word_size);
  401. build_copy_store_pref(&buf, off + 3 * copy_word_size);
  402. build_copy_store(&buf, T3, off + 3 * copy_word_size);
  403. off += 4 * copy_word_size;
  404. } while (off < half_copy_loop_size);
  405. pg_addiu(&buf, A1, A1, 2 * off);
  406. pg_addiu(&buf, A0, A0, 2 * off);
  407. off = -off;
  408. do {
  409. build_copy_load_pref(&buf, off);
  410. build_copy_load(&buf, T0, off);
  411. build_copy_load_pref(&buf, off + copy_word_size);
  412. build_copy_load(&buf, T1, off + copy_word_size);
  413. build_copy_load_pref(&buf, off + 2 * copy_word_size);
  414. build_copy_load(&buf, T2, off + 2 * copy_word_size);
  415. build_copy_load_pref(&buf, off + 3 * copy_word_size);
  416. build_copy_load(&buf, T3, off + 3 * copy_word_size);
  417. build_copy_store_pref(&buf, off);
  418. build_copy_store(&buf, T0, off);
  419. build_copy_store_pref(&buf, off + copy_word_size);
  420. build_copy_store(&buf, T1, off + copy_word_size);
  421. build_copy_store_pref(&buf, off + 2 * copy_word_size);
  422. build_copy_store(&buf, T2, off + 2 * copy_word_size);
  423. build_copy_store_pref(&buf, off + 3 * copy_word_size);
  424. if (off == -(4 * copy_word_size))
  425. uasm_il_bne(&buf, &r, A2, A0, label_copy_pref_both);
  426. build_copy_store(&buf, T3, off + 3 * copy_word_size);
  427. off += 4 * copy_word_size;
  428. } while (off < 0);
  429. if (pref_bias_copy_load - pref_bias_copy_store) {
  430. pg_addiu(&buf, A2, A0,
  431. pref_bias_copy_load - pref_bias_copy_store);
  432. uasm_l_copy_pref_store(&l, buf);
  433. off = 0;
  434. do {
  435. build_copy_load(&buf, T0, off);
  436. build_copy_load(&buf, T1, off + copy_word_size);
  437. build_copy_load(&buf, T2, off + 2 * copy_word_size);
  438. build_copy_load(&buf, T3, off + 3 * copy_word_size);
  439. build_copy_store_pref(&buf, off);
  440. build_copy_store(&buf, T0, off);
  441. build_copy_store_pref(&buf, off + copy_word_size);
  442. build_copy_store(&buf, T1, off + copy_word_size);
  443. build_copy_store_pref(&buf, off + 2 * copy_word_size);
  444. build_copy_store(&buf, T2, off + 2 * copy_word_size);
  445. build_copy_store_pref(&buf, off + 3 * copy_word_size);
  446. build_copy_store(&buf, T3, off + 3 * copy_word_size);
  447. off += 4 * copy_word_size;
  448. } while (off < half_copy_loop_size);
  449. pg_addiu(&buf, A1, A1, 2 * off);
  450. pg_addiu(&buf, A0, A0, 2 * off);
  451. off = -off;
  452. do {
  453. build_copy_load(&buf, T0, off);
  454. build_copy_load(&buf, T1, off + copy_word_size);
  455. build_copy_load(&buf, T2, off + 2 * copy_word_size);
  456. build_copy_load(&buf, T3, off + 3 * copy_word_size);
  457. build_copy_store_pref(&buf, off);
  458. build_copy_store(&buf, T0, off);
  459. build_copy_store_pref(&buf, off + copy_word_size);
  460. build_copy_store(&buf, T1, off + copy_word_size);
  461. build_copy_store_pref(&buf, off + 2 * copy_word_size);
  462. build_copy_store(&buf, T2, off + 2 * copy_word_size);
  463. build_copy_store_pref(&buf, off + 3 * copy_word_size);
  464. if (off == -(4 * copy_word_size))
  465. uasm_il_bne(&buf, &r, A2, A0,
  466. label_copy_pref_store);
  467. build_copy_store(&buf, T3, off + 3 * copy_word_size);
  468. off += 4 * copy_word_size;
  469. } while (off < 0);
  470. }
  471. if (pref_bias_copy_store) {
  472. pg_addiu(&buf, A2, A0, pref_bias_copy_store);
  473. uasm_l_copy_nopref(&l, buf);
  474. off = 0;
  475. do {
  476. build_copy_load(&buf, T0, off);
  477. build_copy_load(&buf, T1, off + copy_word_size);
  478. build_copy_load(&buf, T2, off + 2 * copy_word_size);
  479. build_copy_load(&buf, T3, off + 3 * copy_word_size);
  480. build_copy_store(&buf, T0, off);
  481. build_copy_store(&buf, T1, off + copy_word_size);
  482. build_copy_store(&buf, T2, off + 2 * copy_word_size);
  483. build_copy_store(&buf, T3, off + 3 * copy_word_size);
  484. off += 4 * copy_word_size;
  485. } while (off < half_copy_loop_size);
  486. pg_addiu(&buf, A1, A1, 2 * off);
  487. pg_addiu(&buf, A0, A0, 2 * off);
  488. off = -off;
  489. do {
  490. build_copy_load(&buf, T0, off);
  491. build_copy_load(&buf, T1, off + copy_word_size);
  492. build_copy_load(&buf, T2, off + 2 * copy_word_size);
  493. build_copy_load(&buf, T3, off + 3 * copy_word_size);
  494. build_copy_store(&buf, T0, off);
  495. build_copy_store(&buf, T1, off + copy_word_size);
  496. build_copy_store(&buf, T2, off + 2 * copy_word_size);
  497. if (off == -(4 * copy_word_size))
  498. uasm_il_bne(&buf, &r, A2, A0,
  499. label_copy_nopref);
  500. build_copy_store(&buf, T3, off + 3 * copy_word_size);
  501. off += 4 * copy_word_size;
  502. } while (off < 0);
  503. }
  504. uasm_i_jr(&buf, RA);
  505. uasm_i_nop(&buf);
  506. BUG_ON(buf > &__copy_page_end);
  507. uasm_resolve_relocs(relocs, labels);
  508. pr_debug("Synthesized copy page handler (%u instructions).\n",
  509. (u32)(buf - &__copy_page_start));
  510. pr_debug("\t.set push\n");
  511. pr_debug("\t.set noreorder\n");
  512. for (i = 0; i < (buf - &__copy_page_start); i++)
  513. pr_debug("\t.word 0x%08x\n", (&__copy_page_start)[i]);
  514. pr_debug("\t.set pop\n");
  515. }
  516. #ifdef CONFIG_SIBYTE_DMA_PAGEOPS
  517. extern void clear_page_cpu(void *page);
  518. extern void copy_page_cpu(void *to, void *from);
  519. /*
  520. * Pad descriptors to cacheline, since each is exclusively owned by a
  521. * particular CPU.
  522. */
  523. struct dmadscr {
  524. u64 dscr_a;
  525. u64 dscr_b;
  526. u64 pad_a;
  527. u64 pad_b;
  528. } ____cacheline_aligned_in_smp page_descr[DM_NUM_CHANNELS];
  529. void sb1_dma_init(void)
  530. {
  531. int i;
  532. for (i = 0; i < DM_NUM_CHANNELS; i++) {
  533. const u64 base_val = CPHYSADDR((unsigned long)&page_descr[i]) |
  534. V_DM_DSCR_BASE_RINGSZ(1);
  535. void *base_reg = IOADDR(A_DM_REGISTER(i, R_DM_DSCR_BASE));
  536. __raw_writeq(base_val, base_reg);
  537. __raw_writeq(base_val | M_DM_DSCR_BASE_RESET, base_reg);
  538. __raw_writeq(base_val | M_DM_DSCR_BASE_ENABL, base_reg);
  539. }
  540. }
  541. void clear_page(void *page)
  542. {
  543. u64 to_phys = CPHYSADDR((unsigned long)page);
  544. unsigned int cpu = smp_processor_id();
  545. /* if the page is not in KSEG0, use old way */
  546. if ((long)KSEGX((unsigned long)page) != (long)CKSEG0)
  547. return clear_page_cpu(page);
  548. page_descr[cpu].dscr_a = to_phys | M_DM_DSCRA_ZERO_MEM |
  549. M_DM_DSCRA_L2C_DEST | M_DM_DSCRA_INTERRUPT;
  550. page_descr[cpu].dscr_b = V_DM_DSCRB_SRC_LENGTH(PAGE_SIZE);
  551. __raw_writeq(1, IOADDR(A_DM_REGISTER(cpu, R_DM_DSCR_COUNT)));
  552. /*
  553. * Don't really want to do it this way, but there's no
  554. * reliable way to delay completion detection.
  555. */
  556. while (!(__raw_readq(IOADDR(A_DM_REGISTER(cpu, R_DM_DSCR_BASE_DEBUG)))
  557. & M_DM_DSCR_BASE_INTERRUPT))
  558. ;
  559. __raw_readq(IOADDR(A_DM_REGISTER(cpu, R_DM_DSCR_BASE)));
  560. }
  561. void copy_page(void *to, void *from)
  562. {
  563. u64 from_phys = CPHYSADDR((unsigned long)from);
  564. u64 to_phys = CPHYSADDR((unsigned long)to);
  565. unsigned int cpu = smp_processor_id();
  566. /* if any page is not in KSEG0, use old way */
  567. if ((long)KSEGX((unsigned long)to) != (long)CKSEG0
  568. || (long)KSEGX((unsigned long)from) != (long)CKSEG0)
  569. return copy_page_cpu(to, from);
  570. page_descr[cpu].dscr_a = to_phys | M_DM_DSCRA_L2C_DEST |
  571. M_DM_DSCRA_INTERRUPT;
  572. page_descr[cpu].dscr_b = from_phys | V_DM_DSCRB_SRC_LENGTH(PAGE_SIZE);
  573. __raw_writeq(1, IOADDR(A_DM_REGISTER(cpu, R_DM_DSCR_COUNT)));
  574. /*
  575. * Don't really want to do it this way, but there's no
  576. * reliable way to delay completion detection.
  577. */
  578. while (!(__raw_readq(IOADDR(A_DM_REGISTER(cpu, R_DM_DSCR_BASE_DEBUG)))
  579. & M_DM_DSCR_BASE_INTERRUPT))
  580. ;
  581. __raw_readq(IOADDR(A_DM_REGISTER(cpu, R_DM_DSCR_BASE)));
  582. }
  583. #endif /* CONFIG_SIBYTE_DMA_PAGEOPS */