1 #ifndef __NVKM_PWR_MEMX_H__
2 #define __NVKM_PWR_MEMX_H__
4 #include <subdev/pwr.h>
5 #include <subdev/pwr/fuc/os.h>
8 struct nouveau_pwr *ppwr;
19 memx_out(struct nouveau_memx *memx)
21 struct nouveau_pwr *ppwr = memx->ppwr;
25 nv_wr32(ppwr, 0x10a1c4, (memx->c.size << 16) | memx->c.mthd);
26 for (i = 0; i < memx->c.size; i++)
27 nv_wr32(ppwr, 0x10a1c4, memx->c.data[i]);
33 memx_cmd(struct nouveau_memx *memx, u32 mthd, u32 size, u32 data[])
35 if ((memx->c.size + size >= ARRAY_SIZE(memx->c.data)) ||
36 (memx->c.size && memx->c.mthd != mthd))
38 memcpy(&memx->c.data[memx->c.size], data, size * sizeof(data[0]));
44 nouveau_memx_init(struct nouveau_pwr *ppwr, struct nouveau_memx **pmemx)
46 struct nouveau_memx *memx;
50 ret = ppwr->message(ppwr, reply, PROC_MEMX, MEMX_MSG_INFO, 0, 0);
54 memx = *pmemx = kzalloc(sizeof(*memx), GFP_KERNEL);
58 memx->base = reply[0];
59 memx->size = reply[1];
61 /* acquire data segment access */
63 nv_wr32(ppwr, 0x10a580, 0x00000003);
64 } while (nv_rd32(ppwr, 0x10a580) != 0x00000003);
65 nv_wr32(ppwr, 0x10a1c0, 0x01000000 | memx->base);
66 nv_wr32(ppwr, 0x10a1c4, 0x00010000 | MEMX_ENTER);
67 nv_wr32(ppwr, 0x10a1c4, 0x00000000);
72 nouveau_memx_fini(struct nouveau_memx **pmemx, bool exec)
74 struct nouveau_memx *memx = *pmemx;
75 struct nouveau_pwr *ppwr = memx->ppwr;
78 /* flush the cache... */
81 /* release data segment access */
82 nv_wr32(ppwr, 0x10a1c4, 0x00000000 | MEMX_LEAVE);
83 finish = nv_rd32(ppwr, 0x10a1c0) & 0x00ffffff;
84 nv_wr32(ppwr, 0x10a580, 0x00000000);
86 /* call MEMX process to execute the script, and wait for reply */
88 ppwr->message(ppwr, reply, PROC_MEMX, MEMX_MSG_EXEC,
97 nouveau_memx_wr32(struct nouveau_memx *memx, u32 addr, u32 data)
99 nv_debug(memx->ppwr, "R[%06x] = 0x%08x\n", addr, data);
100 memx_cmd(memx, MEMX_WR32, 2, (u32[]){ addr, data });
104 nouveau_memx_wait(struct nouveau_memx *memx,
105 u32 addr, u32 mask, u32 data, u32 nsec)
107 nv_debug(memx->ppwr, "R[%06x] & 0x%08x == 0x%08x, %d us\n",
108 addr, mask, data, nsec);
109 memx_cmd(memx, MEMX_WAIT, 4, (u32[]){ addr, ~mask, data, nsec });
110 memx_out(memx); /* fuc can't handle multiple */
114 nouveau_memx_nsec(struct nouveau_memx *memx, u32 nsec)
116 nv_debug(memx->ppwr, " DELAY = %d ns\n", nsec);
117 memx_cmd(memx, MEMX_DELAY, 1, (u32[]){ nsec });
118 memx_out(memx); /* fuc can't handle multiple */