blob: 7ff38e67000f6f0f6a00cd9708d675ebe26f3046 [file] [log] [blame]
Andrew Scull18834872018-10-12 11:48:09 +01001/*
David Brazdilc4dfdb72019-09-23 07:39:24 +00002 * Copyright 2018 The Hafnium Authors.
Andrew Scull18834872018-10-12 11:48:09 +01003 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/BSD-3-Clause.
Andrew Scull18834872018-10-12 11:48:09 +01007 */
8
Andrew Scullfbc938a2018-08-20 14:09:28 +01009#pragma once
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010010
David Brazdilf8305e72019-09-27 13:17:52 +000011/*
12 * Includes the arch-specific definition of 'struct spinlock' and
13 * implementations of:
14 * - SPINLOCK_INIT
15 * - sl_lock()
16 * - sl_unlock()
17 */
18#include "hf/arch/spinlock.h"
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010019
20static inline void sl_init(struct spinlock *l)
21{
David Brazdilf8305e72019-09-27 13:17:52 +000022 *l = SPINLOCK_INIT;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010023}
24
Andrew Scull6386f252018-12-06 13:29:10 +000025/**
26 * Locks both locks, enforcing the lowest address first ordering for locks of
27 * the same kind.
28 */
29static inline void sl_lock_both(struct spinlock *a, struct spinlock *b)
30{
31 if (a < b) {
32 sl_lock(a);
33 sl_lock(b);
34 } else {
35 sl_lock(b);
36 sl_lock(a);
37 }
38}