base.c (2541626cfb794e57ba0575a6920826f591f7ced0) | base.c (a51c69ee74d195e6d84fe9d48ca55f51d39e1b5b) |
---|---|
1/* 2 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 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 --- 11 unchanged lines hidden (view full) --- 20 * DEALINGS IN THE SOFTWARE. 21 */ 22#include "priv.h" 23 24#include <subdev/mc.h> 25#include <subdev/timer.h> 26#include <subdev/top.h> 27 | 1/* 2 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 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 --- 11 unchanged lines hidden (view full) --- 20 * DEALINGS IN THE SOFTWARE. 21 */ 22#include "priv.h" 23 24#include <subdev/mc.h> 25#include <subdev/timer.h> 26#include <subdev/top.h> 27 |
28static const struct nvkm_falcon_func_dma * 29nvkm_falcon_dma(struct nvkm_falcon *falcon, enum nvkm_falcon_mem *mem_type, u32 *mem_base) 30{ 31 switch (*mem_type) { 32 case IMEM: return falcon->func->imem_dma; 33 case DMEM: return falcon->func->dmem_dma; 34 default: 35 return NULL; 36 } 37} 38 39int 40nvkm_falcon_dma_wr(struct nvkm_falcon *falcon, const u8 *img, u64 dma_addr, u32 dma_base, 41 enum nvkm_falcon_mem mem_type, u32 mem_base, int len, bool sec) 42{ 43 const struct nvkm_falcon_func_dma *dma = nvkm_falcon_dma(falcon, &mem_type, &mem_base); 44 const char *type = nvkm_falcon_mem(mem_type); 45 const int dmalen = 256; 46 u32 dma_start = 0; 47 u32 dst, src, cmd; 48 int ret, i; 49 50 if (WARN_ON(!dma->xfer)) 51 return -EINVAL; 52 53 if (mem_type == DMEM) { 54 dma_start = dma_base; 55 dma_addr += dma_base; 56 } 57 58 FLCN_DBG(falcon, "%s %08x <- %08x bytes at %08x (%010llx %08x)", 59 type, mem_base, len, dma_base, dma_addr - dma_base, dma_start); 60 if (WARN_ON(!len || (len & (dmalen - 1)))) 61 return -EINVAL; 62 63 ret = dma->init(falcon, dma_addr, dmalen, mem_type, sec, &cmd); 64 if (ret) 65 return ret; 66 67 dst = mem_base; 68 src = dma_base; 69 if (len) { 70 while (len >= dmalen) { 71 dma->xfer(falcon, dst, src - dma_start, cmd); 72 73 if (img && nvkm_printk_ok(falcon->owner, falcon->user, NV_DBG_TRACE)) { 74 for (i = 0; i < dmalen; i += 4, mem_base += 4) { 75 const int w = 8, x = (i / 4) % w; 76 77 if (x == 0) 78 printk(KERN_INFO "%s %08x <-", type, mem_base); 79 printk(KERN_CONT " %08x", *(u32 *)(img + src + i)); 80 if (x == (w - 1) || ((i + 4) == dmalen)) 81 printk(KERN_CONT " <- %08x+%08x", dma_base, 82 src + i - dma_base - (x * 4)); 83 if (i == (7 * 4)) 84 printk(KERN_CONT " *"); 85 } 86 } 87 88 if (nvkm_msec(falcon->owner->device, 2000, 89 if (dma->done(falcon)) 90 break; 91 ) < 0) 92 return -ETIMEDOUT; 93 94 src += dmalen; 95 dst += dmalen; 96 len -= dmalen; 97 } 98 WARN_ON(len); 99 } 100 101 return 0; 102} 103 |
|
28static const struct nvkm_falcon_func_pio * 29nvkm_falcon_pio(struct nvkm_falcon *falcon, enum nvkm_falcon_mem *mem_type, u32 *mem_base) 30{ 31 switch (*mem_type) { 32 case IMEM: 33 return falcon->func->imem_pio; 34 case DMEM: 35 if (!falcon->func->emem_addr || *mem_base < falcon->func->emem_addr) --- 198 unchanged lines hidden (view full) --- 234nvkm_falcon_ctor(const struct nvkm_falcon_func *func, 235 struct nvkm_subdev *subdev, const char *name, u32 addr, 236 struct nvkm_falcon *falcon) 237{ 238 falcon->func = func; 239 falcon->owner = subdev; 240 falcon->name = name; 241 falcon->addr = addr; | 104static const struct nvkm_falcon_func_pio * 105nvkm_falcon_pio(struct nvkm_falcon *falcon, enum nvkm_falcon_mem *mem_type, u32 *mem_base) 106{ 107 switch (*mem_type) { 108 case IMEM: 109 return falcon->func->imem_pio; 110 case DMEM: 111 if (!falcon->func->emem_addr || *mem_base < falcon->func->emem_addr) --- 198 unchanged lines hidden (view full) --- 310nvkm_falcon_ctor(const struct nvkm_falcon_func *func, 311 struct nvkm_subdev *subdev, const char *name, u32 addr, 312 struct nvkm_falcon *falcon) 313{ 314 falcon->func = func; 315 falcon->owner = subdev; 316 falcon->name = name; 317 falcon->addr = addr; |
318 falcon->addr2 = func->addr2; |
|
242 mutex_init(&falcon->mutex); 243 mutex_init(&falcon->dmem_mutex); 244 return 0; 245} | 319 mutex_init(&falcon->mutex); 320 mutex_init(&falcon->dmem_mutex); 321 return 0; 322} |