spi-topcliff-pch: Fix issue for transmitting over 4KByte
[zen-stable.git] / arch / microblaze / kernel / selfmod.c
blob89508bdc9f3cba4e1f1372c58fc1928c9512294f
1 /*
2 * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
3 * Copyright (C) 2009 PetaLogix
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 */
10 #include <linux/interrupt.h>
11 #include <asm/selfmod.h>
13 #undef DEBUG
15 #if __GNUC__ > 3
16 #error GCC 4 unsupported SELFMOD. Please disable SELFMOD from menuconfig.
17 #endif
19 #define OPCODE_IMM 0xB0000000
20 #define OPCODE_LWI 0xE8000000
21 #define OPCODE_LWI_MASK 0xEC000000
22 #define OPCODE_RTSD 0xB60F0008 /* return from func: rtsd r15, 8 */
23 #define OPCODE_ADDIK 0x30000000
24 #define OPCODE_ADDIK_MASK 0xFC000000
26 #define IMM_BASE (OPCODE_IMM | (BARRIER_BASE_ADDR >> 16))
27 #define LWI_BASE (OPCODE_LWI | (BARRIER_BASE_ADDR & 0x0000ff00))
28 #define LWI_BASE_MASK (OPCODE_LWI_MASK | (BARRIER_BASE_ADDR & 0x0000ff00))
29 #define ADDIK_BASE (OPCODE_ADDIK | (BARRIER_BASE_ADDR & 0x0000ff00))
30 #define ADDIK_BASE_MASK (OPCODE_ADDIK_MASK | (BARRIER_BASE_ADDR & 0x0000ff00))
32 #define MODIFY_INSTR { \
33 pr_debug("%s: curr instr, (%d):0x%x, next(%d):0x%x\n", \
34 __func__, i, addr[i], i + 1, addr[i + 1]); \
35 addr[i] = OPCODE_IMM + (base >> 16); \
36 /* keep instruction opcode and add only last 16bits */ \
37 addr[i + 1] = (addr[i + 1] & 0xffff00ff) + (base & 0xffff); \
38 __invalidate_icache(addr[i]); \
39 __invalidate_icache(addr[i + 1]); \
40 pr_debug("%s: hack instr, (%d):0x%x, next(%d):0x%x\n", \
41 __func__, i, addr[i], i + 1, addr[i + 1]); }
43 /* NOTE
44 * self-modified part of code for improvement of interrupt controller
45 * save instruction in interrupt rutine
47 void selfmod_function(const int *arr_fce, const unsigned int base)
49 unsigned int flags, i, j, *addr = NULL;
51 local_irq_save(flags);
52 __disable_icache();
54 /* zero terminated array */
55 for (j = 0; arr_fce[j] != 0; j++) {
56 /* get start address of function */
57 addr = (unsigned int *) arr_fce[j];
58 pr_debug("%s: func(%d) at 0x%x\n",
59 __func__, j, (unsigned int) addr);
60 for (i = 0; ; i++) {
61 pr_debug("%s: instruction code at %d: 0x%x\n",
62 __func__, i, addr[i]);
63 if (addr[i] == IMM_BASE) {
64 /* detecting of lwi (0xE8) or swi (0xF8) instr
65 * I can detect both opcode with one mask */
66 if ((addr[i + 1] & LWI_BASE_MASK) == LWI_BASE) {
67 MODIFY_INSTR;
68 } else /* detection addik for ack */
69 if ((addr[i + 1] & ADDIK_BASE_MASK) ==
70 ADDIK_BASE) {
71 MODIFY_INSTR;
73 } else if (addr[i] == OPCODE_RTSD) {
74 /* return from function means end of function */
75 pr_debug("%s: end of array %d\n", __func__, i);
76 break;
80 local_irq_restore(flags);
81 } /* end of self-modified code */