1
/* Copyright 2013-2014 IBM Corp.
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
23
/* Lock value has bit 63 as lock bit and the PIR of the owner
26
unsigned long lock_val;
29
* Set to true if lock is involved in the console flush path
30
* in which case taking it will suspend console flushing
36
#define LOCK_UNLOCKED { .lock_val = 0, .in_con_path = 0 }
38
/* Note vs. libc and locking:
40
* The printf() family of
41
* functions use stack based t buffers and call into skiboot
42
* underlying read() and write() which use a console lock.
44
* The underlying FSP console code will thus operate within that
47
* The libc does *NOT* lock stream buffer operations, so don't
48
* try to scanf() from the same FILE from two different processors.
50
* FSP operations are locked using an FSP lock, so all processors
51
* can safely call the FSP API
53
* Note about ordering:
55
* lock() is a full memory barrier. unlock() is a lwsync
59
extern bool bust_locks;
61
static inline void init_lock(struct lock *l)
63
*l = (struct lock)LOCK_UNLOCKED;
66
extern bool __try_lock(struct lock *l);
67
extern bool try_lock(struct lock *l);
68
extern void lock(struct lock *l);
69
extern void unlock(struct lock *l);
71
extern bool lock_held_by_me(struct lock *l);
73
/* The debug output can happen while the FSP lock, so we need some kind
74
* of recursive lock support here. I don't want all locks to be recursive
75
* though, thus the caller need to explicitly call lock_recursive which
76
* returns false if the lock was already held by this cpu. If it returns
77
* true, then the caller shall release it when done.
79
extern bool lock_recursive(struct lock *l);
81
/* Called after per-cpu data structures are available */
82
extern void init_locks(void);