at master 1.9 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * Cache coherency maintenance operation device drivers 4 * 5 * Copyright Huawei 2025 6 */ 7#ifndef _LINUX_CACHE_COHERENCY_H_ 8#define _LINUX_CACHE_COHERENCY_H_ 9 10#include <linux/list.h> 11#include <linux/kref.h> 12#include <linux/types.h> 13 14struct cc_inval_params { 15 phys_addr_t addr; 16 size_t size; 17}; 18 19struct cache_coherency_ops_inst; 20 21struct cache_coherency_ops { 22 int (*wbinv)(struct cache_coherency_ops_inst *cci, 23 struct cc_inval_params *invp); 24 int (*done)(struct cache_coherency_ops_inst *cci); 25}; 26 27struct cache_coherency_ops_inst { 28 struct kref kref; 29 struct list_head node; 30 const struct cache_coherency_ops *ops; 31}; 32 33int cache_coherency_ops_instance_register(struct cache_coherency_ops_inst *cci); 34void cache_coherency_ops_instance_unregister(struct cache_coherency_ops_inst *cci); 35 36struct cache_coherency_ops_inst * 37_cache_coherency_ops_instance_alloc(const struct cache_coherency_ops *ops, 38 size_t size); 39/** 40 * cache_coherency_ops_instance_alloc - Allocate cache coherency ops instance 41 * @ops: Cache maintenance operations 42 * @drv_struct: structure that contains the struct cache_coherency_ops_inst 43 * @member: Name of the struct cache_coherency_ops_inst member in @drv_struct. 44 * 45 * This allocates a driver specific structure and initializes the 46 * cache_coherency_ops_inst embedded in the drv_struct. Upon success the 47 * pointer must be freed via cache_coherency_ops_instance_put(). 48 * 49 * Returns a &drv_struct * on success, %NULL on error. 50 */ 51#define cache_coherency_ops_instance_alloc(ops, drv_struct, member) \ 52 ({ \ 53 static_assert(__same_type(struct cache_coherency_ops_inst, \ 54 ((drv_struct *)NULL)->member)); \ 55 static_assert(offsetof(drv_struct, member) == 0); \ 56 (drv_struct *)_cache_coherency_ops_instance_alloc(ops, \ 57 sizeof(drv_struct)); \ 58 }) 59void cache_coherency_ops_instance_put(struct cache_coherency_ops_inst *cci); 60 61#endif