summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/amd/amdgpu/ualink_v1_0.c
blob: d440ed6b573360ae9600bed298644746b48dbb61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * Copyright 2026 Advanced Micro Devices, 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 <linux/delay.h>
#include "amdgpu.h"
#include "ivsrcid/mpnht/irqsrcs_mpnht_15_0.h"
#include "amdgpu_ualink.h"
#include "ualink_v1_0.h"

/* nHT firmware mailbox registers via SMN, copy of MP1 */
#define mmMPNHT_SMN_C2PMSG_CMD		0xAE10958
#define mmMPNHT_SMN_C2PMSG_DATA		0xAE1095C
#define mmMPNHT_SMN_C2PMSG_ADDR_LO	0xAE10960
#define mmMPNHT_SMN_C2PMSG_ADDR_HI	0xAE10964
#define mmMPNHT_SMN_C2PMSG_STATUS	0xAE10968

/* nHT firmware commands */
#define UALINK_V1_0_FW_CMD_LOAD_METADATA	0x1
#define UALINK_V1_0_FW_CMD_HALT_OPERATION	0x2

#define UALINK_V1_0_FW_POLL_COUNT	2000

static u32 ualink_v1_0_check_status(struct amdgpu_device *adev)
{
	return RREG32_PCIE(mmMPNHT_SMN_C2PMSG_STATUS);
}

static int ualink_v1_0_send_metadata(struct amdgpu_device *adev,
				     u64 metadata_gpu_addr, u32 accel_data)
{
	u32 status;
	int i;

	dev_dbg(adev->dev, "nht load metadata addr 0x%llx accel_data 0x%x\n",
		metadata_gpu_addr, accel_data);

	WREG32_PCIE(mmMPNHT_SMN_C2PMSG_ADDR_HI, upper_32_bits(metadata_gpu_addr));
	WREG32_PCIE(mmMPNHT_SMN_C2PMSG_ADDR_LO, lower_32_bits(metadata_gpu_addr));
	WREG32_PCIE(mmMPNHT_SMN_C2PMSG_DATA, accel_data);
	WREG32_PCIE(mmMPNHT_SMN_C2PMSG_CMD, UALINK_V1_0_FW_CMD_LOAD_METADATA);

	for (i = 0; i < UALINK_V1_0_FW_POLL_COUNT; i++) {
		status = RREG32_PCIE(mmMPNHT_SMN_C2PMSG_STATUS);
		if (status == AMDGPU_NHT_FW_ST_READY)
			return 0;
		mdelay(1);
	}

	dev_dbg(adev->dev, "f/w load metadata failed 0x%x\n", status);
	return -ETIME;
}

static int ualink_v1_0_send_halt(struct amdgpu_device *adev)
{
	u32 status;
	int i;

	dev_dbg(adev->dev, "nht halt cmd 0x%x\n", UALINK_V1_0_FW_CMD_HALT_OPERATION);

	WREG32_PCIE(mmMPNHT_SMN_C2PMSG_CMD, UALINK_V1_0_FW_CMD_HALT_OPERATION);

	for (i = 0; i < UALINK_V1_0_FW_POLL_COUNT; i++) {
		status = RREG32_PCIE(mmMPNHT_SMN_C2PMSG_STATUS);
		if (status == AMDGPU_NHT_FW_ST_HALT)
			return 0;
		mdelay(1);
	}

	dev_warn(adev->dev, "f/w halt failed status 0x%x\n", status);
	return -ETIME;
}

const struct amdgpu_ualink_msg_ctl ualink_v1_0_msg_ctl = {
	.check_status = ualink_v1_0_check_status,
	.send_metadata = ualink_v1_0_send_metadata,
	.send_halt = ualink_v1_0_send_halt,
};

static int ualink_v1_0_early_init(struct amdgpu_ip_block *ip_block)
{
	struct amdgpu_device *adev = ip_block->adev;

	adev->ualink.msg_ctl = &ualink_v1_0_msg_ctl;

	return 0;
}

static int ualink_v1_0_sw_init(struct amdgpu_ip_block *ip_block)
{
	struct amdgpu_device *adev = ip_block->adev;
	int r;

	r = ualink_ip_sw_init(ip_block);
	if (r)
		return r;

	r = amdgpu_ualink_init_interrupt(adev, SOC_V1_0_IH_CLIENTID_nHT,
					 MPNHT_15_0__SRCID__REMOTE_INTERRUPT);
	if (r) {
		dev_err(adev->dev, "Failed to add UALink irq: %d\n", r);
		return r;
	}

	return 0;
}

static const struct amd_ip_funcs ualink_v1_0_ip_funcs = {
	.name = "ualink",
	.early_init = ualink_v1_0_early_init,
	.late_init = ualink_ip_late_init,
	.sw_init = ualink_v1_0_sw_init,
	.sw_fini = ualink_ip_sw_fini,
	.hw_init = ualink_ip_hw_init,
	.hw_fini = ualink_ip_hw_fini,
};

const struct amdgpu_ip_block_version ualink_v1_0_ip_block = {
	.type = AMD_IP_BLOCK_TYPE_UALINK,
	.major = 1,
	.minor = 0,
	.rev = 0,
	.funcs = &ualink_v1_0_ip_funcs,
};