Lines Matching +full:block +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0-or-later
21 mutex_lock(&alloc->memory_mutex); in snd_gf1_mem_lock()
23 mutex_unlock(&alloc->memory_mutex); in snd_gf1_mem_lock()
28 snd_gf1_mem_xalloc(struct snd_gf1_mem *alloc, struct snd_gf1_mem_block *block, in snd_gf1_mem_xalloc() argument
36 *nblock = *block; in snd_gf1_mem_xalloc()
37 nblock->name = kstrdup(name, GFP_KERNEL); in snd_gf1_mem_xalloc()
38 if (!nblock->name) { in snd_gf1_mem_xalloc()
43 pblock = alloc->first; in snd_gf1_mem_xalloc()
45 if (pblock->ptr > nblock->ptr) { in snd_gf1_mem_xalloc()
46 nblock->prev = pblock->prev; in snd_gf1_mem_xalloc()
47 nblock->next = pblock; in snd_gf1_mem_xalloc()
48 pblock->prev = nblock; in snd_gf1_mem_xalloc()
49 if (pblock == alloc->first) in snd_gf1_mem_xalloc()
50 alloc->first = nblock; in snd_gf1_mem_xalloc()
52 nblock->prev->next = nblock; in snd_gf1_mem_xalloc()
53 mutex_unlock(&alloc->memory_mutex); in snd_gf1_mem_xalloc()
56 pblock = pblock->next; in snd_gf1_mem_xalloc()
58 nblock->next = NULL; in snd_gf1_mem_xalloc()
59 if (alloc->last == NULL) { in snd_gf1_mem_xalloc()
60 nblock->prev = NULL; in snd_gf1_mem_xalloc()
61 alloc->first = alloc->last = nblock; in snd_gf1_mem_xalloc()
63 nblock->prev = alloc->last; in snd_gf1_mem_xalloc()
64 alloc->last->next = nblock; in snd_gf1_mem_xalloc()
65 alloc->last = nblock; in snd_gf1_mem_xalloc()
70 int snd_gf1_mem_xfree(struct snd_gf1_mem * alloc, struct snd_gf1_mem_block * block) in snd_gf1_mem_xfree() argument
72 if (block->share) { /* ok.. shared block */ in snd_gf1_mem_xfree()
73 block->share--; in snd_gf1_mem_xfree()
74 mutex_unlock(&alloc->memory_mutex); in snd_gf1_mem_xfree()
77 if (alloc->first == block) { in snd_gf1_mem_xfree()
78 alloc->first = block->next; in snd_gf1_mem_xfree()
79 if (block->next) in snd_gf1_mem_xfree()
80 block->next->prev = NULL; in snd_gf1_mem_xfree()
82 block->prev->next = block->next; in snd_gf1_mem_xfree()
83 if (block->next) in snd_gf1_mem_xfree()
84 block->next->prev = block->prev; in snd_gf1_mem_xfree()
86 if (alloc->last == block) { in snd_gf1_mem_xfree()
87 alloc->last = block->prev; in snd_gf1_mem_xfree()
88 if (block->prev) in snd_gf1_mem_xfree()
89 block->prev->next = NULL; in snd_gf1_mem_xfree()
91 block->next->prev = block->prev; in snd_gf1_mem_xfree()
92 if (block->prev) in snd_gf1_mem_xfree()
93 block->prev->next = block->next; in snd_gf1_mem_xfree()
95 kfree(block->name); in snd_gf1_mem_xfree()
96 kfree(block); in snd_gf1_mem_xfree()
103 struct snd_gf1_mem_block *block; in snd_gf1_mem_look() local
105 for (block = alloc->first; block; block = block->next) { in snd_gf1_mem_look()
106 if (block->ptr == address) { in snd_gf1_mem_look()
107 return block; in snd_gf1_mem_look()
116 struct snd_gf1_mem_block *block; in snd_gf1_mem_share() local
121 for (block = alloc->first; block; block = block->next) in snd_gf1_mem_share()
122 if (!memcmp(share_id, block->share_id, in snd_gf1_mem_share()
123 sizeof(block->share_id))) in snd_gf1_mem_share()
124 return block; in snd_gf1_mem_share()
129 struct snd_gf1_mem_block * block, in snd_gf1_mem_find() argument
130 unsigned int size, int w_16, int align) in snd_gf1_mem_find() argument
132 struct snd_gf1_bank_info *info = w_16 ? alloc->banks_16 : alloc->banks_8; in snd_gf1_mem_find()
140 block->flags = w_16 ? SNDRV_GF1_MEM_BLOCK_16BIT : 0; in snd_gf1_mem_find()
141 block->owner = SNDRV_GF1_MEM_OWNER_DRIVER; in snd_gf1_mem_find()
142 block->share = 0; in snd_gf1_mem_find()
143 block->share_id[0] = block->share_id[1] = in snd_gf1_mem_find()
144 block->share_id[2] = block->share_id[3] = 0; in snd_gf1_mem_find()
145 block->name = NULL; in snd_gf1_mem_find()
146 block->prev = block->next = NULL; in snd_gf1_mem_find()
147 for (pblock = alloc->first, idx = 0; pblock; pblock = pblock->next) { in snd_gf1_mem_find()
148 while (pblock->ptr >= (boundary = info[idx].address + info[idx].size)) in snd_gf1_mem_find()
150 while (pblock->ptr + pblock->size >= (boundary = info[idx].address + info[idx].size)) in snd_gf1_mem_find()
153 if (pblock->next) { in snd_gf1_mem_find()
154 if (pblock->ptr + pblock->size == pblock->next->ptr) in snd_gf1_mem_find()
156 if (pblock->next->ptr < boundary) in snd_gf1_mem_find()
157 ptr2 = pblock->next->ptr; in snd_gf1_mem_find()
159 ptr1 = ALIGN(pblock->ptr + pblock->size, align); in snd_gf1_mem_find()
162 size1 = ptr2 - ptr1; in snd_gf1_mem_find()
163 if ((int)size <= size1) { in snd_gf1_mem_find()
164 block->ptr = ptr1; in snd_gf1_mem_find()
165 block->size = size; in snd_gf1_mem_find()
170 if (size <= info[idx].size) { in snd_gf1_mem_find()
172 block->ptr = info[idx].address; in snd_gf1_mem_find()
173 block->size = size; in snd_gf1_mem_find()
177 return -ENOMEM; in snd_gf1_mem_find()
181 char *name, int size, int w_16, int align, in snd_gf1_mem_alloc() argument
184 struct snd_gf1_mem_block block, *nblock; in snd_gf1_mem_alloc() local
190 if (size != (int)nblock->size) { in snd_gf1_mem_alloc()
192 pr_err("%s - share: sizes differ\n", __func__); in snd_gf1_mem_alloc()
195 nblock->share++; in snd_gf1_mem_alloc()
201 if (snd_gf1_mem_find(alloc, &block, size, w_16, align) < 0) { in snd_gf1_mem_alloc()
206 memcpy(&block.share_id, share_id, sizeof(block.share_id)); in snd_gf1_mem_alloc()
207 block.owner = owner; in snd_gf1_mem_alloc()
208 nblock = snd_gf1_mem_xalloc(alloc, &block, name); in snd_gf1_mem_alloc()
216 struct snd_gf1_mem_block *block; in snd_gf1_mem_free() local
219 block = snd_gf1_mem_look(alloc, address); in snd_gf1_mem_free()
220 if (block) { in snd_gf1_mem_free()
221 result = snd_gf1_mem_xfree(alloc, block); in snd_gf1_mem_free()
226 return -EINVAL; in snd_gf1_mem_free()
232 struct snd_gf1_mem_block block; in snd_gf1_mem_init() local
234 alloc = &gus->gf1.mem_alloc; in snd_gf1_mem_init()
235 mutex_init(&alloc->memory_mutex); in snd_gf1_mem_init()
236 alloc->first = alloc->last = NULL; in snd_gf1_mem_init()
237 if (!gus->gf1.memory) in snd_gf1_mem_init()
240 memset(&block, 0, sizeof(block)); in snd_gf1_mem_init()
241 block.owner = SNDRV_GF1_MEM_OWNER_DRIVER; in snd_gf1_mem_init()
242 if (gus->gf1.enh_mode) { in snd_gf1_mem_init()
243 block.ptr = 0; in snd_gf1_mem_init()
244 block.size = 1024; in snd_gf1_mem_init()
245 if (!snd_gf1_mem_xalloc(alloc, &block, "InterWave LFOs")) in snd_gf1_mem_init()
246 return -ENOMEM; in snd_gf1_mem_init()
248 block.ptr = gus->gf1.default_voice_address; in snd_gf1_mem_init()
249 block.size = 4; in snd_gf1_mem_init()
250 if (!snd_gf1_mem_xalloc(alloc, &block, "Voice default (NULL's)")) in snd_gf1_mem_init()
251 return -ENOMEM; in snd_gf1_mem_init()
253 snd_card_ro_proc_new(gus->card, "gusmem", gus, snd_gf1_mem_info_read); in snd_gf1_mem_init()
261 struct snd_gf1_mem_block *block, *nblock; in snd_gf1_mem_done() local
263 alloc = &gus->gf1.mem_alloc; in snd_gf1_mem_done()
264 block = alloc->first; in snd_gf1_mem_done()
265 while (block) { in snd_gf1_mem_done()
266 nblock = block->next; in snd_gf1_mem_done()
267 snd_gf1_mem_xfree(alloc, block); in snd_gf1_mem_done()
268 block = nblock; in snd_gf1_mem_done()
279 struct snd_gf1_mem_block *block; in snd_gf1_mem_info_read() local
283 gus = entry->private_data; in snd_gf1_mem_info_read()
284 alloc = &gus->gf1.mem_alloc; in snd_gf1_mem_info_read()
285 mutex_lock(&alloc->memory_mutex); in snd_gf1_mem_info_read()
286 snd_iprintf(buffer, "8-bit banks : \n "); in snd_gf1_mem_info_read()
288 …snd_iprintf(buffer, "0x%06x (%04ik)%s", alloc->banks_8[i].address, alloc->banks_8[i].size >> 10, i… in snd_gf1_mem_info_read()
290 "16-bit banks : \n "); in snd_gf1_mem_info_read()
292 …snd_iprintf(buffer, "0x%06x (%04ik)%s", alloc->banks_16[i].address, alloc->banks_16[i].size >> 10,… in snd_gf1_mem_info_read()
293 total += alloc->banks_16[i].size; in snd_gf1_mem_info_read()
297 for (block = alloc->first, i = 0; block; block = block->next, i++) { in snd_gf1_mem_info_read()
298 used += block->size; in snd_gf1_mem_info_read()
299 …snd_iprintf(buffer, "Block %i onboard 0x%x size %i (0x%x):\n", i, block->ptr, block->size, block-> in snd_gf1_mem_info_read()
300 if (block->share || in snd_gf1_mem_info_read()
301 block->share_id[0] || block->share_id[1] || in snd_gf1_mem_info_read()
302 block->share_id[2] || block->share_id[3]) in snd_gf1_mem_info_read()
304 block->share, in snd_gf1_mem_info_read()
305 block->share_id[0], block->share_id[1], in snd_gf1_mem_info_read()
306 block->share_id[2], block->share_id[3]); in snd_gf1_mem_info_read()
308 block->flags & SNDRV_GF1_MEM_BLOCK_16BIT ? " 16-bit" : ""); in snd_gf1_mem_info_read()
310 switch (block->owner) { in snd_gf1_mem_info_read()
312 snd_iprintf(buffer, "driver - %s\n", block->name); in snd_gf1_mem_info_read()
328 total, used, total - used); in snd_gf1_mem_info_read()
329 mutex_unlock(&alloc->memory_mutex); in snd_gf1_mem_info_read()
331 ultra_iprintf(buffer, " Verify: free = %i, max 8-bit block = %i, max 16-bit block = %i\n", in snd_gf1_mem_info_read()
332 ultra_memory_free_size(card, &card->gf1.mem_alloc), in snd_gf1_mem_info_read()
333 ultra_memory_free_block(card, &card->gf1.mem_alloc, 0), in snd_gf1_mem_info_read()
334 ultra_memory_free_block(card, &card->gf1.mem_alloc, 1)); in snd_gf1_mem_info_read()