~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/skiboot/include/lock.h

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2013-2014 IBM Corp.
 
2
 *
 
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
 
6
 *
 
7
 *      http://www.apache.org/licenses/LICENSE-2.0
 
8
 *
 
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
 
12
 * implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#ifndef __LOCK_H
 
18
#define __LOCK_H
 
19
 
 
20
#include <stdbool.h>
 
21
 
 
22
struct lock {
 
23
        /* Lock value has bit 63 as lock bit and the PIR of the owner
 
24
         * in the top 32-bit
 
25
         */
 
26
        unsigned long lock_val;
 
27
 
 
28
        /*
 
29
         * Set to true if lock is involved in the console flush path
 
30
         * in which case taking it will suspend console flushing
 
31
         */
 
32
        bool in_con_path;
 
33
};
 
34
 
 
35
/* Initializer */
 
36
#define LOCK_UNLOCKED   { .lock_val = 0, .in_con_path = 0 }
 
37
 
 
38
/* Note vs. libc and locking:
 
39
 *
 
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.
 
43
 *
 
44
 * The underlying FSP console code will thus operate within that
 
45
 * console lock.
 
46
 *
 
47
 * The libc does *NOT* lock stream buffer operations, so don't
 
48
 * try to scanf() from the same FILE from two different processors.
 
49
 *
 
50
 * FSP operations are locked using an FSP lock, so all processors
 
51
 * can safely call the FSP API
 
52
 *
 
53
 * Note about ordering:
 
54
 *
 
55
 * lock() is a full memory barrier. unlock() is a lwsync
 
56
 *
 
57
 */
 
58
 
 
59
extern bool bust_locks;
 
60
 
 
61
static inline void init_lock(struct lock *l)
 
62
{
 
63
        *l = (struct lock)LOCK_UNLOCKED;
 
64
}
 
65
 
 
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);
 
70
 
 
71
extern bool lock_held_by_me(struct lock *l);
 
72
 
 
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.
 
78
 */
 
79
extern bool lock_recursive(struct lock *l);
 
80
 
 
81
/* Called after per-cpu data structures are available */
 
82
extern void init_locks(void);
 
83
 
 
84
#endif /* __LOCK_H */