page.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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_R10000:
  126. case CPU_R12000:
  127. case CPU_R14000:
  128. /*
  129. * Those values have been experimentally tuned for an
  130. * Origin 200.
  131. */
  132. pref_bias_clear_store = 512;
  133. pref_bias_copy_load = 256;
  134. pref_bias_copy_store = 256;
  135. pref_src_mode = Pref_LoadStreamed;
  136. pref_dst_mode = Pref_StoreStreamed;
  137. break;
  138. case CPU_SB1:
  139. case CPU_SB1A:
  140. pref_bias_clear_store = 128;
  141. pref_bias_copy_load = 128;
  142. pref_bias_copy_store = 128;
  143. /*
  144. * SB1 pass1 Pref_LoadStreamed/Pref_StoreStreamed
  145. * hints are broken.
  146. */
  147. if (current_cpu_type() == CPU_SB1 &&
  148. (current_cpu_data.processor_id & 0xff) < 0x02) {
  149. pref_src_mode = Pref_Load;
  150. pref_dst_mode = Pref_Store;
  151. } else {
  152. pref_src_mode = Pref_LoadStreamed;
  153. pref_dst_mode = Pref_StoreStreamed;
  154. }
  155. break;
  156. default:
  157. pref_bias_clear_store = 128;
  158. pref_bias_copy_load = 256;
  159. pref_bias_copy_store = 128;
  160. pref_src_mode = Pref_LoadStreamed;
  161. pref_dst_mode = Pref_PrepareForStore;
  162. break;
  163. }
  164. } else {
  165. if (cpu_has_cache_cdex_s)
  166. cache_line_size = cpu_scache_line_size();
  167. else if (cpu_has_cache_cdex_p)
  168. cache_line_size = cpu_dcache_line_size();
  169. }
  170. /*
  171. * Too much unrolling will overflow the available space in
  172. * clear_space_array / copy_page_array.
  173. */
  174. half_clear_loop_size = min(16 * clear_word_size,
  175. max(cache_line_size >> 1,
  176. 4 * clear_word_size));
  177. half_copy_loop_size = min(16 * copy_word_size,
  178. max(cache_line_size >> 1,
  179. 4 * copy_word_size));
  180. }
  181. static void __cpuinit build_clear_store(u32 **buf, int off)
  182. {
  183. if (cpu_has_64bit_gp_regs || cpu_has_64bit_zero_reg) {
  184. uasm_i_sd(buf, ZERO, off, A0);
  185. } else {
  186. uasm_i_sw(buf, ZERO, off, A0);
  187. }
  188. }
  189. static inline void __cpuinit build_clear_pref(u32 **buf, int off)
  190. {
  191. if (off & cache_line_mask())
  192. return;
  193. if (pref_bias_clear_store) {
  194. uasm_i_pref(buf, pref_dst_mode, pref_bias_clear_store + off,
  195. A0);
  196. } else if (cache_line_size == (half_clear_loop_size << 1)) {
  197. if (cpu_has_cache_cdex_s) {
  198. uasm_i_cache(buf, Create_Dirty_Excl_SD, off, A0);
  199. } else if (cpu_has_cache_cdex_p) {
  200. if (R4600_V1_HIT_CACHEOP_WAR && cpu_is_r4600_v1_x()) {
  201. uasm_i_nop(buf);
  202. uasm_i_nop(buf);
  203. uasm_i_nop(buf);
  204. uasm_i_nop(buf);
  205. }
  206. if (R4600_V2_HIT_CACHEOP_WAR && cpu_is_r4600_v2_x())
  207. uasm_i_lw(buf, ZERO, ZERO, AT);
  208. uasm_i_cache(buf, Create_Dirty_Excl_D, off, A0);
  209. }
  210. }
  211. }
  212. extern u32 __clear_page_start;
  213. extern u32 __clear_page_end;
  214. extern u32 __copy_page_start;
  215. extern u32 __copy_page_end;
  216. void __cpuinit build_clear_page(void)
  217. {
  218. int off;
  219. u32 *buf = &__clear_page_start;
  220. struct uasm_label *l = labels;
  221. struct uasm_reloc *r = relocs;
  222. int i;
  223. memset(labels, 0, sizeof(labels));
  224. memset(relocs, 0, sizeof(relocs));
  225. set_prefetch_parameters();
  226. /*
  227. * This algorithm makes the following assumptions:
  228. * - The prefetch bias is a multiple of 2 words.
  229. * - The prefetch bias is less than one page.
  230. */
  231. BUG_ON(pref_bias_clear_store % (2 * clear_word_size));
  232. BUG_ON(PAGE_SIZE < pref_bias_clear_store);
  233. off = PAGE_SIZE - pref_bias_clear_store;
  234. if (off > 0xffff || !pref_bias_clear_store)
  235. pg_addiu(&buf, A2, A0, off);
  236. else
  237. uasm_i_ori(&buf, A2, A0, off);
  238. if (R4600_V2_HIT_CACHEOP_WAR && cpu_is_r4600_v2_x())
  239. uasm_i_lui(&buf, AT, 0xa000);
  240. off = cache_line_size ? min(8, pref_bias_clear_store / cache_line_size)
  241. * cache_line_size : 0;
  242. while (off) {
  243. build_clear_pref(&buf, -off);
  244. off -= cache_line_size;
  245. }
  246. uasm_l_clear_pref(&l, buf);
  247. do {
  248. build_clear_pref(&buf, off);
  249. build_clear_store(&buf, off);
  250. off += clear_word_size;
  251. } while (off < half_clear_loop_size);
  252. pg_addiu(&buf, A0, A0, 2 * off);
  253. off = -off;
  254. do {
  255. build_clear_pref(&buf, off);
  256. if (off == -clear_word_size)
  257. uasm_il_bne(&buf, &r, A0, A2, label_clear_pref);
  258. build_clear_store(&buf, off);
  259. off += clear_word_size;
  260. } while (off < 0);
  261. if (pref_bias_clear_store) {
  262. pg_addiu(&buf, A2, A0, pref_bias_clear_store);
  263. uasm_l_clear_nopref(&l, buf);
  264. off = 0;
  265. do {
  266. build_clear_store(&buf, off);
  267. off += clear_word_size;
  268. } while (off < half_clear_loop_size);
  269. pg_addiu(&buf, A0, A0, 2 * off);
  270. off = -off;
  271. do {
  272. if (off == -clear_word_size)
  273. uasm_il_bne(&buf, &r, A0, A2,
  274. label_clear_nopref);
  275. build_clear_store(&buf, off);
  276. off += clear_word_size;
  277. } while (off < 0);
  278. }
  279. uasm_i_jr(&buf, RA);
  280. uasm_i_nop(&buf);
  281. BUG_ON(buf > &__clear_page_end);
  282. uasm_resolve_relocs(relocs, labels);
  283. pr_debug("Synthesized clear page handler (%u instructions).\n",
  284. (u32)(buf - &__clear_page_start));
  285. pr_debug("\t.set push\n");
  286. pr_debug("\t.set noreorder\n");
  287. for (i = 0; i < (buf - &__clear_page_start); i++)
  288. pr_debug("\t.word 0x%08x\n", (&__clear_page_start)[i]);
  289. pr_debug("\t.set pop\n");
  290. }
  291. static void __cpuinit build_copy_load(u32 **buf, int reg, int off)
  292. {
  293. if (cpu_has_64bit_gp_regs) {
  294. uasm_i_ld(buf, reg, off, A1);
  295. } else {
  296. uasm_i_lw(buf, reg, off, A1);
  297. }
  298. }
  299. static void __cpuinit build_copy_store(u32 **buf, int reg, int off)
  300. {
  301. if (cpu_has_64bit_gp_regs) {
  302. uasm_i_sd(buf, reg, off, A0);
  303. } else {
  304. uasm_i_sw(buf, reg, off, A0);
  305. }
  306. }
  307. static inline void build_copy_load_pref(u32 **buf, int off)
  308. {
  309. if (off & cache_line_mask())
  310. return;
  311. if (pref_bias_copy_load)
  312. uasm_i_pref(buf, pref_src_mode, pref_bias_copy_load + off, A1);
  313. }
  314. static inline void build_copy_store_pref(u32 **buf, int off)
  315. {
  316. if (off & cache_line_mask())
  317. return;
  318. if (pref_bias_copy_store) {
  319. uasm_i_pref(buf, pref_dst_mode, pref_bias_copy_store + off,
  320. A0);
  321. } else if (cache_line_size == (half_copy_loop_size << 1)) {
  322. if (cpu_has_cache_cdex_s) {
  323. uasm_i_cache(buf, Create_Dirty_Excl_SD, off, A0);
  324. } else if (cpu_has_cache_cdex_p) {
  325. if (R4600_V1_HIT_CACHEOP_WAR && cpu_is_r4600_v1_x()) {
  326. uasm_i_nop(buf);
  327. uasm_i_nop(buf);
  328. uasm_i_nop(buf);
  329. uasm_i_nop(buf);
  330. }
  331. if (R4600_V2_HIT_CACHEOP_WAR && cpu_is_r4600_v2_x())
  332. uasm_i_lw(buf, ZERO, ZERO, AT);
  333. uasm_i_cache(buf, Create_Dirty_Excl_D, off, A0);
  334. }
  335. }
  336. }
  337. void __cpuinit build_copy_page(void)
  338. {
  339. int off;
  340. u32 *buf = &__copy_page_start;
  341. struct uasm_label *l = labels;
  342. struct uasm_reloc *r = relocs;
  343. int i;
  344. memset(labels, 0, sizeof(labels));
  345. memset(relocs, 0, sizeof(relocs));
  346. set_prefetch_parameters();
  347. /*
  348. * This algorithm makes the following assumptions:
  349. * - All prefetch biases are multiples of 8 words.
  350. * - The prefetch biases are less than one page.
  351. * - The store prefetch bias isn't greater than the load
  352. * prefetch bias.
  353. */
  354. BUG_ON(pref_bias_copy_load % (8 * copy_word_size));
  355. BUG_ON(pref_bias_copy_store % (8 * copy_word_size));
  356. BUG_ON(PAGE_SIZE < pref_bias_copy_load);
  357. BUG_ON(pref_bias_copy_store > pref_bias_copy_load);
  358. off = PAGE_SIZE - pref_bias_copy_load;
  359. if (off > 0xffff || !pref_bias_copy_load)
  360. pg_addiu(&buf, A2, A0, off);
  361. else
  362. uasm_i_ori(&buf, A2, A0, off);
  363. if (R4600_V2_HIT_CACHEOP_WAR && cpu_is_r4600_v2_x())
  364. uasm_i_lui(&buf, AT, 0xa000);
  365. off = cache_line_size ? min(8, pref_bias_copy_load / cache_line_size) *
  366. cache_line_size : 0;
  367. while (off) {
  368. build_copy_load_pref(&buf, -off);
  369. off -= cache_line_size;
  370. }
  371. off = cache_line_size ? min(8, pref_bias_copy_store / cache_line_size) *
  372. cache_line_size : 0;
  373. while (off) {
  374. build_copy_store_pref(&buf, -off);
  375. off -= cache_line_size;
  376. }
  377. uasm_l_copy_pref_both(&l, buf);
  378. do {
  379. build_copy_load_pref(&buf, off);
  380. build_copy_load(&buf, T0, off);
  381. build_copy_load_pref(&buf, off + copy_word_size);
  382. build_copy_load(&buf, T1, off + copy_word_size);
  383. build_copy_load_pref(&buf, off + 2 * copy_word_size);
  384. build_copy_load(&buf, T2, off + 2 * copy_word_size);
  385. build_copy_load_pref(&buf, off + 3 * copy_word_size);
  386. build_copy_load(&buf, T3, off + 3 * copy_word_size);
  387. build_copy_store_pref(&buf, off);
  388. build_copy_store(&buf, T0, off);
  389. build_copy_store_pref(&buf, off + copy_word_size);
  390. build_copy_store(&buf, T1, off + copy_word_size);
  391. build_copy_store_pref(&buf, off + 2 * copy_word_size);
  392. build_copy_store(&buf, T2, off + 2 * copy_word_size);
  393. build_copy_store_pref(&buf, off + 3 * copy_word_size);
  394. build_copy_store(&buf, T3, off + 3 * copy_word_size);
  395. off += 4 * copy_word_size;
  396. } while (off < half_copy_loop_size);
  397. pg_addiu(&buf, A1, A1, 2 * off);
  398. pg_addiu(&buf, A0, A0, 2 * off);
  399. off = -off;
  400. do {
  401. build_copy_load_pref(&buf, off);
  402. build_copy_load(&buf, T0, off);
  403. build_copy_load_pref(&buf, off + copy_word_size);
  404. build_copy_load(&buf, T1, off + copy_word_size);
  405. build_copy_load_pref(&buf, off + 2 * copy_word_size);
  406. build_copy_load(&buf, T2, off + 2 * copy_word_size);
  407. build_copy_load_pref(&buf, off + 3 * copy_word_size);
  408. build_copy_load(&buf, T3, off + 3 * copy_word_size);
  409. build_copy_store_pref(&buf, off);
  410. build_copy_store(&buf, T0, off);
  411. build_copy_store_pref(&buf, off + copy_word_size);
  412. build_copy_store(&buf, T1, off + copy_word_size);
  413. build_copy_store_pref(&buf, off + 2 * copy_word_size);
  414. build_copy_store(&buf, T2, off + 2 * copy_word_size);
  415. build_copy_store_pref(&buf, off + 3 * copy_word_size);
  416. if (off == -(4 * copy_word_size))
  417. uasm_il_bne(&buf, &r, A2, A0, label_copy_pref_both);
  418. build_copy_store(&buf, T3, off + 3 * copy_word_size);
  419. off += 4 * copy_word_size;
  420. } while (off < 0);
  421. if (pref_bias_copy_load - pref_bias_copy_store) {
  422. pg_addiu(&buf, A2, A0,
  423. pref_bias_copy_load - pref_bias_copy_store);
  424. uasm_l_copy_pref_store(&l, buf);
  425. off = 0;
  426. do {
  427. build_copy_load(&buf, T0, off);
  428. build_copy_load(&buf, T1, off + copy_word_size);
  429. build_copy_load(&buf, T2, off + 2 * copy_word_size);
  430. build_copy_load(&buf, T3, off + 3 * copy_word_size);
  431. build_copy_store_pref(&buf, off);
  432. build_copy_store(&buf, T0, off);
  433. build_copy_store_pref(&buf, off + copy_word_size);
  434. build_copy_store(&buf, T1, off + copy_word_size);
  435. build_copy_store_pref(&buf, off + 2 * copy_word_size);
  436. build_copy_store(&buf, T2, off + 2 * copy_word_size);
  437. build_copy_store_pref(&buf, off + 3 * copy_word_size);
  438. build_copy_store(&buf, T3, off + 3 * copy_word_size);
  439. off += 4 * copy_word_size;
  440. } while (off < half_copy_loop_size);
  441. pg_addiu(&buf, A1, A1, 2 * off);
  442. pg_addiu(&buf, A0, A0, 2 * off);
  443. off = -off;
  444. do {
  445. build_copy_load(&buf, T0, off);
  446. build_copy_load(&buf, T1, off + copy_word_size);
  447. build_copy_load(&buf, T2, off + 2 * copy_word_size);
  448. build_copy_load(&buf, T3, off + 3 * copy_word_size);
  449. build_copy_store_pref(&buf, off);
  450. build_copy_store(&buf, T0, off);
  451. build_copy_store_pref(&buf, off + copy_word_size);
  452. build_copy_store(&buf, T1, off + copy_word_size);
  453. build_copy_store_pref(&buf, off + 2 * copy_word_size);
  454. build_copy_store(&buf, T2, off + 2 * copy_word_size);
  455. build_copy_store_pref(&buf, off + 3 * copy_word_size);
  456. if (off == -(4 * copy_word_size))
  457. uasm_il_bne(&buf, &r, A2, A0,
  458. label_copy_pref_store);
  459. build_copy_store(&buf, T3, off + 3 * copy_word_size);
  460. off += 4 * copy_word_size;
  461. } while (off < 0);
  462. }
  463. if (pref_bias_copy_store) {
  464. pg_addiu(&buf, A2, A0, pref_bias_copy_store);
  465. uasm_l_copy_nopref(&l, buf);
  466. off = 0;
  467. do {
  468. build_copy_load(&buf, T0, off);
  469. build_copy_load(&buf, T1, off + copy_word_size);
  470. build_copy_load(&buf, T2, off + 2 * copy_word_size);
  471. build_copy_load(&buf, T3, off + 3 * copy_word_size);
  472. build_copy_store(&buf, T0, off);
  473. build_copy_store(&buf, T1, off + copy_word_size);
  474. build_copy_store(&buf, T2, off + 2 * copy_word_size);
  475. build_copy_store(&buf, T3, off + 3 * copy_word_size);
  476. off += 4 * copy_word_size;
  477. } while (off < half_copy_loop_size);
  478. pg_addiu(&buf, A1, A1, 2 * off);
  479. pg_addiu(&buf, A0, A0, 2 * off);
  480. off = -off;
  481. do {
  482. build_copy_load(&buf, T0, off);
  483. build_copy_load(&buf, T1, off + copy_word_size);
  484. build_copy_load(&buf, T2, off + 2 * copy_word_size);
  485. build_copy_load(&buf, T3, off + 3 * copy_word_size);
  486. build_copy_store(&buf, T0, off);
  487. build_copy_store(&buf, T1, off + copy_word_size);
  488. build_copy_store(&buf, T2, off + 2 * copy_word_size);
  489. if (off == -(4 * copy_word_size))
  490. uasm_il_bne(&buf, &r, A2, A0,
  491. label_copy_nopref);
  492. build_copy_store(&buf, T3, off + 3 * copy_word_size);
  493. off += 4 * copy_word_size;
  494. } while (off < 0);
  495. }
  496. uasm_i_jr(&buf, RA);
  497. uasm_i_nop(&buf);
  498. BUG_ON(buf > &__copy_page_end);
  499. uasm_resolve_relocs(relocs, labels);
  500. pr_debug("Synthesized copy page handler (%u instructions).\n",
  501. (u32)(buf - &__copy_page_start));
  502. pr_debug("\t.set push\n");
  503. pr_debug("\t.set noreorder\n");
  504. for (i = 0; i < (buf - &__copy_page_start); i++)
  505. pr_debug("\t.word 0x%08x\n", (&__copy_page_start)[i]);
  506. pr_debug("\t.set pop\n");
  507. }
  508. #ifdef CONFIG_SIBYTE_DMA_PAGEOPS
  509. extern void clear_page_cpu(void *page);
  510. extern void copy_page_cpu(void *to, void *from);
  511. /*
  512. * Pad descriptors to cacheline, since each is exclusively owned by a
  513. * particular CPU.
  514. */
  515. struct dmadscr {
  516. u64 dscr_a;
  517. u64 dscr_b;
  518. u64 pad_a;
  519. u64 pad_b;
  520. } ____cacheline_aligned_in_smp page_descr[DM_NUM_CHANNELS];
  521. void sb1_dma_init(void)
  522. {
  523. int i;
  524. for (i = 0; i < DM_NUM_CHANNELS; i++) {
  525. const u64 base_val = CPHYSADDR((unsigned long)&page_descr[i]) |
  526. V_DM_DSCR_BASE_RINGSZ(1);
  527. void *base_reg = IOADDR(A_DM_REGISTER(i, R_DM_DSCR_BASE));
  528. __raw_writeq(base_val, base_reg);
  529. __raw_writeq(base_val | M_DM_DSCR_BASE_RESET, base_reg);
  530. __raw_writeq(base_val | M_DM_DSCR_BASE_ENABL, base_reg);
  531. }
  532. }
  533. void clear_page(void *page)
  534. {
  535. u64 to_phys = CPHYSADDR((unsigned long)page);
  536. unsigned int cpu = smp_processor_id();
  537. /* if the page is not in KSEG0, use old way */
  538. if ((long)KSEGX((unsigned long)page) != (long)CKSEG0)
  539. return clear_page_cpu(page);
  540. page_descr[cpu].dscr_a = to_phys | M_DM_DSCRA_ZERO_MEM |
  541. M_DM_DSCRA_L2C_DEST | M_DM_DSCRA_INTERRUPT;
  542. page_descr[cpu].dscr_b = V_DM_DSCRB_SRC_LENGTH(PAGE_SIZE);
  543. __raw_writeq(1, IOADDR(A_DM_REGISTER(cpu, R_DM_DSCR_COUNT)));
  544. /*
  545. * Don't really want to do it this way, but there's no
  546. * reliable way to delay completion detection.
  547. */
  548. while (!(__raw_readq(IOADDR(A_DM_REGISTER(cpu, R_DM_DSCR_BASE_DEBUG)))
  549. & M_DM_DSCR_BASE_INTERRUPT))
  550. ;
  551. __raw_readq(IOADDR(A_DM_REGISTER(cpu, R_DM_DSCR_BASE)));
  552. }
  553. void copy_page(void *to, void *from)
  554. {
  555. u64 from_phys = CPHYSADDR((unsigned long)from);
  556. u64 to_phys = CPHYSADDR((unsigned long)to);
  557. unsigned int cpu = smp_processor_id();
  558. /* if any page is not in KSEG0, use old way */
  559. if ((long)KSEGX((unsigned long)to) != (long)CKSEG0
  560. || (long)KSEGX((unsigned long)from) != (long)CKSEG0)
  561. return copy_page_cpu(to, from);
  562. page_descr[cpu].dscr_a = to_phys | M_DM_DSCRA_L2C_DEST |
  563. M_DM_DSCRA_INTERRUPT;
  564. page_descr[cpu].dscr_b = from_phys | V_DM_DSCRB_SRC_LENGTH(PAGE_SIZE);
  565. __raw_writeq(1, IOADDR(A_DM_REGISTER(cpu, R_DM_DSCR_COUNT)));
  566. /*
  567. * Don't really want to do it this way, but there's no
  568. * reliable way to delay completion detection.
  569. */
  570. while (!(__raw_readq(IOADDR(A_DM_REGISTER(cpu, R_DM_DSCR_BASE_DEBUG)))
  571. & M_DM_DSCR_BASE_INTERRUPT))
  572. ;
  573. __raw_readq(IOADDR(A_DM_REGISTER(cpu, R_DM_DSCR_BASE)));
  574. }
  575. #endif /* CONFIG_SIBYTE_DMA_PAGEOPS */