Skip to content

Commit

Permalink
drm/nouveau/gsp: select implementation based on available firmware
Browse files Browse the repository at this point in the history
This will allow for further customisation of the subdev depending on what
firmware is available.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
  • Loading branch information
Ben Skeggs committed Jan 15, 2020
1 parent c63fe2e commit 78b10b7
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 30 deletions.
1 change: 1 addition & 0 deletions drivers/gpu/drm/nouveau/nvkm/subdev/gsp/Kbuild
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# SPDX-License-Identifier: MIT
nvkm-y += nvkm/subdev/gsp/base.o
nvkm-y += nvkm/subdev/gsp/gv100.o
70 changes: 70 additions & 0 deletions drivers/gpu/drm/nouveau/nvkm/subdev/gsp/base.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2019 Red Hat Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "priv.h"
#include <core/falcon.h>
#include <core/firmware.h>
#include <subdev/acr.h>
#include <subdev/top.h>

static int
nvkm_gsp_oneinit(struct nvkm_subdev *subdev)
{
struct nvkm_gsp *gsp = nvkm_gsp(subdev);

gsp->addr = nvkm_top_addr(subdev->device, subdev->index);
if (!gsp->addr)
return -EINVAL;

return nvkm_falcon_v1_new(subdev, "GSP", gsp->addr, &gsp->falcon);
}

static void *
nvkm_gsp_dtor(struct nvkm_subdev *subdev)
{
struct nvkm_gsp *gsp = nvkm_gsp(subdev);
nvkm_falcon_del(&gsp->falcon);
return gsp;
}

static const struct nvkm_subdev_func
nvkm_gsp = {
.dtor = nvkm_gsp_dtor,
.oneinit = nvkm_gsp_oneinit,
};

int
nvkm_gsp_new_(const struct nvkm_gsp_fwif *fwif, struct nvkm_device *device,
int index, struct nvkm_gsp **pgsp)
{
struct nvkm_gsp *gsp;

if (!(gsp = *pgsp = kzalloc(sizeof(*gsp), GFP_KERNEL)))
return -ENOMEM;

nvkm_subdev_ctor(&nvkm_gsp, device, index, &gsp->subdev);

fwif = nvkm_firmware_load(&gsp->subdev, fwif, "Gsp", gsp);
if (IS_ERR(fwif))
return PTR_ERR(fwif);

return 0;
}
38 changes: 8 additions & 30 deletions drivers/gpu/drm/nouveau/nvkm/subdev/gsp/gv100.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,22 @@
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <subdev/gsp.h>
#include <subdev/top.h>
#include <engine/falcon.h>
#include "priv.h"

static int
gv100_gsp_oneinit(struct nvkm_subdev *subdev)
gv100_gsp_nofw(struct nvkm_gsp *gsp, int ver, const struct nvkm_gsp_fwif *fwif)
{
struct nvkm_gsp *gsp = nvkm_gsp(subdev);

gsp->addr = nvkm_top_addr(subdev->device, subdev->index);
if (!gsp->addr)
return -EINVAL;

return nvkm_falcon_v1_new(subdev, "GSP", gsp->addr, &gsp->falcon);
}

static void *
gv100_gsp_dtor(struct nvkm_subdev *subdev)
{
struct nvkm_gsp *gsp = nvkm_gsp(subdev);
nvkm_falcon_del(&gsp->falcon);
return gsp;
return 0;
}

static const struct nvkm_subdev_func
gv100_gsp = {
.dtor = gv100_gsp_dtor,
.oneinit = gv100_gsp_oneinit,
struct nvkm_gsp_fwif
gv100_gsp[] = {
{ -1, gv100_gsp_nofw },
{}
};

int
gv100_gsp_new(struct nvkm_device *device, int index, struct nvkm_gsp **pgsp)
{
struct nvkm_gsp *gsp;

if (!(gsp = *pgsp = kzalloc(sizeof(*gsp), GFP_KERNEL)))
return -ENOMEM;

nvkm_subdev_ctor(&gv100_gsp, device, index, &gsp->subdev);
return 0;
return nvkm_gsp_new_(gv100_gsp, device, index, pgsp);
}
14 changes: 14 additions & 0 deletions drivers/gpu/drm/nouveau/nvkm/subdev/gsp/priv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* SPDX-License-Identifier: MIT */
#ifndef __NVKM_GSP_PRIV_H__
#define __NVKM_GSP_PRIV_H__
#include <subdev/gsp.h>
enum nvkm_acr_lsf_id;

struct nvkm_gsp_fwif {
int version;
int (*load)(struct nvkm_gsp *, int ver, const struct nvkm_gsp_fwif *);
};

int nvkm_gsp_new_(const struct nvkm_gsp_fwif *, struct nvkm_device *, int,
struct nvkm_gsp **);
#endif

0 comments on commit 78b10b7

Please sign in to comment.