/* * User address space access functions. * The non inlined parts of asm-m32r/uaccess.h are here. * * Copyright 1997 Andi Kleen * Copyright 1997 Linus Torvalds * Copyright 2001, 2002, 2004 Hirokazu Takata */ #include #include #include #include unsigned long __generic_copy_to_user(void __user *to, const void *from, unsigned long n) { prefetch(from); if (access_ok(VERIFY_WRITE, to, n)) __copy_user(to,from,n); return n; } unsigned long __generic_copy_from_user(void *to, const void __user *from, unsigned long n) { prefetchw(to); if (access_ok(VERIFY_READ, from, n)) __copy_user_zeroing(to,from,n); else memset(to, 0, n); return n; } /* * Copy a null terminated string from userspace. */ #ifdef CONFIG_ISA_DUAL_ISSUE #define __do_strncpy_from_user(dst,src,count,res) \ do { \ int __d0, __d1, __d2; \ __asm__ __volatile__( \ " beqz %1, 2f\n" \ " .fillinsn\n" \ "0: ldb r14, @%3 || addi %3, #1\n" \ " stb r14, @%4 || addi %4, #1\n" \ " beqz r14, 1f\n" \ " addi %1, #-1\n" \ " bnez %1, 0b\n" \ " .fillinsn\n" \ "1: sub %0, %1\n" \ " .fillinsn\n" \ "2:\n" \ ".section .fixup,\"ax\"\n" \ " .balign 4\n" \ "3: seth r14, #high(2b)\n" \ " or3 r14, r14, #low(2b)\n" \ " jmp r14 || ldi %0, #%5\n" \ ".previous\n" \ ".section __ex_table,\"a\"\n" \ " .balign 4\n" \ " .long 0b,3b\n" \ ".previous" \ : "=&r"(res), "=&r"(count), "=&r" (__d0), "=&r" (__d1), \ "=&r" (__d2) \ : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), \ "4"(dst) \ : "r14", "cbit", "memory"); \ } while (0) #else /* not CONFIG_ISA_DUAL_ISSUE */ #define __do_strncpy_from_user(dst,src,count,res) \ do { \ int __d0, __d1, __d2; \ __asm__ __volatile__( \ " beqz %1, 2f\n" \ " .fillinsn\n" \ "0: ldb r14, @%3\n" \ " stb r14, @%4\n" \ " addi %3, #1\n" \ " addi %4, #1\n" \ " beqz r14, 1f\n" \ " addi %1, #-1\n" \ " bnez %1, 0b\n" \ " .fillinsn\n" \ "1: sub %0, %1\n" \ " .fillinsn\n" \ "2:\n" \ ".section .fixup,\"ax\"\n" \ " .balign 4\n" \ "3: ldi %0, #%5\n" \ " seth r14, #high(2b)\n" \ " or3 r14, r14, #low(2b)\n" \ " jmp r14\n" \ ".previous\n" \ ".section __ex_table,\"a\"\n" \ " .balign 4\n" \ " .long 0b,3b\n" \ ".previous" \ : "=&r"(res), "=&r"(count), "=&r" (__d0), "=&r" (__d1), \ "=&r" (__d2) \ : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), \ "4"(dst) \ : "r14", "cbit", "memory"); \ } while (0) #endif /* CONFIG_ISA_DUAL_ISSUE */ long __strncpy_from_user(char *dst, const char __user *src, long count) { long res; __do_strncpy_from_user(dst, src, count, res); return res; } long strncpy_from_user(char *dst, const char __user *src, long count) { long res = -EFAULT; if (access_ok(VERIFY_READ, src, 1)) __do_strncpy_from_user(dst, src, count, res); return res; } /* * Zero Userspace */ #ifdef CONFIG_ISA_DUAL_ISSUE #define __do_clear_user(addr,size) \ do { \ int __dst, __c; \ __asm__ __volatile__( \ " beqz %1, 9f\n" \ " and3 r14, %0, #3\n" \ " bnez r14, 2f\n" \ " and3 r14, %1, #3\n" \ " bnez r14, 2f\n" \ " and3 %1, %1, #3\n" \ " beqz %2, 2f\n" \ " addi %0, #-4\n" \ " .fillinsn\n" \ "0: ; word clear \n" \ " st %6, @+%0 || addi %2, #-1\n" \ " bnez %2, 0b\n" \ " beqz %1, 9f\n" \ " .fillinsn\n" \ "2: ; byte clear \n" \ " stb %6, @%0 || addi %1, #-1\n" \ " addi %0, #1\n" \ " bnez %1, 2b\n" \ " .fillinsn\n" \ "9:\n" \ ".section .fixup,\"ax\"\n" \ " .balign 4\n" \ "4: slli %2, #2\n" \ " seth r14, #high(9b)\n" \ " or3 r14, r14, #low(9b)\n" \ " jmp r14 || add %1, %2\n" \ ".previous\n" \ ".section __ex_table,\"a\"\n" \ " .balign 4\n" \ " .long 0b,4b\n" \ " .long 2b,9b\n" \ ".previous\n" \ : "=&r"(__dst), "=&r"(size), "=&r"(__c) \ : "0"(addr), "1"(size), "2"(size / 4), "r"(0) \ : "r14", "cbit", "memory"); \ } while (0) #else /* not CONFIG_ISA_DUAL_ISSUE */ #define __do_clear_user(addr,size) \ do { \ int __dst, __c; \ __asm__ __volatile__( \ " beqz %1, 9f\n" \ " and3 r14, %0, #3\n" \ " bnez r14, 2f\n" \ " and3 r14, %1, #3\n" \ " bnez r14, 2f\n" \ " and3 %1, %1, #3\n" \ " beqz %2, 2f\n" \ " addi %0, #-4\n" \ " .fillinsn\n" \ "0: st %6, @+%0 ; word clear \n" \ " addi %2, #-1\n" \ " bnez %2, 0b\n" \ " beqz %1, 9f\n" \ " .fillinsn\n" \ "2: stb %6, @%0 ; byte clear \n" \ " addi %1, #-1\n" \ " addi %0, #1\n" \ " bnez %1, 2b\n" \ " .fillinsn\n" \ "9:\n" \ ".section .fixup,\"ax\"\n" \ " .balign 4\n" \ "4: slli %2, #2\n" \ " add %1, %2\n" \ " seth r14, #high(9b)\n" \ " or3 r14, r14, #low(9b)\n" \ " jmp r14\n" \ ".previous\n" \ ".section __ex_table,\"a\"\n" \ " .balign 4\n" \ " .long 0b,4b\n" \ " .long 2b,9b\n" \ ".previous\n" \ : "=&r"(__dst), "=&r"(size), "=&r"(__c) \ : "0"(addr), "1"(size), "2"(size / 4), "r"(0) \ : "r14", "cbit", "memory"); \ } while (0) #endif /* not CONFIG_ISA_DUAL_ISSUE */ unsigned long clear_user(void __user *to, unsigned long n) { if (access_ok(VERIFY_WRITE, to, n)) __do_clear_user(to, n); return n; } unsigned long __clear_user(void __user *to, unsigned long n) { __do_clear_user(to, n); return n; } /* * Return the size of a string (including the ending 0) * * Return 0 on exception, a value greater than N if too long */ #ifdef CONFIG_ISA_DUAL_ISSUE long strnlen_user(const char __user *s, long n) { unsigned long mask = -__addr_ok(s); unsigned long res; __asm__ __volatile__( " and %0, %5 || mv r1, %1\n" " beqz %0, strnlen_exit\n" " and3 r0, %1, #3\n" " bnez r0, strnlen_byte_loop\n" " cmpui %0, #4\n" " bc strnlen_byte_loop\n" "strnlen_word_loop:\n" "0: ld r0, @%1+\n" " pcmpbz r0\n" " bc strnlen_last_bytes_fixup\n" " addi %0, #-4\n" " beqz %0, strnlen_exit\n" " bgtz %0, strnlen_word_loop\n" "strnlen_last_bytes:\n" " mv %0, %4\n" "strnlen_last_bytes_fixup:\n" " addi %1, #-4\n" "strnlen_byte_loop:\n" "1: ldb r0, @%1 || addi %0, #-1\n" " beqz r0, strnlen_exit\n" " addi %1, #1\n" " bnez %0, strnlen_byte_loop\n" "strnlen_exit:\n" " sub %1, r1\n" " add3 %0, %1, #1\n" " .fillinsn\n" "9:\n" ".section .fixup,\"ax\"\n" " .balign 4\n" "4: addi %1, #-4\n" " .fillinsn\n" "5: seth r1, #high(9b)\n" " or3 r1, r1, #low(9b)\n" " jmp r1 || ldi %0, #0\n" ".previous\n" ".section __ex_table,\"a\"\n" " .balign 4\n" " .long 0b,4b\n" " .long 1b,5b\n" ".previous" : "=&r" (res), "=r" (s) : "0" (n), "1" (s), "r" (n & 3), "r" (mask), "r"(0x01010101) : "r0", "r1", "cbit"); /* NOTE: strnlen_user() algorithm: * { * char *p; * for (p = s; n-- && *p != '\0'; ++p) * ; * return p - s + 1; * } */ /* NOTE: If a null char. exists, return 0. * if ((x - 0x01010101) & ~x & 0x80808080)\n" * return 0;\n" */ return res & mask; } #else /* not CONFIG_ISA_DUAL_ISSUE */ long strnlen_user(const char __user *s, long n) { unsigned long mask = -__addr_ok(s); unsigned long res; __asm__ __volatile__( " and %0, %5\n" " mv r1, %1\n" " beqz %0, strnlen_exit\n" " and3 r0, %1, #3\n" " bnez r0, strnlen_byte_loop\n" " cmpui %0, #4\n" " bc strnlen_byte_loop\n" " sll3 r3, %6, #7\n" "strnlen_word_loop:\n" "0: ld r0, @%1+\n" " not r2, r0\n" " sub r0, %6\n" " and r2, r3\n" " and r2, r0\n" " bnez r2, strnlen_last_bytes_fixup\n" " addi %0, #-4\n" " beqz %0, strnlen_exit\n" " bgtz %0, strnlen_word_loop\n" "strnlen_last_bytes:\n" " mv %0, %4\n" "strnlen_last_bytes_fixup:\n" " addi %1, #-4\n" "strnlen_byte_loop:\n" "1: ldb r0, @%1\n" " addi %0, #-1\n" " beqz r0, strnlen_exit\n" " addi %1, #1\n" " bnez %0, strnlen_byte_loop\n" "strnlen_exit:\n" " sub %1, r1\n" " add3 %0, %1, #1\n" " .fillinsn\n" "9:\n" ".section .fixup,\"ax\"\n" " .balign 4\n" "4: addi %1, #-4\n" " .fillinsn\n" "5: ldi %0, #0\n" " seth r1, #high(9b)\n" " or3 r1, r1, #low(9b)\n" " jmp r1\n" ".previous\n" ".section __ex_table,\"a\"\n" " .balign 4\n" " .long 0b,4b\n" " .long 1b,5b\n" ".previous" : "=&r" (res), "=r" (s) : "0" (n), "1" (s), "r" (n & 3), "r" (mask), "r"(0x01010101) : "r0", "r1", "r2", "r3", "cbit"); /* NOTE: strnlen_user() algorithm: * { * char *p; * for (p = s; n-- && *p != '\0'; ++p) * ; * return p - s + 1; * } */ /* NOTE: If a null char. exists, return 0. * if ((x - 0x01010101) & ~x & 0x80808080)\n" * return 0;\n" */ return res & mask; } #endif /* CONFIG_ISA_DUAL_ISSUE */ href='#n149'>149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
/*
 * Driver/API for AMD Geode Multi-Function General Purpose Timers (MFGPT)
 *
 * Copyright (C) 2006, Advanced Micro Devices, Inc.
 * Copyright (C) 2007, Andres Salomon <dilinger@debian.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public License
 * as published by the Free Software Foundation.
 *
 * The MFGPTs are documented in AMD Geode CS5536 Companion Device Data Book.
 */

/*
 * We are using the 32.768kHz input clock - it's the only one that has the
 * ranges we find desirable.  The following table lists the suitable
 * divisors and the associated Hz, minimum interval and the maximum interval:
 *
 *  Divisor   Hz      Min Delta (s)  Max Delta (s)
 *   1        32768   .00048828125      2.000
 *   2        16384   .0009765625       4.000
 *   4         8192   .001953125        8.000
 *   8         4096   .00390625        16.000
 *   16        2048   .0078125         32.000
 *   32        1024   .015625          64.000
 *   64         512   .03125          128.000
 *  128         256   .0625           256.000
 *  256         128   .125            512.000
 */

#include <linux/kernel.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <asm/geode.h>

#define MFGPT_DEFAULT_IRQ	7

static struct mfgpt_timer_t {
	unsigned int avail:1;
} mfgpt_timers[MFGPT_MAX_TIMERS];

/* Selected from the table above */

#define MFGPT_DIVISOR 16
#define MFGPT_SCALE  4     /* divisor = 2^(scale) */
#define MFGPT_HZ  (32768 / MFGPT_DIVISOR)
#define MFGPT_PERIODIC (MFGPT_HZ / HZ)

/* Allow for disabling of MFGPTs */
static int disable;
static int __init mfgpt_disable(char *s)
{
	disable = 1;
	return 1;
}
__setup("nomfgpt", mfgpt_disable);

/* Reset the MFGPT timers. This is required by some broken BIOSes which already
 * do the same and leave the system in an unstable state. TinyBIOS 0.98 is
 * affected at least (0.99 is OK with MFGPT workaround left to off).
 */
static int __init mfgpt_fix(char *s)
{
	u32 val, dummy;

	/* The following udocumented bit resets the MFGPT timers */
	val = 0xFF; dummy = 0;
	wrmsr(MSR_MFGPT_SETUP, val, dummy);
	return 1;
}
__setup("mfgptfix", mfgpt_fix);

/*
 * Check whether any MFGPTs are available for the kernel to use.  In most
 * cases, firmware that uses AMD's VSA code will claim all timers during
 * bootup; we certainly don't want to take them if they're already in use.