page.c 18 KB

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