Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: MIT
nvkm-y += nvkm/subdev/vfn/base.o
nvkm-y += nvkm/subdev/vfn/uvfn.o
nvkm-y += nvkm/subdev/vfn/gv100.o
nvkm-y += nvkm/subdev/vfn/tu102.o
nvkm-y += nvkm/subdev/vfn/ga100.o
nvkm-y += nvkm/subdev/vfn/r535.o
@@ -0,0 +1,60 @@
/*
* Copyright 2021 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"
static void *
nvkm_vfn_dtor(struct nvkm_subdev *subdev)
{
return nvkm_vfn(subdev);
}
static const struct nvkm_subdev_func
nvkm_vfn = {
.dtor = nvkm_vfn_dtor,
};
int
nvkm_vfn_new_(const struct nvkm_vfn_func *func, struct nvkm_device *device,
enum nvkm_subdev_type type, int inst, u32 addr, struct nvkm_vfn **pvfn)
{
struct nvkm_vfn *vfn;
int ret;
if (!(vfn = *pvfn = kzalloc_obj(*vfn)))
return -ENOMEM;
nvkm_subdev_ctor(&nvkm_vfn, device, type, inst, &vfn->subdev);
vfn->func = func;
vfn->addr.priv = addr;
vfn->addr.user = vfn->addr.priv + func->user.addr;
if (vfn->func->intr) {
ret = nvkm_intr_add(vfn->func->intr, vfn->func->intrs,
&vfn->subdev, 8, &vfn->intr);
if (ret)
return ret;
}
vfn->user.ctor = nvkm_uvfn_new;
vfn->user.base = func->user.base;
return 0;
}
@@ -0,0 +1,52 @@
/*
* Copyright 2021 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 <subdev/gsp.h>
#include <nvif/class.h>
static const struct nvkm_intr_data
ga100_vfn_intrs[] = {
{ NVKM_ENGINE_DISP , 0, 4, 0x04000000, true },
{ NVKM_SUBDEV_GPIO , 0, 4, 0x00200000, true },
{ NVKM_SUBDEV_I2C , 0, 4, 0x00200000, true },
{ NVKM_SUBDEV_PRIVRING, 0, 4, 0x40000000, true },
{}
};
static const struct nvkm_vfn_func
ga100_vfn = {
.intr = &tu102_vfn_intr,
.intrs = ga100_vfn_intrs,
.user = { 0x030000, 0x010000, { -1, -1, AMPERE_USERMODE_A } },
};
int
ga100_vfn_new(struct nvkm_device *device,
enum nvkm_subdev_type type, int inst, struct nvkm_vfn **pvfn)
{
if (nvkm_gsp_rm(device->gsp))
return r535_vfn_new(&ga100_vfn, device, type, inst, 0xb80000, pvfn);
return nvkm_vfn_new_(&ga100_vfn, device, type, inst, 0xb80000, pvfn);
}
@@ -0,0 +1,36 @@
/*
* Copyright 2021 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 <nvif/class.h>
static const struct nvkm_vfn_func
gv100_vfn = {
.user = { 0x810000, 0x010000, { -1, -1, VOLTA_USERMODE_A } },
};
int
gv100_vfn_new(struct nvkm_device *device,
enum nvkm_subdev_type type, int inst, struct nvkm_vfn **pvfn)
{
return nvkm_vfn_new_(&gv100_vfn, device, type, inst, 0, pvfn);
}
@@ -0,0 +1,30 @@
/* SPDX-License-Identifier: MIT */
#ifndef __NVKM_VFN_PRIV_H__
#define __NVKM_VFN_PRIV_H__
#define nvkm_vfn(p) container_of((p), struct nvkm_vfn, subdev)
#include <subdev/vfn.h>
struct nvkm_vfn_func {
void (*dtor)(struct nvkm_vfn *);
const struct nvkm_intr_func *intr;
const struct nvkm_intr_data *intrs;
struct {
u32 addr;
u32 size;
struct nvkm_sclass base;
} user;
};
int r535_vfn_new(const struct nvkm_vfn_func *hw, struct nvkm_device *, enum nvkm_subdev_type, int,
u32 addr, struct nvkm_vfn **);
int nvkm_vfn_new_(const struct nvkm_vfn_func *, struct nvkm_device *, enum nvkm_subdev_type, int,
u32 addr, struct nvkm_vfn **);
extern const struct nvkm_intr_func tu102_vfn_intr;
int nvkm_uvfn_new(struct nvkm_device *, const struct nvkm_oclass *, void *, u32,
struct nvkm_object **);
#endif
@@ -0,0 +1,57 @@
/*
* Copyright 2023 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 <rm/gpu.h>
static void
r535_vfn_dtor(struct nvkm_vfn *vfn)
{
kfree(vfn->func);
}
int
r535_vfn_new(const struct nvkm_vfn_func *hw,
struct nvkm_device *device, enum nvkm_subdev_type type, int inst, u32 addr,
struct nvkm_vfn **pvfn)
{
const struct nvkm_rm_gpu *gpu = device->gsp->rm->gpu;
struct nvkm_vfn_func *rm;
int ret;
if (!(rm = kzalloc_obj(*rm)))
return -ENOMEM;
rm->dtor = r535_vfn_dtor;
rm->intr = &tu102_vfn_intr;
rm->user.addr = 0x030000;
rm->user.size = 0x010000;
rm->user.base.minver = -1;
rm->user.base.maxver = -1;
rm->user.base.oclass = gpu->usermode.class;
ret = nvkm_vfn_new_(rm, device, type, inst, addr, pvfn);
if (ret)
kfree(rm);
return ret;
}
@@ -0,0 +1,113 @@
/*
* Copyright 2021 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 <subdev/gsp.h>
#include <nvif/class.h>
static void
tu102_vfn_intr_reset(struct nvkm_intr *intr, int leaf, u32 mask)
{
struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
nvkm_wr32(vfn->subdev.device, vfn->addr.priv + 0x1000 + (leaf * 4), mask);
}
static void
tu102_vfn_intr_allow(struct nvkm_intr *intr, int leaf, u32 mask)
{
struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
nvkm_wr32(vfn->subdev.device, vfn->addr.priv + 0x1200 + (leaf * 4), mask);
}
static void
tu102_vfn_intr_block(struct nvkm_intr *intr, int leaf, u32 mask)
{
struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
nvkm_wr32(vfn->subdev.device, vfn->addr.priv + 0x1400 + (leaf * 4), mask);
}
static void
tu102_vfn_intr_rearm(struct nvkm_intr *intr)
{
struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
nvkm_wr32(vfn->subdev.device, vfn->addr.priv + 0x1608, 0x0000000f);
}
static void
tu102_vfn_intr_unarm(struct nvkm_intr *intr)
{
struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
nvkm_wr32(vfn->subdev.device, vfn->addr.priv + 0x1610, 0x0000000f);
}
static bool
tu102_vfn_intr_pending(struct nvkm_intr *intr)
{
struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
struct nvkm_device *device = vfn->subdev.device;
u32 intr_top = nvkm_rd32(device, vfn->addr.priv + 0x1600);
int pending = 0, leaf;
for (leaf = 0; leaf < 8; leaf++) {
if (intr_top & BIT(leaf / 2)) {
intr->stat[leaf] = nvkm_rd32(device, vfn->addr.priv + 0x1000 + (leaf * 4));
if (intr->stat[leaf])
pending++;
} else {
intr->stat[leaf] = 0;
}
}
return pending != 0;
}
const struct nvkm_intr_func
tu102_vfn_intr = {
.pending = tu102_vfn_intr_pending,
.unarm = tu102_vfn_intr_unarm,
.rearm = tu102_vfn_intr_rearm,
.block = tu102_vfn_intr_block,
.allow = tu102_vfn_intr_allow,
.reset = tu102_vfn_intr_reset,
};
static const struct nvkm_vfn_func
tu102_vfn = {
.intr = &tu102_vfn_intr,
.user = { 0x030000, 0x010000, { -1, -1, TURING_USERMODE_A } },
};
int
tu102_vfn_new(struct nvkm_device *device,
enum nvkm_subdev_type type, int inst, struct nvkm_vfn **pvfn)
{
if (nvkm_gsp_rm(device->gsp))
return r535_vfn_new(&tu102_vfn, device, type, inst, 0xb80000, pvfn);
return nvkm_vfn_new_(&tu102_vfn, device, type, inst, 0xb80000, pvfn);
}
@@ -0,0 +1,67 @@
/*
* Copyright 2021 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.
*/
#define nvkm_uvfn(p) container_of((p), struct nvkm_uvfn, object)
#include "priv.h"
#include <core/object.h>
struct nvkm_uvfn {
struct nvkm_object object;
struct nvkm_vfn *vfn;
};
static int
nvkm_uvfn_map(struct nvkm_object *object, void *argv, u32 argc,
enum nvkm_object_map *type, u64 *addr, u64 *size)
{
struct nvkm_vfn *vfn = nvkm_uvfn(object)->vfn;
struct nvkm_device *device = vfn->subdev.device;
*addr = device->func->resource_addr(device, NVKM_BAR0_PRI) + vfn->addr.user;
*size = vfn->func->user.size;
*type = NVKM_OBJECT_MAP_IO;
return 0;
}
static const struct nvkm_object_func
nvkm_uvfn = {
.map = nvkm_uvfn_map,
};
int
nvkm_uvfn_new(struct nvkm_device *device, const struct nvkm_oclass *oclass,
void *argv, u32 argc, struct nvkm_object **pobject)
{
struct nvkm_uvfn *uvfn;
if (argc != 0)
return -ENOSYS;
if (!(uvfn = kzalloc_obj(*uvfn)))
return -ENOMEM;
nvkm_object_ctor(&nvkm_uvfn, oclass, &uvfn->object);
uvfn->vfn = device->vfn;
*pobject = &uvfn->object;
return 0;
}