blob: 38b663f954668b73dbfd8282a11911cf8d2fd839 [file] [log] [blame]
developer02e65912023-08-17 16:33:10 +08001/* adapter_lock.c
2 *
3 * Adapter concurrency (locking) management
4 * Linux kernel-space implementation
5 *
6 */
7
8/*****************************************************************************
9* Copyright (c) 2013-2020 by Rambus, Inc. and/or its subsidiaries.
10*
11* This program is free software: you can redistribute it and/or modify
12* it under the terms of the GNU General Public License as published by
13* the Free Software Foundation, either version 2 of the License, or
14* any later version.
15*
16* This program is distributed in the hope that it will be useful,
17* but WITHOUT ANY WARRANTY; without even the implied warranty of
18* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19* GNU General Public License for more details.
20*
21* You should have received a copy of the GNU General Public License
22* along with this program. If not, see <http://www.gnu.org/licenses/>.
23*****************************************************************************/
24
25/*----------------------------------------------------------------------------
26 * This module implements (provides) the following interface(s):
27 */
28
29// Adapter locking API
30#include "adapter_lock.h"
31
32
33/*----------------------------------------------------------------------------
34 * This module uses (requires) the following interface(s):
35 */
36
37// Driver Framework Basic Definitions API
38#include "basic_defs.h" // IDENTIFIER_NOT_USED
39
40// Adapter Lock Internal API
41#include "adapter_lock_internal.h"
42
43// Adapter Memory Allocation API
44#include "adapter_alloc.h"
45
46// Logging API
47#undef LOG_SEVERITY_MAX
48#define LOG_SEVERITY_MAX LOG_SEVERITY_WARN
49#include "log.h"
50
51// Linux Kernel API
52#include <linux/spinlock.h> // spinlock_*
53
54
55/*----------------------------------------------------------------------------
56 * Definitions and macros
57 */
58
59
60/*----------------------------------------------------------------------------
61 * Adapter_Lock_Alloc
62 */
63Adapter_Lock_t
64Adapter_Lock_Alloc(void)
65{
66 spinlock_t * Lock_p;
67
68 size_t LockSize=sizeof(spinlock_t);
69 if (LockSize==0)
70 LockSize=4;
71
72 Lock_p = Adapter_Alloc(LockSize);
73 if (Lock_p == NULL)
74 return Adapter_Lock_NULL;
75
76 Log_FormattedMessage("%s: Lock = spinlock\n", __func__);
77
78 spin_lock_init(Lock_p);
79
80 return Lock_p;
81}
82
83
84/*----------------------------------------------------------------------------
85 * Adapter_Lock_Free
86 */
87void
88Adapter_Lock_Free(Adapter_Lock_t Lock)
89{
90 Adapter_Free((void*)Lock);
91}
92
93
94/*----------------------------------------------------------------------------
95 * Adapter_Lock_Acquire
96 */
97void
98Adapter_Lock_Acquire(
99 Adapter_Lock_t Lock,
100 unsigned long * Flags)
101{
102 spin_lock_irqsave((spinlock_t *)Lock, *Flags);
103}
104
105
106/*----------------------------------------------------------------------------
107 * Adapter_Lock_Release
108 */
109void
110Adapter_Lock_Release(
111 Adapter_Lock_t Lock,
112 unsigned long * Flags)
113{
114 spin_unlock_irqrestore((spinlock_t *)Lock, *Flags);
115}
116
117
118/* end of file adapter_lock.c */