WARM_A = libwarm.a
WARM_SO = libwarm.so
-OBJS = warm.o sys_cacheflush.o
+OBJS = warm.o
all: $(WARM_A) $(WARM_SO) test
$(WARM_SO): $(OBJS)
$(CC) $(CFLAGS) $^ -o $@ -shared
-test: test.o
- $(CC) $(CFLAGS) $^ -o $@ libwarm.a
+test: test.o $(WARM_A)
+ $(CC) $(CFLAGS) $^ -o $@
clean:
$(RM) $(WARM_A) $(WARM_SO) $(OBJS) test test.o
CROSS_COMPILE = arm-linux-
INCLUDE = $(KERNEL_DIR)/include
-CPPFLAGS = -O2 -DMODULE -D__KERNEL__ -I${INCLUDE}
+CPPFLAGS = -Wall -O2 -DMODULE -D__KERNEL__ -msoft-float -nostdinc -isystem ${INCLUDE}
+CPPFLAGS+= -isystem $(shell $(CC) -print-file-name=include)
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
u32 desc1, desc2;
u32 *pgtable, *cpt;
u32 start, end;
+ u32 mask;
if (in_cb & WCB_C_BIT)
bits |= 8;
if (in_cb & WCB_B_BIT)
bits |= 4;
- size += addr & (PAGE_SIZE - 1);
- size = ALIGN(size, PAGE_SIZE);
+ mask = PAGE_SIZE - 1;
+ size += addr & mask;
+ size = (size + mask) & ~mask;
addr &= ~(PAGE_SIZE - 1);
start = addr;
case 3: /* fine table */
cpt = __va(desc1 & 0xfffff000);
desc2 = cpt[(addr >> 10) & 0x3ff];
+ break;
default:
return -EINVAL;
}
switch (desc2 & 3) {
case 1: /* large page */
- *_addr = (desc2 & 0xffff0000) | (addr & 0xffff);
+ *_addr = (desc2 & ~0xffff) | (addr & 0xffff);
break;
case 2: /* small page */
- *_addr = (desc2 & 0xfffff000) | (addr & 0x0fff);
+ *_addr = (desc2 & ~0x0fff) | (addr & 0x0fff);
break;
case 3: /* tiny page */
- *_addr = (desc2 & 0xfffffc00) | (addr & 0x03ff);
+ *_addr = (desc2 & ~0x03ff) | (addr & 0x03ff);
break;
default:
return -EINVAL;
-/* vim:filetype=armasm
-*/
-
-#include <linux/init.h>
+/*
+ * Cache operations
+ *
+ * Author: GraÅžvydas "notaz" Ignotas
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef AUTOCONF_INCLUDED
+#include <linux/config.h>
+#endif
#define CACHELINE_SZC #32
-#ifndef CONFIG_CPU_ARM926T
+#if !defined(CONFIG_CPU_ARM926T) && !defined(CONFIG_CPU_ARM920T)
#error CPU not supported
#endif
.align 2
.global warm_cop_clean_inval_d
+.global warm_cop_clean_d
+
+#ifdef CONFIG_CPU_ARM926T
+
warm_cop_clean_inval_d:
0: mrc p15, 0, r15, c7, c14, 3 @ test, clean and invalidate
bne 0b
bx lr
-
-.global warm_cop_clean_d
warm_cop_clean_d:
0: mrc p15, 0, r15, c7, c10, 3 @ test and clean
bne 0b
bx lr
+#else
+
+/* comes from Linux kernel code */
+.macro warm_cop_wholecache_dop crm
+ mov r1, #0x000000e0 @ 8 segments
+1: orr r3, r1, #0xfc000000 @ 64 entries
+2: mcr p15, 0, r3, c7, \crm, 2 @ D index op
+ subs r3, r3, #1<<26
+ bcs 2b @ entries 63 to 0
+ subs r1, r1, #1<<5
+ bcs 1b @ segments 7 to 0
+ bx lr
+.endm
+
+warm_cop_clean_inval_d:
+ warm_cop_wholecache_dop c14
+
+warm_cop_clean_d:
+ warm_cop_wholecache_dop c10
+
+#endif
.global warm_cop_inval_d
warm_cop_inval_d:
mcr p15, 0, r0, c8, c7, 0
bx lr
+
+@ vim:filetype=armasm
+
+++ /dev/null
-@ vim:filetype=armasm
-#include <sys/syscall.h>
-
-
-.global sys_cacheflush @ void *start_addr, void *end_addr
-
-sys_cacheflush:
- mov r2, #0
-#ifdef __ARM_EABI__
- /* EABI version */
- str r7, [sp, #-4]!
- mov r7, #(__ARM_NR_cacheflush & 0xff)
- orr r7, r7, #(__ARM_NR_cacheflush & 0x00ff00)
- orr r7, r7, #(__ARM_NR_cacheflush & 0xff0000)
- swi 0
- ldr r7, [sp], #4
-#else
- /* OABI */
- swi __ARM_NR_cacheflush
-#endif
- bx lr
-
+++ /dev/null
-
-void sys_cacheflush(void *start_addr, void *end_addr);
-
{
volatile unsigned char *buff_mapped;
volatile unsigned char *buff_vol;
- unsigned long buff_phys, align;
- unsigned char buff_mapped_vals[5];
+ unsigned long buff_phys, mapped_phys, align;
+ unsigned char buff_mapped_vals[6];
unsigned char buff_vals[5];
int random_offs;
int memdev;
srand(time(NULL));
- buff_phys = warm_virt2phys(buff);
+ buff_phys = warm_virt2phys(buff_mid);
align = buff_phys & 0xfff;
memdev = open("/dev/mem", O_RDONLY | O_SYNC);
return;
}
- /* the mapping is valid for 1 page only. */
+ /* the mapping is valid for 1 page only.
+ * Also it doesn't work for GP2X F100 (2.4 kernels?),
+ * only upper mem maps correctly there. */
buff_mapped = mmap(NULL, 0x1000, PROT_READ,
MAP_SHARED, memdev, buff_phys & ~0xfff);
if (buff_mapped == MAP_FAILED) {
}
buff_mapped += align;
+ buff_mapped_vals[5] = buff_mapped[0]; /* touch */
+ mapped_phys = warm_virt2phys((void *)buff_mapped);
+ if (buff_phys != mapped_phys)
+ printf("warning: mmap requested %08lx, got %08lx\n", buff_phys, mapped_phys);
+
random_offs = rand() % (0x1000 - align);
- buff_vol = (volatile void *)buff;
+ buff_vol = (volatile void *)buff_mid;
buff_vals[0] = buff_vol[random_offs]; buff_mapped_vals[0] = buff_mapped[random_offs];
/* incremented: */
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/utsname.h>
+#include <sys/syscall.h>
#include <errno.h>
#define WARM_CODE
#include "warm.h"
-#include "sys_cacheflush.h"
+
+extern long init_module(void *, unsigned long, const char *); /* provided by glibc */
static int warm_fd = -1;
+static int kernel_version;
+
+static void sys_cacheflush(void *start, void *end)
+{
+#ifdef __ARM_EABI__
+ /* EABI version */
+ int num = __ARM_NR_cacheflush;
+ __asm__("mov r0, %0 ;"
+ "mov r1, %1 ;"
+ "mov r2, #0 ;"
+ "mov r7, %2 ;"
+ "swi 0" : : "r" (start), "r" (end), "r" (num)
+ : "r0", "r1", "r2", "r3", "r7");
+#else
+ /* OABI */
+ __asm__("mov r0, %0 ;"
+ "mov r1, %1 ;"
+ "mov r2, #0 ;"
+ "swi %2" : : "r" (start), "r" (end), "i" __ARM_NR_cacheflush
+ : "r0", "r1", "r2", "r3");
+#endif
+}
+
+static int manual_insmod_26(const char *fname, const char *opts)
+{
+ unsigned long len, read_len;
+ int ret = -1;
+ void *buff;
+ FILE *f;
+
+ f = fopen(fname, "rb");
+ if (f == NULL)
+ return -1;
+
+ fseek(f, 0, SEEK_END);
+ len = ftell(f);
+ fseek(f, 0, SEEK_SET);
+
+ buff = malloc(len);
+ if (buff == NULL)
+ goto fail0;
+
+ read_len = fread(buff, 1, len, f);
+ if (read_len != len) {
+ fprintf(stderr, "failed to read module\n");
+ goto fail1;
+ }
+
+ ret = init_module(buff, len, opts);
+
+fail1:
+ free(buff);
+fail0:
+ fclose(f);
+ return ret;
+}
int warm_init(void)
{
struct utsname unm;
- char buff[128];
+ char buff1[32], buff2[128];
+ int ret;
warm_fd = open("/proc/warm", O_RDWR);
if (warm_fd >= 0)
memset(&unm, 0, sizeof(unm));
uname(&unm);
- snprintf(buff, sizeof(buff), "/sbin/insmod warm_%s.ko verbose=1", unm.release);
+
+ if (strlen(unm.release) < 3 || unm.release[1] != '.') {
+ fprintf(stderr, "unexpected version string: %s\n", unm.release);
+ goto fail;
+ }
+ kernel_version = ((unm.release[0] - '0') << 4) | (unm.release[2] - '0');
+
+ snprintf(buff1, sizeof(buff1), "warm_%s.%s", unm.release, kernel_version >= 0x26 ? "ko" : "o");
+ snprintf(buff2, sizeof(buff2), "/sbin/insmod %s verbose=1", buff1);
/* try to insmod */
- system(buff);
+ ret = system(buff2);
+ if (ret != 0) {
+ fprintf(stderr, "system/insmod failed: %d %d\n", ret, errno);
+ if (kernel_version >= 0x26) {
+ ret = manual_insmod_26(buff1, "verbose=1");
+ if (ret != 0)
+ fprintf(stderr, "manual insmod also failed: %d\n", ret);
+ }
+ }
+
warm_fd = open("/proc/warm", O_RDWR);
if (warm_fd >= 0)
return 0;
+fail:
fprintf(stderr, "wARM: can't init, acting as sys_cacheflush wrapper\n");
return -1;
}
void warm_finish(void)
{
- if (warm_fd >= 0)
- close(warm_fd);
- system("rmmod warm");
+ char cmd[64];
+
+ if (warm_fd < 0)
+ return;
+
+ close(warm_fd);
+ warm_fd = -1;
+
+ if (kernel_version < 0x26) {
+ struct utsname unm;
+ memset(&unm, 0, sizeof(unm));
+ uname(&unm);
+ snprintf(cmd, sizeof(cmd), "/sbin/rmmod warm_%s", unm.release);
+ }
+ else
+ strcpy(cmd, "/sbin/rmmod warm");
+
+ system(cmd);
}
int warm_cache_op_range(int op, void *addr, unsigned long size)
int ret;
if (warm_fd < 0) {
+ /* note that this won't work for warm_cache_op_all */
sys_cacheflush(addr, (char *)addr + size);
return -1;
}
int warm_cache_op_all(int op)
{
- return warm_cache_op_range(op, NULL, (size_t)-1);
+ return warm_cache_op_range(op, NULL, (unsigned long)-1);
}
int warm_change_cb_range(int cb, int is_set, void *addr, unsigned long size)