blob: 80d1cfc1d891296752b9d59d70c1584f15ee8259 [file] [log] [blame]
Andrew Scull18834872018-10-12 11:48:09 +01001/*
David Brazdil713580c2019-09-17 16:16:51 +01002 * Copyright 2019 The Hafnium Authors.
Andrew Scull18834872018-10-12 11:48:09 +01003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Andrew Scullfbc938a2018-08-20 14:09:28 +010017#pragma once
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010018
David Brazdil713580c2019-09-17 16:16:51 +010019/*
20 * Includes the arch-specific definition of 'struct spinlock' and
21 * implementations of:
22 * - SPINLOCK_INIT
23 * - sl_lock()
24 * - sl_unlock()
25 */
26#include "hf/arch/spinlock.h"
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010027
28static inline void sl_init(struct spinlock *l)
29{
David Brazdil713580c2019-09-17 16:16:51 +010030 *l = SPINLOCK_INIT;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010031}
32
Andrew Scull6386f252018-12-06 13:29:10 +000033/**
34 * Locks both locks, enforcing the lowest address first ordering for locks of
35 * the same kind.
36 */
37static inline void sl_lock_both(struct spinlock *a, struct spinlock *b)
38{
39 if (a < b) {
40 sl_lock(a);
41 sl_lock(b);
42 } else {
43 sl_lock(b);
44 sl_lock(a);
45 }
46}