1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-11-23 18:15:55 +02:00

libubb/physmem.c: new function physmem_flush to flush cached writes to memory

This is mainly a wrapper for the "cacheflush" system call.
This commit is contained in:
Werner Almesberger 2013-01-15 23:30:02 -03:00
parent 752a77f015
commit a8f905a85f
3 changed files with 38 additions and 1 deletions

View File

@ -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

View File

@ -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 <sys/types.h>
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 */

View File

@ -19,6 +19,7 @@
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <asm/cachectl.h>
#include <ubb/physmem.h>
@ -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;
}