base.c (0e44c21708761977dcbea9b846b51a6fb684907a) base.c (2541626cfb794e57ba0575a6920826f591f7ced0)
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

--- 8 unchanged lines hidden (view full) ---

17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22#include "priv.h"
23
24#include <subdev/mc.h>
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

--- 8 unchanged lines hidden (view full) ---

17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22#include "priv.h"
23
24#include <subdev/mc.h>
25#include <subdev/timer.h>
25#include <subdev/top.h>
26
27static const struct nvkm_falcon_func_pio *
28nvkm_falcon_pio(struct nvkm_falcon *falcon, enum nvkm_falcon_mem *mem_type, u32 *mem_base)
29{
30 switch (*mem_type) {
31 case IMEM:
32 return falcon->func->imem_pio;
33 case DMEM:
34 if (!falcon->func->emem_addr || *mem_base < falcon->func->emem_addr)
35 return falcon->func->dmem_pio;
36
37 *mem_base -= falcon->func->emem_addr;
38 fallthrough;
26#include <subdev/top.h>
27
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)
36 return falcon->func->dmem_pio;
37
38 *mem_base -= falcon->func->emem_addr;
39 fallthrough;
40 case EMEM:
41 return falcon->func->emem_pio;
39 default:
40 return NULL;
41 }
42}
43
44int
42 default:
43 return NULL;
44 }
45}
46
47int
48nvkm_falcon_pio_rd(struct nvkm_falcon *falcon, u8 port, enum nvkm_falcon_mem mem_type, u32 mem_base,
49 const u8 *img, u32 img_base, int len)
50{
51 const struct nvkm_falcon_func_pio *pio = nvkm_falcon_pio(falcon, &mem_type, &mem_base);
52 const char *type = nvkm_falcon_mem(mem_type);
53 int xfer_len;
54
55 if (WARN_ON(!pio || !pio->rd))
56 return -EINVAL;
57
58 FLCN_DBG(falcon, "%s %08x -> %08x bytes at %08x", type, mem_base, len, img_base);
59 if (WARN_ON(!len || (len & (pio->min - 1))))
60 return -EINVAL;
61
62 pio->rd_init(falcon, port, mem_base);
63 do {
64 xfer_len = min(len, pio->max);
65 pio->rd(falcon, port, img, xfer_len);
66
67 if (nvkm_printk_ok(falcon->owner, falcon->user, NV_DBG_TRACE)) {
68 for (img_base = 0; img_base < xfer_len; img_base += 4, mem_base += 4) {
69 if (((img_base / 4) % 8) == 0)
70 printk(KERN_INFO "%s %08x ->", type, mem_base);
71 printk(KERN_CONT " %08x", *(u32 *)(img + img_base));
72 }
73 }
74
75 img += xfer_len;
76 len -= xfer_len;
77 } while (len);
78
79 return 0;
80}
81
82int
45nvkm_falcon_pio_wr(struct nvkm_falcon *falcon, const u8 *img, u32 img_base, u8 port,
46 enum nvkm_falcon_mem mem_type, u32 mem_base, int len, u16 tag, bool sec)
47{
48 const struct nvkm_falcon_func_pio *pio = nvkm_falcon_pio(falcon, &mem_type, &mem_base);
49 const char *type = nvkm_falcon_mem(mem_type);
50 int xfer_len;
51
52 if (WARN_ON(!pio || !pio->wr))

--- 46 unchanged lines hidden (view full) ---

99 mutex_lock(&falcon->dmem_mutex);
100
101 falcon->func->load_dmem(falcon, data, start, size, port);
102
103 mutex_unlock(&falcon->dmem_mutex);
104}
105
106void
83nvkm_falcon_pio_wr(struct nvkm_falcon *falcon, const u8 *img, u32 img_base, u8 port,
84 enum nvkm_falcon_mem mem_type, u32 mem_base, int len, u16 tag, bool sec)
85{
86 const struct nvkm_falcon_func_pio *pio = nvkm_falcon_pio(falcon, &mem_type, &mem_base);
87 const char *type = nvkm_falcon_mem(mem_type);
88 int xfer_len;
89
90 if (WARN_ON(!pio || !pio->wr))

--- 46 unchanged lines hidden (view full) ---

137 mutex_lock(&falcon->dmem_mutex);
138
139 falcon->func->load_dmem(falcon, data, start, size, port);
140
141 mutex_unlock(&falcon->dmem_mutex);
142}
143
144void
107nvkm_falcon_read_dmem(struct nvkm_falcon *falcon, u32 start, u32 size, u8 port,
108 void *data)
109{
110 mutex_lock(&falcon->dmem_mutex);
111
112 falcon->func->read_dmem(falcon, start, size, port, data);
113
114 mutex_unlock(&falcon->dmem_mutex);
115}
116
117void
118nvkm_falcon_bind_context(struct nvkm_falcon *falcon, struct nvkm_memory *inst)
119{
120 if (!falcon->func->bind_context) {
121 nvkm_error(falcon->user,
122 "Context binding not supported on this falcon!\n");
123 return;
124 }
125
126 falcon->func->bind_context(falcon, inst);
127}
128
129void
130nvkm_falcon_set_start_addr(struct nvkm_falcon *falcon, u32 start_addr)
131{
132 falcon->func->set_start_addr(falcon, start_addr);
133}
134
135void
136nvkm_falcon_start(struct nvkm_falcon *falcon)
137{
138 falcon->func->start(falcon);
139}
140
141int
142nvkm_falcon_reset(struct nvkm_falcon *falcon)
143{
144 int ret;
145
146 ret = falcon->func->disable(falcon);
147 if (WARN_ON(ret))
148 return ret;
149
150 return nvkm_falcon_enable(falcon);
151}
152
145nvkm_falcon_start(struct nvkm_falcon *falcon)
146{
147 falcon->func->start(falcon);
148}
149
150int
151nvkm_falcon_reset(struct nvkm_falcon *falcon)
152{
153 int ret;
154
155 ret = falcon->func->disable(falcon);
156 if (WARN_ON(ret))
157 return ret;
158
159 return nvkm_falcon_enable(falcon);
160}
161
153int
154nvkm_falcon_wait_for_halt(struct nvkm_falcon *falcon, u32 ms)
155{
156 return falcon->func->wait_for_halt(falcon, ms);
157}
158
159int
160nvkm_falcon_clear_interrupt(struct nvkm_falcon *falcon, u32 mask)
161{
162 return falcon->func->clear_interrupt(falcon, mask);
163}
164
165static int
166nvkm_falcon_oneinit(struct nvkm_falcon *falcon)
167{
168 const struct nvkm_falcon_func *func = falcon->func;
169 const struct nvkm_subdev *subdev = falcon->owner;
170 u32 reg;
171
172 if (!falcon->addr) {

--- 76 unchanged lines hidden ---
162static int
163nvkm_falcon_oneinit(struct nvkm_falcon *falcon)
164{
165 const struct nvkm_falcon_func *func = falcon->func;
166 const struct nvkm_subdev *subdev = falcon->owner;
167 u32 reg;
168
169 if (!falcon->addr) {

--- 76 unchanged lines hidden ---