File Index
Files and directories
Sign in
FILE

base.c

File preview with syntax highlighting.

linux-6.19.14/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/base.c C
  1/*
  2 * Copyright 2019 Red Hat Inc.
  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
  9 * Software is furnished to do so, subject to the following conditions:
 10 *
 11 * The above copyright notice and this permission notice shall be included in
 12 * all copies or substantial portions of the Software.
 13 *
 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 20 * OTHER DEALINGS IN THE SOFTWARE.
 21 */
 22#include "priv.h"
 23
 24int
 25nvkm_gsp_intr_nonstall(struct nvkm_gsp *gsp, enum nvkm_subdev_type type, int inst)
 26{
 27	for (int i = 0; i < gsp->intr_nr; i++) {
 28		if (gsp->intr[i].type == type && gsp->intr[i].inst == inst)
 29			return gsp->intr[i].nonstall;
 30	}
 31
 32	return -ENOENT;
 33}
 34
 35int
 36nvkm_gsp_intr_stall(struct nvkm_gsp *gsp, enum nvkm_subdev_type type, int inst)
 37{
 38	for (int i = 0; i < gsp->intr_nr; i++) {
 39		if (gsp->intr[i].type == type && gsp->intr[i].inst == inst) {
 40			if (gsp->intr[i].stall != ~0)
 41				return gsp->intr[i].stall;
 42
 43			return -EINVAL;
 44		}
 45	}
 46
 47	return -ENOENT;
 48}
 49
 50static int
 51nvkm_gsp_fini(struct nvkm_subdev *subdev, enum nvkm_suspend_state suspend)
 52{
 53	struct nvkm_gsp *gsp = nvkm_gsp(subdev);
 54
 55	if (!gsp->func->fini || !gsp->running)
 56		return 0;
 57
 58	return gsp->func->fini(gsp, suspend);
 59}
 60
 61static int
 62nvkm_gsp_init(struct nvkm_subdev *subdev)
 63{
 64	struct nvkm_gsp *gsp = nvkm_gsp(subdev);
 65
 66	if (!gsp->func->init)
 67		return 0;
 68
 69	return gsp->func->init(gsp);
 70}
 71
 72static int
 73nvkm_gsp_oneinit(struct nvkm_subdev *subdev)
 74{
 75	struct nvkm_gsp *gsp = nvkm_gsp(subdev);
 76
 77	if (!gsp->func->oneinit)
 78		return 0;
 79
 80	return gsp->func->oneinit(gsp);
 81}
 82
 83void
 84nvkm_gsp_dtor_fws(struct nvkm_gsp *gsp)
 85{
 86	nvkm_firmware_put(gsp->fws.fmc);
 87	gsp->fws.fmc = NULL;
 88	nvkm_firmware_put(gsp->fws.bl);
 89	gsp->fws.bl = NULL;
 90	nvkm_firmware_put(gsp->fws.booter.unload);
 91	gsp->fws.booter.unload = NULL;
 92	nvkm_firmware_put(gsp->fws.booter.load);
 93	gsp->fws.booter.load = NULL;
 94	nvkm_firmware_put(gsp->fws.rm);
 95	gsp->fws.rm = NULL;
 96}
 97
 98static void *
 99nvkm_gsp_dtor(struct nvkm_subdev *subdev)
100{
101	struct nvkm_gsp *gsp = nvkm_gsp(subdev);
102
103	if (gsp->func && gsp->func->dtor)
104		gsp->func->dtor(gsp);
105
106	nvkm_falcon_dtor(&gsp->falcon);
107	kfree(gsp->rm);
108	return gsp;
109}
110
111static const struct nvkm_subdev_func
112nvkm_gsp = {
113	.dtor = nvkm_gsp_dtor,
114	.oneinit = nvkm_gsp_oneinit,
115	.init = nvkm_gsp_init,
116	.fini = nvkm_gsp_fini,
117};
118
119int
120nvkm_gsp_load_fw(struct nvkm_gsp *gsp, const char *name, const char *ver,
121		 const struct firmware **pfw)
122{
123	char fwname[64];
124
125	snprintf(fwname, sizeof(fwname), "gsp/%s-%s", name, ver);
126	return nvkm_firmware_get(&gsp->subdev, fwname, 0, pfw);
127}
128
129int
130nvkm_gsp_new_(const struct nvkm_gsp_fwif *fwif, struct nvkm_device *device,
131	      enum nvkm_subdev_type type, int inst, struct nvkm_gsp **pgsp)
132{
133	struct nvkm_gsp *gsp;
134
135	if (!(gsp = *pgsp = kzalloc(sizeof(*gsp), GFP_KERNEL)))
136		return -ENOMEM;
137
138	nvkm_subdev_ctor(&nvkm_gsp, device, type, inst, &gsp->subdev);
139
140	fwif = nvkm_firmware_load(&gsp->subdev, fwif, "Gsp", gsp);
141	if (IS_ERR(fwif)) {
142		nvkm_error(&gsp->subdev, "Failed to load required firmware for device.");
143		return PTR_ERR(fwif);
144	}
145
146	gsp->func = fwif->func;
147
148	if (fwif->rm) {
149		nvkm_info(&gsp->subdev, "RM version: %s\n", fwif->ver);
150
151		gsp->rm = kzalloc(sizeof(*gsp->rm), GFP_KERNEL);
152		if (!gsp->rm)
153			return -ENOMEM;
154
155		gsp->rm->device = device;
156		gsp->rm->gpu = fwif->func->rm.gpu;
157		gsp->rm->wpr = fwif->rm->wpr;
158		gsp->rm->api = fwif->rm->api;
159	}
160
161	return nvkm_falcon_ctor(gsp->func->flcn, &gsp->subdev, gsp->subdev.name, 0x110000,
162				&gsp->falcon);
163}
~/ Read-only file preview.