Home | History | Annotate | Line # | Download | only in include
lock.h revision 1.14.18.1
      1  1.14.18.1      yamt /*	$NetBSD: lock.h,v 1.14.18.1 2008/05/18 12:32:43 yamt Exp $	*/
      2        1.1   thorpej 
      3        1.1   thorpej /*-
      4        1.4  gmcgarry  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5        1.1   thorpej  * All rights reserved.
      6        1.1   thorpej  *
      7        1.1   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8        1.4  gmcgarry  * by Gregory McGarry.
      9        1.1   thorpej  *
     10        1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     11        1.1   thorpej  * modification, are permitted provided that the following conditions
     12        1.1   thorpej  * are met:
     13        1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     14        1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     15        1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17        1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     18        1.1   thorpej  *
     19        1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1   thorpej  */
     31        1.1   thorpej 
     32        1.1   thorpej /*
     33        1.1   thorpej  * Machine-dependent spin lock operations.
     34        1.1   thorpej  */
     35        1.1   thorpej 
     36        1.1   thorpej #ifndef _SH3_LOCK_H_
     37        1.1   thorpej #define	_SH3_LOCK_H_
     38        1.4  gmcgarry 
     39       1.10       uwe static __inline void __cpu_simple_lock_init(__cpu_simple_lock_t *)
     40        1.4  gmcgarry 	__attribute__((__unused__));
     41       1.10       uwe static __inline void __cpu_simple_lock(__cpu_simple_lock_t *)
     42        1.4  gmcgarry 	__attribute__((__unused__));
     43       1.10       uwe static __inline int __cpu_simple_lock_try(__cpu_simple_lock_t *)
     44        1.4  gmcgarry 	__attribute__((__unused__));
     45       1.10       uwe static __inline void __cpu_simple_unlock(__cpu_simple_lock_t *)
     46        1.4  gmcgarry 	__attribute__((__unused__));
     47        1.4  gmcgarry 
     48       1.13     skrll static __inline int
     49       1.13     skrll __SIMPLELOCK_LOCKED_P(__cpu_simple_lock_t *__ptr)
     50       1.13     skrll {
     51       1.13     skrll 	return *__ptr == __SIMPLELOCK_LOCKED;
     52       1.13     skrll }
     53       1.13     skrll 
     54       1.13     skrll static __inline int
     55       1.13     skrll __SIMPLELOCK_UNLOCKED_P(__cpu_simple_lock_t *__ptr)
     56       1.13     skrll {
     57       1.13     skrll 	return *__ptr == __SIMPLELOCK_UNLOCKED;
     58       1.13     skrll }
     59       1.13     skrll 
     60       1.13     skrll static __inline void
     61       1.13     skrll __cpu_simple_lock_clear(__cpu_simple_lock_t *__ptr)
     62       1.13     skrll {
     63       1.13     skrll 	*__ptr = __SIMPLELOCK_UNLOCKED;
     64       1.13     skrll }
     65       1.13     skrll 
     66       1.13     skrll static __inline void
     67       1.13     skrll __cpu_simple_lock_set(__cpu_simple_lock_t *__ptr)
     68       1.13     skrll {
     69       1.13     skrll 	*__ptr = __SIMPLELOCK_LOCKED;
     70       1.13     skrll }
     71       1.13     skrll 
     72        1.9     perry static __inline void
     73        1.4  gmcgarry __cpu_simple_lock_init(__cpu_simple_lock_t *alp)
     74        1.4  gmcgarry {
     75        1.4  gmcgarry 
     76        1.4  gmcgarry 	*alp = __SIMPLELOCK_UNLOCKED;
     77        1.4  gmcgarry }
     78        1.4  gmcgarry 
     79        1.9     perry static __inline void
     80        1.4  gmcgarry __cpu_simple_lock(__cpu_simple_lock_t *alp)
     81        1.4  gmcgarry {
     82        1.4  gmcgarry 
     83        1.8     perry 	 __asm volatile(
     84        1.4  gmcgarry 		"1:	tas.b	%0	\n"
     85        1.4  gmcgarry 		"	bf	1b	\n"
     86       1.12       uwe 		: "=m" (*alp)
     87       1.12       uwe 		: /* no inputs */
     88       1.12       uwe 		: "cc");
     89        1.4  gmcgarry }
     90        1.4  gmcgarry 
     91        1.9     perry static __inline int
     92        1.4  gmcgarry __cpu_simple_lock_try(__cpu_simple_lock_t *alp)
     93        1.4  gmcgarry {
     94        1.4  gmcgarry 	int __rv;
     95        1.4  gmcgarry 
     96        1.8     perry 	__asm volatile(
     97        1.4  gmcgarry 		"	tas.b	%0	\n"
     98       1.12       uwe 		"	movt	%1	\n"
     99       1.12       uwe 		: "=m" (*alp), "=r" (__rv)
    100       1.12       uwe 		: /* no inputs */
    101       1.12       uwe 		: "cc");
    102        1.4  gmcgarry 
    103        1.4  gmcgarry 	return (__rv);
    104        1.4  gmcgarry }
    105        1.4  gmcgarry 
    106        1.9     perry static __inline void
    107        1.4  gmcgarry __cpu_simple_unlock(__cpu_simple_lock_t *alp)
    108        1.4  gmcgarry {
    109        1.4  gmcgarry 
    110        1.4  gmcgarry 	*alp = __SIMPLELOCK_UNLOCKED;
    111        1.4  gmcgarry }
    112        1.1   thorpej 
    113       1.11        ad static __inline void
    114       1.11        ad mb_read(void)
    115       1.11        ad {
    116       1.11        ad 	__asm volatile("" : : : "memory");
    117       1.11        ad }
    118       1.11        ad 
    119       1.11        ad static __inline void
    120       1.11        ad mb_write(void)
    121       1.11        ad {
    122       1.11        ad 	__asm volatile("" : : : "memory");
    123       1.11        ad }
    124       1.11        ad 
    125       1.11        ad static __inline void
    126       1.11        ad mb_memory(void)
    127       1.11        ad {
    128       1.11        ad 	__asm volatile("" : : : "memory");
    129       1.11        ad }
    130       1.11        ad 
    131        1.3       uch #endif /* !_SH3_LOCK_H_ */
    132