| .. | .. |
|---|
| 1 | | -/* |
|---|
| 2 | | - * Register cache access API - rbtree caching support |
|---|
| 3 | | - * |
|---|
| 4 | | - * Copyright 2011 Wolfson Microelectronics plc |
|---|
| 5 | | - * |
|---|
| 6 | | - * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 9 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 10 | | - * published by the Free Software Foundation. |
|---|
| 11 | | - */ |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | +// |
|---|
| 3 | +// Register cache access API - rbtree caching support |
|---|
| 4 | +// |
|---|
| 5 | +// Copyright 2011 Wolfson Microelectronics plc |
|---|
| 6 | +// |
|---|
| 7 | +// Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> |
|---|
| 12 | 8 | |
|---|
| 13 | 9 | #include <linux/debugfs.h> |
|---|
| 14 | 10 | #include <linux/device.h> |
|---|
| .. | .. |
|---|
| 33 | 29 | unsigned int blklen; |
|---|
| 34 | 30 | /* the actual rbtree node holding this block */ |
|---|
| 35 | 31 | struct rb_node node; |
|---|
| 36 | | -} __attribute__ ((packed)); |
|---|
| 32 | +}; |
|---|
| 37 | 33 | |
|---|
| 38 | 34 | struct regcache_rbtree_ctx { |
|---|
| 39 | 35 | struct rb_root root; |
|---|
| .. | .. |
|---|
| 177 | 173 | return 0; |
|---|
| 178 | 174 | } |
|---|
| 179 | 175 | |
|---|
| 180 | | -static int rbtree_open(struct inode *inode, struct file *file) |
|---|
| 181 | | -{ |
|---|
| 182 | | - return single_open(file, rbtree_show, inode->i_private); |
|---|
| 183 | | -} |
|---|
| 184 | | - |
|---|
| 185 | | -static const struct file_operations rbtree_fops = { |
|---|
| 186 | | - .open = rbtree_open, |
|---|
| 187 | | - .read = seq_read, |
|---|
| 188 | | - .llseek = seq_lseek, |
|---|
| 189 | | - .release = single_release, |
|---|
| 190 | | -}; |
|---|
| 176 | +DEFINE_SHOW_ATTRIBUTE(rbtree); |
|---|
| 191 | 177 | |
|---|
| 192 | 178 | static void rbtree_debugfs_init(struct regmap *map) |
|---|
| 193 | 179 | { |
|---|
| .. | .. |
|---|
| 291 | 277 | |
|---|
| 292 | 278 | blk = krealloc(rbnode->block, |
|---|
| 293 | 279 | blklen * map->cache_word_size, |
|---|
| 294 | | - GFP_KERNEL); |
|---|
| 280 | + map->alloc_flags); |
|---|
| 295 | 281 | if (!blk) |
|---|
| 296 | 282 | return -ENOMEM; |
|---|
| 297 | 283 | |
|---|
| .. | .. |
|---|
| 300 | 286 | if (BITS_TO_LONGS(blklen) > BITS_TO_LONGS(rbnode->blklen)) { |
|---|
| 301 | 287 | present = krealloc(rbnode->cache_present, |
|---|
| 302 | 288 | BITS_TO_LONGS(blklen) * sizeof(*present), |
|---|
| 303 | | - GFP_KERNEL); |
|---|
| 289 | + map->alloc_flags); |
|---|
| 304 | 290 | if (!present) |
|---|
| 305 | 291 | return -ENOMEM; |
|---|
| 306 | 292 | |
|---|
| .. | .. |
|---|
| 334 | 320 | const struct regmap_range *range; |
|---|
| 335 | 321 | int i; |
|---|
| 336 | 322 | |
|---|
| 337 | | - rbnode = kzalloc(sizeof(*rbnode), GFP_KERNEL); |
|---|
| 323 | + rbnode = kzalloc(sizeof(*rbnode), map->alloc_flags); |
|---|
| 338 | 324 | if (!rbnode) |
|---|
| 339 | 325 | return NULL; |
|---|
| 340 | 326 | |
|---|
| .. | .. |
|---|
| 360 | 346 | } |
|---|
| 361 | 347 | |
|---|
| 362 | 348 | rbnode->block = kmalloc_array(rbnode->blklen, map->cache_word_size, |
|---|
| 363 | | - GFP_KERNEL); |
|---|
| 349 | + map->alloc_flags); |
|---|
| 364 | 350 | if (!rbnode->block) |
|---|
| 365 | 351 | goto err_free; |
|---|
| 366 | 352 | |
|---|
| 367 | 353 | rbnode->cache_present = kcalloc(BITS_TO_LONGS(rbnode->blklen), |
|---|
| 368 | 354 | sizeof(*rbnode->cache_present), |
|---|
| 369 | | - GFP_KERNEL); |
|---|
| 355 | + map->alloc_flags); |
|---|
| 370 | 356 | if (!rbnode->cache_present) |
|---|
| 371 | 357 | goto err_free_block; |
|---|
| 372 | 358 | |
|---|
| .. | .. |
|---|
| 467 | 453 | if (!rbnode) |
|---|
| 468 | 454 | return -ENOMEM; |
|---|
| 469 | 455 | regcache_rbtree_set_register(map, rbnode, |
|---|
| 470 | | - reg - rbnode->base_reg, value); |
|---|
| 456 | + (reg - rbnode->base_reg) / map->reg_stride, |
|---|
| 457 | + value); |
|---|
| 471 | 458 | regcache_rbtree_insert(map, &rbtree_ctx->root, rbnode); |
|---|
| 472 | 459 | rbtree_ctx->cached_rbnode = rbnode; |
|---|
| 473 | 460 | } |
|---|