2 * wARM - exporting ARM processor specific privileged services to userspace
5 * Copyright (c) GraÅžvydas "notaz" Ignotas, 2009
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of the organization nor the
15 * names of its contributors may be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/types.h>
37 #include <sys/ioctl.h>
38 #include <sys/utsname.h>
43 #include "sys_cacheflush.h"
45 static int warm_fd = -1;
52 warm_fd = open("/proc/warm", O_RDWR);
56 memset(&unm, 0, sizeof(unm));
58 snprintf(buff, sizeof(buff), "/sbin/insmod warm_%s.ko verbose=1", unm.release);
62 warm_fd = open("/proc/warm", O_RDWR);
66 fprintf(stderr, "wARM: can't init, acting as sys_cacheflush wrapper\n");
70 void warm_finish(void)
77 int warm_cache_op_range(int op, void *addr, unsigned long size)
79 struct warm_cache_op wop;
83 sys_cacheflush(addr, (char *)addr + size);
88 wop.addr = (unsigned long)addr;
91 ret = ioctl(warm_fd, WARMC_CACHE_OP, &wop);
93 perror("WARMC_CACHE_OP failed");
100 int warm_cache_op_all(int op)
102 return warm_cache_op_range(op, NULL, (size_t)-1);
105 int warm_change_cb_range(int cb, int is_set, void *addr, unsigned long size)
107 struct warm_change_cb ccb;
113 ccb.addr = (unsigned long)addr;
118 ret = ioctl(warm_fd, WARMC_CHANGE_CB, &ccb);
120 perror("WARMC_CHANGE_CB failed");
127 int warm_change_cb_upper(int cb, int is_set)
129 return warm_change_cb_range(cb, is_set, 0, 0);
132 unsigned long warm_virt2phys(const void *ptr)
137 ptrio = (unsigned long)ptr;
138 ret = ioctl(warm_fd, WARMC_VIRT2PHYS, &ptrio);
140 perror("WARMC_VIRT2PHYS failed");
141 return (unsigned long)-1;