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

fb.h (6223B)


      1/* SPDX-License-Identifier: MIT */
      2#ifndef __NVKM_FB_H__
      3#define __NVKM_FB_H__
      4#include <core/subdev.h>
      5#include <core/mm.h>
      6
      7/* memory type/access flags, do not match hardware values */
      8#define NV_MEM_ACCESS_RO  1
      9#define NV_MEM_ACCESS_WO  2
     10#define NV_MEM_ACCESS_RW (NV_MEM_ACCESS_RO | NV_MEM_ACCESS_WO)
     11#define NV_MEM_ACCESS_SYS 4
     12#define NV_MEM_ACCESS_VM  8
     13#define NV_MEM_ACCESS_NOSNOOP 16
     14
     15#define NV_MEM_TARGET_VRAM        0
     16#define NV_MEM_TARGET_PCI         1
     17#define NV_MEM_TARGET_PCI_NOSNOOP 2
     18#define NV_MEM_TARGET_VM          3
     19#define NV_MEM_TARGET_GART        4
     20
     21#define NVKM_RAM_TYPE_VM 0x7f
     22#define NV_MEM_COMP_VM 0x03
     23
     24struct nvkm_fb_tile {
     25	struct nvkm_mm_node *tag;
     26	u32 addr;
     27	u32 limit;
     28	u32 pitch;
     29	u32 zcomp;
     30};
     31
     32struct nvkm_fb {
     33	const struct nvkm_fb_func *func;
     34	struct nvkm_subdev subdev;
     35
     36	struct nvkm_blob vpr_scrubber;
     37
     38	struct nvkm_ram *ram;
     39
     40	struct {
     41		struct mutex mutex; /* protects mm and nvkm_memory::tags */
     42		struct nvkm_mm mm;
     43	} tags;
     44
     45	struct {
     46		struct nvkm_fb_tile region[16];
     47		int regions;
     48	} tile;
     49
     50	u8 page;
     51
     52	struct nvkm_memory *mmu_rd;
     53	struct nvkm_memory *mmu_wr;
     54};
     55
     56void nvkm_fb_tile_init(struct nvkm_fb *, int region, u32 addr, u32 size,
     57		       u32 pitch, u32 flags, struct nvkm_fb_tile *);
     58void nvkm_fb_tile_fini(struct nvkm_fb *, int region, struct nvkm_fb_tile *);
     59void nvkm_fb_tile_prog(struct nvkm_fb *, int region, struct nvkm_fb_tile *);
     60
     61int nv04_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     62int nv10_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     63int nv1a_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     64int nv20_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     65int nv25_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     66int nv30_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     67int nv35_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     68int nv36_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     69int nv40_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     70int nv41_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     71int nv44_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     72int nv46_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     73int nv47_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     74int nv49_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     75int nv4e_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     76int nv50_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     77int g84_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     78int gt215_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     79int mcp77_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     80int mcp89_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     81int gf100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     82int gf108_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     83int gk104_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     84int gk110_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     85int gk20a_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     86int gm107_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     87int gm200_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     88int gm20b_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     89int gp100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     90int gp102_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     91int gp10b_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     92int gv100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     93int ga100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     94int ga102_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
     95
     96#include <subdev/bios.h>
     97#include <subdev/bios/ramcfg.h>
     98
     99struct nvkm_ram_data {
    100	struct list_head head;
    101	struct nvbios_ramcfg bios;
    102	u32 freq;
    103};
    104
    105enum nvkm_ram_type {
    106	NVKM_RAM_TYPE_UNKNOWN = 0,
    107	NVKM_RAM_TYPE_STOLEN,
    108	NVKM_RAM_TYPE_SGRAM,
    109	NVKM_RAM_TYPE_SDRAM,
    110	NVKM_RAM_TYPE_DDR1,
    111	NVKM_RAM_TYPE_DDR2,
    112	NVKM_RAM_TYPE_DDR3,
    113	NVKM_RAM_TYPE_GDDR2,
    114	NVKM_RAM_TYPE_GDDR3,
    115	NVKM_RAM_TYPE_GDDR4,
    116	NVKM_RAM_TYPE_GDDR5,
    117	NVKM_RAM_TYPE_GDDR5X,
    118	NVKM_RAM_TYPE_GDDR6,
    119	NVKM_RAM_TYPE_HBM2,
    120};
    121
    122struct nvkm_ram {
    123	const struct nvkm_ram_func *func;
    124	struct nvkm_fb *fb;
    125	enum nvkm_ram_type type;
    126	u64 size;
    127
    128#define NVKM_RAM_MM_SHIFT 12
    129#define NVKM_RAM_MM_ANY    (NVKM_MM_HEAP_ANY + 0)
    130#define NVKM_RAM_MM_NORMAL (NVKM_MM_HEAP_ANY + 1)
    131#define NVKM_RAM_MM_NOMAP  (NVKM_MM_HEAP_ANY + 2)
    132#define NVKM_RAM_MM_MIXED  (NVKM_MM_HEAP_ANY + 3)
    133	struct nvkm_mm vram;
    134	u64 stolen;
    135	struct mutex mutex;
    136
    137	int ranks;
    138	int parts;
    139	int part_mask;
    140
    141	u32 freq;
    142	u32 mr[16];
    143	u32 mr1_nuts;
    144
    145	struct nvkm_ram_data *next;
    146	struct nvkm_ram_data former;
    147	struct nvkm_ram_data xition;
    148	struct nvkm_ram_data target;
    149};
    150
    151int
    152nvkm_ram_get(struct nvkm_device *, u8 heap, u8 type, u8 page, u64 size,
    153	     bool contig, bool back, struct nvkm_memory **);
    154
    155struct nvkm_ram_func {
    156	u64 upper;
    157	u32 (*probe_fbp)(const struct nvkm_ram_func *, struct nvkm_device *,
    158			 int fbp, int *pltcs);
    159	u32 (*probe_fbp_amount)(const struct nvkm_ram_func *, u32 fbpao,
    160				struct nvkm_device *, int fbp, int *pltcs);
    161	u32 (*probe_fbpa_amount)(struct nvkm_device *, int fbpa);
    162	void *(*dtor)(struct nvkm_ram *);
    163	int (*init)(struct nvkm_ram *);
    164
    165	int (*calc)(struct nvkm_ram *, u32 freq);
    166	int (*prog)(struct nvkm_ram *);
    167	void (*tidy)(struct nvkm_ram *);
    168};
    169#endif