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

memnv04.c (2233B)


      1/*
      2 * Copyright 2017 Red Hat Inc.
      3 *
      4 * Permission is hereby granted, free of charge, to any person obtaining a
      5 * copy of this software and associated documentation files (the "Software"),
      6 * to deal in the Software without restriction, including without limitation
      7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8 * and/or sell copies of the Software, and to permit persons to whom the
      9 * Software is furnished to do so, subject to the following conditions:
     10 *
     11 * The above copyright notice and this permission notice shall be included in
     12 * all copies or substantial portions of the Software.
     13 *
     14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     20 * OTHER DEALINGS IN THE SOFTWARE.
     21 */
     22#include "mem.h"
     23
     24#include <core/memory.h>
     25#include <subdev/fb.h>
     26
     27#include <nvif/if000b.h>
     28#include <nvif/unpack.h>
     29
     30int
     31nv04_mem_map(struct nvkm_mmu *mmu, struct nvkm_memory *memory, void *argv,
     32	     u32 argc, u64 *paddr, u64 *psize, struct nvkm_vma **pvma)
     33{
     34	union {
     35		struct nv04_mem_map_vn vn;
     36	} *args = argv;
     37	struct nvkm_device *device = mmu->subdev.device;
     38	const u64 addr = nvkm_memory_addr(memory);
     39	int ret = -ENOSYS;
     40
     41	if ((ret = nvif_unvers(ret, &argv, &argc, args->vn)))
     42		return ret;
     43
     44	*paddr = device->func->resource_addr(device, 1) + addr;
     45	*psize = nvkm_memory_size(memory);
     46	*pvma = ERR_PTR(-ENODEV);
     47	return 0;
     48}
     49
     50int
     51nv04_mem_new(struct nvkm_mmu *mmu, int type, u8 page, u64 size,
     52	     void *argv, u32 argc, struct nvkm_memory **pmemory)
     53{
     54	union {
     55		struct nv04_mem_vn vn;
     56	} *args = argv;
     57	int ret = -ENOSYS;
     58
     59	if ((ret = nvif_unvers(ret, &argv, &argc, args->vn)))
     60		return ret;
     61
     62	if (mmu->type[type].type & NVKM_MEM_MAPPABLE)
     63		type = NVKM_RAM_MM_NORMAL;
     64	else
     65		type = NVKM_RAM_MM_NOMAP;
     66
     67	return nvkm_ram_get(mmu->subdev.device, type, 0x01, page,
     68			    size, true, false, pmemory);
     69}