From a8f905a85fae2721ab4d4d44d1ce4700b2ccc04c Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 15 Jan 2013 23:30:02 -0300 Subject: [PATCH] libubb/physmem.c: new function physmem_flush to flush cached writes to memory This is mainly a wrapper for the "cacheflush" system call. --- libubb/Makefile | 2 +- libubb/include/ubb/physmem.h | 24 ++++++++++++++++++++++++ libubb/physmem.c | 13 +++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 libubb/include/ubb/physmem.h diff --git a/libubb/Makefile b/libubb/Makefile index 3266274..1c23ca8 100644 --- a/libubb/Makefile +++ b/libubb/Makefile @@ -15,7 +15,7 @@ TARGET = mipsel-openwrt-linux- CC = $(TARGET)gcc LD = $(TARGET)ld -CFLAGS = -g -Wall -fPIC -Iinclude +CFLAGS = -g -Wall -fPIC -march=mips32 -Iinclude LIB = libubb.a SHLIB = libubb.so diff --git a/libubb/include/ubb/physmem.h b/libubb/include/ubb/physmem.h new file mode 100644 index 0000000..4449316 --- /dev/null +++ b/libubb/include/ubb/physmem.h @@ -0,0 +1,24 @@ +/* + * physmem.h - Physical memory translator and allocator + * + * Written 2013 by Werner Almesberger + * Copyright 2013 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef UBB_PHYSMEM_H +#define UBB_PHYSMEM_H + +#include + + +void *physmem_malloc(size_t size); +void *physmem_calloc(size_t size); +unsigned long physmem_xlat(void *v); +int physmem_flush(const void *data, size_t size); + +#endif /* !UBB_PHYSMEM_H */ diff --git a/libubb/physmem.c b/libubb/physmem.c index 6cf529d..d774180 100644 --- a/libubb/physmem.c +++ b/libubb/physmem.c @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -34,6 +35,9 @@ #define ALIGN 32 /* DMA transfer size */ +extern int cacheflush(char *addr, int nbytes, int cache); + + static void *align_brk(int alignment) { void *initial; @@ -138,3 +142,12 @@ unsigned long physmem_xlat(void *v) close(fd); return res; } + + +int physmem_flush(const void *v, size_t size) +{ + if (cacheflush((void *) v, size, DCACHE)) + return -1; + asm("sync"); /* flush the write buffer */ + return 0; +}