hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/soc/fsl/qe/qe_common.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Common CPM code
34 *
....@@ -11,10 +12,6 @@
1112 * Copyright (c) 2000 MontaVista Software, Inc (source@mvista.com)
1213 * 2006 (c) MontaVista Software, Inc.
1314 * Vitaly Bordug <vbordug@ru.mvista.com>
14
- *
15
- * This program is free software; you can redistribute it and/or modify
16
- * it under the terms of version 2 of the GNU General Public License as
17
- * published by the Free Software Foundation.
1815 */
1916 #include <linux/genalloc.h>
2017 #include <linux/init.h>
....@@ -35,7 +32,7 @@
3532
3633 struct muram_block {
3734 struct list_head head;
38
- unsigned long start;
35
+ s32 start;
3936 int size;
4037 };
4138
....@@ -49,7 +46,7 @@
4946 {
5047 struct device_node *np;
5148 struct resource r;
52
- u32 zero[OF_MAX_ADDR_CELLS] = {};
49
+ __be32 zero[OF_MAX_ADDR_CELLS] = {};
5350 resource_size_t max = 0;
5451 int i = 0;
5552 int ret = 0;
....@@ -113,34 +110,30 @@
113110 * @algo: algorithm for alloc.
114111 * @data: data for genalloc's algorithm.
115112 *
116
- * This function returns an offset into the muram area.
113
+ * This function returns a non-negative offset into the muram area, or
114
+ * a negative errno on failure.
117115 */
118
-static unsigned long cpm_muram_alloc_common(unsigned long size,
119
- genpool_algo_t algo, void *data)
116
+static s32 cpm_muram_alloc_common(unsigned long size,
117
+ genpool_algo_t algo, void *data)
120118 {
121119 struct muram_block *entry;
122
- unsigned long start;
120
+ s32 start;
123121
124
- if (!muram_pool && cpm_muram_init())
125
- goto out2;
126
-
127
- start = gen_pool_alloc_algo(muram_pool, size, algo, data);
128
- if (!start)
129
- goto out2;
130
- start = start - GENPOOL_OFFSET;
131
- memset_io(cpm_muram_addr(start), 0, size);
132122 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
133123 if (!entry)
134
- goto out1;
124
+ return -ENOMEM;
125
+ start = gen_pool_alloc_algo(muram_pool, size, algo, data);
126
+ if (!start) {
127
+ kfree(entry);
128
+ return -ENOMEM;
129
+ }
130
+ start = start - GENPOOL_OFFSET;
131
+ memset_io(cpm_muram_addr(start), 0, size);
135132 entry->start = start;
136133 entry->size = size;
137134 list_add(&entry->head, &muram_block_list);
138135
139136 return start;
140
-out1:
141
- gen_pool_free(muram_pool, start, size);
142
-out2:
143
- return (unsigned long)-ENOMEM;
144137 }
145138
146139 /*
....@@ -148,13 +141,14 @@
148141 * @size: number of bytes to allocate
149142 * @align: requested alignment, in bytes
150143 *
151
- * This function returns an offset into the muram area.
144
+ * This function returns a non-negative offset into the muram area, or
145
+ * a negative errno on failure.
152146 * Use cpm_dpram_addr() to get the virtual address of the area.
153147 * Use cpm_muram_free() to free the allocation.
154148 */
155
-unsigned long cpm_muram_alloc(unsigned long size, unsigned long align)
149
+s32 cpm_muram_alloc(unsigned long size, unsigned long align)
156150 {
157
- unsigned long start;
151
+ s32 start;
158152 unsigned long flags;
159153 struct genpool_data_align muram_pool_data;
160154
....@@ -171,11 +165,14 @@
171165 * cpm_muram_free - free a chunk of multi-user ram
172166 * @offset: The beginning of the chunk as returned by cpm_muram_alloc().
173167 */
174
-int cpm_muram_free(unsigned long offset)
168
+void cpm_muram_free(s32 offset)
175169 {
176170 unsigned long flags;
177171 int size;
178172 struct muram_block *tmp;
173
+
174
+ if (offset < 0)
175
+ return;
179176
180177 size = 0;
181178 spin_lock_irqsave(&cpm_muram_lock, flags);
....@@ -189,7 +186,6 @@
189186 }
190187 gen_pool_free(muram_pool, offset + GENPOOL_OFFSET, size);
191188 spin_unlock_irqrestore(&cpm_muram_lock, flags);
192
- return size;
193189 }
194190 EXPORT_SYMBOL(cpm_muram_free);
195191
....@@ -197,13 +193,14 @@
197193 * cpm_muram_alloc_fixed - reserve a specific region of multi-user ram
198194 * @offset: offset of allocation start address
199195 * @size: number of bytes to allocate
200
- * This function returns an offset into the muram area
196
+ * This function returns @offset if the area was available, a negative
197
+ * errno otherwise.
201198 * Use cpm_dpram_addr() to get the virtual address of the area.
202199 * Use cpm_muram_free() to free the allocation.
203200 */
204
-unsigned long cpm_muram_alloc_fixed(unsigned long offset, unsigned long size)
201
+s32 cpm_muram_alloc_fixed(unsigned long offset, unsigned long size)
205202 {
206
- unsigned long start;
203
+ s32 start;
207204 unsigned long flags;
208205 struct genpool_data_fixed muram_pool_data_fixed;
209206