cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

mm.h (1641B)


      1/* SPDX-License-Identifier: MIT */
      2#ifndef __NVKM_MM_H__
      3#define __NVKM_MM_H__
      4#include <core/os.h>
      5
      6struct nvkm_mm_node {
      7	struct list_head nl_entry;
      8	struct list_head fl_entry;
      9	struct nvkm_mm_node *next;
     10
     11#define NVKM_MM_HEAP_ANY 0x00
     12	u8  heap;
     13#define NVKM_MM_TYPE_NONE 0x00
     14#define NVKM_MM_TYPE_HOLE 0xff
     15	u8  type;
     16	u32 offset;
     17	u32 length;
     18};
     19
     20struct nvkm_mm {
     21	struct list_head nodes;
     22	struct list_head free;
     23
     24	u32 block_size;
     25	int heap_nodes;
     26};
     27
     28static inline bool
     29nvkm_mm_initialised(struct nvkm_mm *mm)
     30{
     31	return mm->heap_nodes;
     32}
     33
     34int  nvkm_mm_init(struct nvkm_mm *, u8 heap, u32 offset, u32 length, u32 block);
     35int  nvkm_mm_fini(struct nvkm_mm *);
     36int  nvkm_mm_head(struct nvkm_mm *, u8 heap, u8 type, u32 size_max,
     37		  u32 size_min, u32 align, struct nvkm_mm_node **);
     38int  nvkm_mm_tail(struct nvkm_mm *, u8 heap, u8 type, u32 size_max,
     39		  u32 size_min, u32 align, struct nvkm_mm_node **);
     40void nvkm_mm_free(struct nvkm_mm *, struct nvkm_mm_node **);
     41void nvkm_mm_dump(struct nvkm_mm *, const char *);
     42
     43static inline u32
     44nvkm_mm_heap_size(struct nvkm_mm *mm, u8 heap)
     45{
     46	struct nvkm_mm_node *node;
     47	u32 size = 0;
     48	list_for_each_entry(node, &mm->nodes, nl_entry) {
     49		if (node->heap == heap)
     50			size += node->length;
     51	}
     52	return size;
     53}
     54
     55static inline bool
     56nvkm_mm_contiguous(struct nvkm_mm_node *node)
     57{
     58	return !node->next;
     59}
     60
     61static inline u32
     62nvkm_mm_addr(struct nvkm_mm_node *node)
     63{
     64	if (WARN_ON(!nvkm_mm_contiguous(node)))
     65		return 0;
     66	return node->offset;
     67}
     68
     69static inline u32
     70nvkm_mm_size(struct nvkm_mm_node *node)
     71{
     72	u32 size = 0;
     73	do {
     74		size += node->length;
     75	} while ((node = node->next));
     76	return size;
     77}
     78#endif