1f15cde64SBen Skeggs /*
2f15cde64SBen Skeggs * Copyright 2022 Red Hat Inc.
3f15cde64SBen Skeggs *
4f15cde64SBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5f15cde64SBen Skeggs * copy of this software and associated documentation files (the "Software"),
6f15cde64SBen Skeggs * to deal in the Software without restriction, including without limitation
7f15cde64SBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8f15cde64SBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9f15cde64SBen Skeggs * Software is furnished to do so, subject to the following conditions:
10f15cde64SBen Skeggs *
11f15cde64SBen Skeggs * The above copyright notice and this permission notice shall be included in
12f15cde64SBen Skeggs * all copies or substantial portions of the Software.
13f15cde64SBen Skeggs *
14f15cde64SBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15f15cde64SBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16f15cde64SBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17f15cde64SBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18f15cde64SBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19f15cde64SBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20f15cde64SBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21f15cde64SBen Skeggs */
22f15cde64SBen Skeggs #include "priv.h"
23f15cde64SBen Skeggs
242541626cSBen Skeggs static void
gp102_flcn_pio_emem_rd(struct nvkm_falcon * falcon,u8 port,const u8 * img,int len)252541626cSBen Skeggs gp102_flcn_pio_emem_rd(struct nvkm_falcon *falcon, u8 port, const u8 *img, int len)
262541626cSBen Skeggs {
272541626cSBen Skeggs while (len >= 4) {
282541626cSBen Skeggs *(u32 *)img = nvkm_falcon_rd32(falcon, 0xac4 + (port * 8));
292541626cSBen Skeggs img += 4;
302541626cSBen Skeggs len -= 4;
312541626cSBen Skeggs }
322541626cSBen Skeggs }
332541626cSBen Skeggs
342541626cSBen Skeggs static void
gp102_flcn_pio_emem_rd_init(struct nvkm_falcon * falcon,u8 port,u32 dmem_base)352541626cSBen Skeggs gp102_flcn_pio_emem_rd_init(struct nvkm_falcon *falcon, u8 port, u32 dmem_base)
362541626cSBen Skeggs {
372541626cSBen Skeggs nvkm_falcon_wr32(falcon, 0xac0 + (port * 8), BIT(25) | dmem_base);
382541626cSBen Skeggs }
392541626cSBen Skeggs
402541626cSBen Skeggs static void
gp102_flcn_pio_emem_wr(struct nvkm_falcon * falcon,u8 port,const u8 * img,int len,u16 tag)412541626cSBen Skeggs gp102_flcn_pio_emem_wr(struct nvkm_falcon *falcon, u8 port, const u8 *img, int len, u16 tag)
422541626cSBen Skeggs {
432541626cSBen Skeggs while (len >= 4) {
442541626cSBen Skeggs nvkm_falcon_wr32(falcon, 0xac4 + (port * 8), *(u32 *)img);
452541626cSBen Skeggs img += 4;
462541626cSBen Skeggs len -= 4;
472541626cSBen Skeggs }
482541626cSBen Skeggs }
492541626cSBen Skeggs
502541626cSBen Skeggs static void
gp102_flcn_pio_emem_wr_init(struct nvkm_falcon * falcon,u8 port,bool sec,u32 emem_base)512541626cSBen Skeggs gp102_flcn_pio_emem_wr_init(struct nvkm_falcon *falcon, u8 port, bool sec, u32 emem_base)
522541626cSBen Skeggs {
532541626cSBen Skeggs nvkm_falcon_wr32(falcon, 0xac0 + (port * 8), BIT(24) | emem_base);
542541626cSBen Skeggs }
552541626cSBen Skeggs
562541626cSBen Skeggs const struct nvkm_falcon_func_pio
572541626cSBen Skeggs gp102_flcn_emem_pio = {
582541626cSBen Skeggs .min = 4,
592541626cSBen Skeggs .max = 0x100,
602541626cSBen Skeggs .wr_init = gp102_flcn_pio_emem_wr_init,
612541626cSBen Skeggs .wr = gp102_flcn_pio_emem_wr,
622541626cSBen Skeggs .rd_init = gp102_flcn_pio_emem_rd_init,
632541626cSBen Skeggs .rd = gp102_flcn_pio_emem_rd,
642541626cSBen Skeggs };
652541626cSBen Skeggs
66f15cde64SBen Skeggs int
gp102_flcn_reset_eng(struct nvkm_falcon * falcon)67f15cde64SBen Skeggs gp102_flcn_reset_eng(struct nvkm_falcon *falcon)
68f15cde64SBen Skeggs {
69*a51c69eeSBen Skeggs int ret;
70*a51c69eeSBen Skeggs
71*a51c69eeSBen Skeggs if (falcon->func->reset_prep) {
72*a51c69eeSBen Skeggs ret = falcon->func->reset_prep(falcon);
73*a51c69eeSBen Skeggs if (ret)
74*a51c69eeSBen Skeggs return ret;
75*a51c69eeSBen Skeggs }
76*a51c69eeSBen Skeggs
77f15cde64SBen Skeggs nvkm_falcon_mask(falcon, 0x3c0, 0x00000001, 0x00000001);
78f15cde64SBen Skeggs udelay(10);
79f15cde64SBen Skeggs nvkm_falcon_mask(falcon, 0x3c0, 0x00000001, 0x00000000);
80f15cde64SBen Skeggs
81f15cde64SBen Skeggs return falcon->func->reset_wait_mem_scrubbing(falcon);
82f15cde64SBen Skeggs }
83