xref: /openbmc/linux/drivers/gpu/drm/nouveau/nvkm/subdev/acr/gm20b.c (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
167e7c6cfSBen Skeggs /*
267e7c6cfSBen Skeggs  * Copyright 2019 Red Hat Inc.
367e7c6cfSBen Skeggs  *
467e7c6cfSBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
567e7c6cfSBen Skeggs  * copy of this software and associated documentation files (the "Software"),
667e7c6cfSBen Skeggs  * to deal in the Software without restriction, including without limitation
767e7c6cfSBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
867e7c6cfSBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
967e7c6cfSBen Skeggs  * Software is furnished to do so, subject to the following conditions:
1067e7c6cfSBen Skeggs  *
1167e7c6cfSBen Skeggs  * The above copyright notice and this permission notice shall be included in
1267e7c6cfSBen Skeggs  * all copies or substantial portions of the Software.
1367e7c6cfSBen Skeggs  *
1467e7c6cfSBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1567e7c6cfSBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1667e7c6cfSBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1767e7c6cfSBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1867e7c6cfSBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1967e7c6cfSBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2067e7c6cfSBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
2167e7c6cfSBen Skeggs  */
2267e7c6cfSBen Skeggs #include "priv.h"
2367e7c6cfSBen Skeggs 
2422dcda45SBen Skeggs #include <core/firmware.h>
2522dcda45SBen Skeggs #include <core/memory.h>
2622dcda45SBen Skeggs #include <subdev/mmu.h>
2722dcda45SBen Skeggs #include <subdev/pmu.h>
2822dcda45SBen Skeggs 
2922dcda45SBen Skeggs #include <nvfw/acr.h>
3022dcda45SBen Skeggs #include <nvfw/flcn.h>
3122dcda45SBen Skeggs 
3222dcda45SBen Skeggs int
gm20b_acr_wpr_alloc(struct nvkm_acr * acr,u32 wpr_size)3322dcda45SBen Skeggs gm20b_acr_wpr_alloc(struct nvkm_acr *acr, u32 wpr_size)
3422dcda45SBen Skeggs {
3522dcda45SBen Skeggs 	struct nvkm_subdev *subdev = &acr->subdev;
3622dcda45SBen Skeggs 
3722dcda45SBen Skeggs 	acr->func->wpr_check(acr, &acr->wpr_start, &acr->wpr_end);
3822dcda45SBen Skeggs 
3922dcda45SBen Skeggs 	if ((acr->wpr_end - acr->wpr_start) < wpr_size) {
4022dcda45SBen Skeggs 		nvkm_error(subdev, "WPR image too big for WPR!\n");
4122dcda45SBen Skeggs 		return -ENOSPC;
4222dcda45SBen Skeggs 	}
4322dcda45SBen Skeggs 
4422dcda45SBen Skeggs 	return nvkm_memory_new(subdev->device, NVKM_MEM_TARGET_INST,
4522dcda45SBen Skeggs 			       wpr_size, 0, true, &acr->wpr);
4622dcda45SBen Skeggs }
4722dcda45SBen Skeggs 
48*2541626cSBen Skeggs static int
gm20b_acr_hsfw_load_bld(struct nvkm_falcon_fw * fw)49*2541626cSBen Skeggs gm20b_acr_hsfw_load_bld(struct nvkm_falcon_fw *fw)
5022dcda45SBen Skeggs {
5122dcda45SBen Skeggs 	struct flcn_bl_dmem_desc hsdesc = {
5222dcda45SBen Skeggs 		.ctx_dma = FALCON_DMAIDX_VIRT,
53*2541626cSBen Skeggs 		.code_dma_base = fw->vma->addr >> 8,
54*2541626cSBen Skeggs 		.non_sec_code_off = fw->nmem_base,
55*2541626cSBen Skeggs 		.non_sec_code_size = fw->nmem_size,
56*2541626cSBen Skeggs 		.sec_code_off = fw->imem_base,
57*2541626cSBen Skeggs 		.sec_code_size = fw->imem_size,
5822dcda45SBen Skeggs 		.code_entry_point = 0,
59*2541626cSBen Skeggs 		.data_dma_base = (fw->vma->addr + fw->dmem_base_img) >> 8,
60*2541626cSBen Skeggs 		.data_size = fw->dmem_size,
6122dcda45SBen Skeggs 	};
6222dcda45SBen Skeggs 
63*2541626cSBen Skeggs 	flcn_bl_dmem_desc_dump(fw->falcon->user, &hsdesc);
6422dcda45SBen Skeggs 
65*2541626cSBen Skeggs 	return nvkm_falcon_pio_wr(fw->falcon, (u8 *)&hsdesc, 0, 0, DMEM, 0, sizeof(hsdesc), 0, 0);
6622dcda45SBen Skeggs }
6722dcda45SBen Skeggs 
68*2541626cSBen Skeggs 
6922dcda45SBen Skeggs static int
gm20b_acr_load_setup(struct nvkm_falcon_fw * fw)70*2541626cSBen Skeggs gm20b_acr_load_setup(struct nvkm_falcon_fw *fw)
7122dcda45SBen Skeggs {
72*2541626cSBen Skeggs 	struct flcn_acr_desc *desc = (void *)&fw->fw.img[fw->dmem_base_img];
73*2541626cSBen Skeggs 	struct nvkm_acr *acr = fw->falcon->owner->device->acr;
7422dcda45SBen Skeggs 
7522dcda45SBen Skeggs 	desc->ucode_blob_base = nvkm_memory_addr(acr->wpr);
7622dcda45SBen Skeggs 	desc->ucode_blob_size = nvkm_memory_size(acr->wpr);
7722dcda45SBen Skeggs 	flcn_acr_desc_dump(&acr->subdev, desc);
78*2541626cSBen Skeggs 	return 0;
7922dcda45SBen Skeggs }
8022dcda45SBen Skeggs 
81*2541626cSBen Skeggs const struct nvkm_falcon_fw_func
8222dcda45SBen Skeggs gm20b_acr_load_0 = {
83*2541626cSBen Skeggs 	.signature = gm200_flcn_fw_signature,
84*2541626cSBen Skeggs 	.reset = gm200_flcn_fw_reset,
85*2541626cSBen Skeggs 	.setup = gm20b_acr_load_setup,
86*2541626cSBen Skeggs 	.load = gm200_flcn_fw_load,
87*2541626cSBen Skeggs 	.load_bld = gm20b_acr_hsfw_load_bld,
88*2541626cSBen Skeggs 	.boot = gm200_flcn_fw_boot,
8922dcda45SBen Skeggs };
9022dcda45SBen Skeggs 
9167e7c6cfSBen Skeggs #if IS_ENABLED(CONFIG_ARCH_TEGRA_210_SOC)
9267e7c6cfSBen Skeggs MODULE_FIRMWARE("nvidia/gm20b/acr/bl.bin");
9367e7c6cfSBen Skeggs MODULE_FIRMWARE("nvidia/gm20b/acr/ucode_load.bin");
9467e7c6cfSBen Skeggs #endif
9567e7c6cfSBen Skeggs 
9622dcda45SBen Skeggs static const struct nvkm_acr_hsf_fwif
9722dcda45SBen Skeggs gm20b_acr_load_fwif[] = {
98*2541626cSBen Skeggs 	{ 0, gm200_acr_hsfw_ctor, &gm20b_acr_load_0, NVKM_ACR_HSF_PMU, 0, 0x10 },
9922dcda45SBen Skeggs 	{}
10022dcda45SBen Skeggs };
10122dcda45SBen Skeggs 
10267e7c6cfSBen Skeggs static const struct nvkm_acr_func
10367e7c6cfSBen Skeggs gm20b_acr = {
10422dcda45SBen Skeggs 	.load = gm20b_acr_load_fwif,
10522dcda45SBen Skeggs 	.wpr_parse = gm200_acr_wpr_parse,
10622dcda45SBen Skeggs 	.wpr_layout = gm200_acr_wpr_layout,
10722dcda45SBen Skeggs 	.wpr_alloc = gm20b_acr_wpr_alloc,
10822dcda45SBen Skeggs 	.wpr_build = gm200_acr_wpr_build,
10922dcda45SBen Skeggs 	.wpr_patch = gm200_acr_wpr_patch,
11022dcda45SBen Skeggs 	.wpr_check = gm200_acr_wpr_check,
11122dcda45SBen Skeggs 	.init = gm200_acr_init,
11267e7c6cfSBen Skeggs };
11367e7c6cfSBen Skeggs 
11467e7c6cfSBen Skeggs int
gm20b_acr_load(struct nvkm_acr * acr,int ver,const struct nvkm_acr_fwif * fwif)11567e7c6cfSBen Skeggs gm20b_acr_load(struct nvkm_acr *acr, int ver, const struct nvkm_acr_fwif *fwif)
11667e7c6cfSBen Skeggs {
11722dcda45SBen Skeggs 	struct nvkm_subdev *subdev = &acr->subdev;
11822dcda45SBen Skeggs 	const struct nvkm_acr_hsf_fwif *hsfwif;
11922dcda45SBen Skeggs 
12022dcda45SBen Skeggs 	hsfwif = nvkm_firmware_load(subdev, fwif->func->load, "AcrLoad",
12122dcda45SBen Skeggs 				    acr, "acr/bl", "acr/ucode_load", "load");
12222dcda45SBen Skeggs 	if (IS_ERR(hsfwif))
12322dcda45SBen Skeggs 		return PTR_ERR(hsfwif);
12422dcda45SBen Skeggs 
12567e7c6cfSBen Skeggs 	return 0;
12667e7c6cfSBen Skeggs }
12767e7c6cfSBen Skeggs 
12867e7c6cfSBen Skeggs static const struct nvkm_acr_fwif
12967e7c6cfSBen Skeggs gm20b_acr_fwif[] = {
13067e7c6cfSBen Skeggs 	{  0, gm20b_acr_load, &gm20b_acr },
13190e9cf74SBen Skeggs 	{ -1, gm200_acr_nofw, &gm200_acr },
13267e7c6cfSBen Skeggs 	{}
13367e7c6cfSBen Skeggs };
13467e7c6cfSBen Skeggs 
13567e7c6cfSBen Skeggs int
gm20b_acr_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_acr ** pacr)136c288b4deSBen Skeggs gm20b_acr_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
137c288b4deSBen Skeggs 	      struct nvkm_acr **pacr)
13867e7c6cfSBen Skeggs {
139c288b4deSBen Skeggs 	return nvkm_acr_new_(gm20b_acr_fwif, device, type, inst, pacr);
14067e7c6cfSBen Skeggs }
141