| 1 |
/* |
| 2 |
* Copyright © 2023 Collabora Ltd. and Red Hat Inc. |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <inttypes.h> |
| 7 |
#include <stdio.h> |
| 8 |
#include <stdlib.h> |
| 9 |
#include <string.h> |
| 10 |
#include "nv_device_info.h" |
| 11 |
#include "nv_push.h" |
| 12 |
|
| 13 |
#include "cl902d.h" |
| 14 |
|
| 15 |
#include "cla040.h" |
| 16 |
#include "cla140.h" |
| 17 |
|
| 18 |
#include "cla097.h" |
| 19 |
#include "cla197.h" |
| 20 |
#include "cla297.h" |
| 21 |
#include "clb097.h" |
| 22 |
#include "clb197.h" |
| 23 |
#include "clc097.h" |
| 24 |
#include "clc197.h" |
| 25 |
#include "clc397.h" |
| 26 |
#include "clc597.h" |
| 27 |
#include "clc697.h" |
| 28 |
#include "clc797.h" |
| 29 |
#include "clc997.h" |
| 30 |
#include "clcb97.h" |
| 31 |
#include "clcd97.h" |
| 32 |
#include "clce97.h" |
| 33 |
|
| 34 |
#include "cla06f.h" |
| 35 |
#include "cla16f.h" |
| 36 |
#include "cla26f.h" |
| 37 |
#include "clb06f.h" |
| 38 |
#include "clc06f.h" |
| 39 |
#include "clc36f.h" |
| 40 |
#include "clc46f.h" |
| 41 |
#include "clc56f.h" |
| 42 |
|
| 43 |
/* AMPERE_CHANNEL_GPFIFO_B has one typo and as we are replacing |
| 44 |
* headers with the ones from the open-gpu-doc repo, let's hack around this for |
| 45 |
* now |
| 46 |
* XXX: Remove this once it's fixed |
| 47 |
*/ |
| 48 |
#define AmpereAControlGPFifo AmpereBControlGPFifo |
| 49 |
#include "clc76f.h" |
| 50 |
#undef AmpereAControlGPFifo |
| 51 |
|
| 52 |
#include "clc86f.h" |
| 53 |
#include "clc96f.h" |
| 54 |
#include "clca6f.h" |
| 55 |
|
| 56 |
#include "cla0b5.h" |
| 57 |
#include "clb0b5.h" |
| 58 |
#include "clc0b5.h" |
| 59 |
#include "clc1b5.h" |
| 60 |
#include "clc3b5.h" |
| 61 |
#include "clc5b5.h" |
| 62 |
#include "clc6b5.h" |
| 63 |
#include "clc9b5.h" |
| 64 |
#include "clcab5.h" |
| 65 |
|
| 66 |
#include "cla0c0.h" |
| 67 |
#include "cla1c0.h" |
| 68 |
#include "clb0c0.h" |
| 69 |
#include "clb1c0.h" |
| 70 |
#include "clc0c0.h" |
| 71 |
#include "clc1c0.h" |
| 72 |
#include "clc3c0.h" |
| 73 |
#include "clc5c0.h" |
| 74 |
#include "clc6c0.h" |
| 75 |
#include "clc7c0.h" |
| 76 |
#include "clc9c0.h" |
| 77 |
#include "clcbc0.h" |
| 78 |
#include "clcdc0.h" |
| 79 |
#include "clcec0.h" |
| 80 |
|
| 81 |
#include "util/macros.h" |
| 82 |
|
| 83 |
struct device_info { |
| 84 |
const char *gen_name; |
| 85 |
const char *alias_name; |
| 86 |
uint16_t cls_eng3d; |
| 87 |
uint16_t cls_compute; |
| 88 |
uint16_t cls_copy; |
| 89 |
uint16_t cls_m2mf; |
| 90 |
uint16_t cls_gpfifo; |
| 91 |
}; |
| 92 |
|
| 93 |
struct device_info fake_devices[] = { |
| 94 |
{"KEPLER_A", "KEPLER", KEPLER_A, KEPLER_COMPUTE_A, KEPLER_DMA_COPY_A, KEPLER_INLINE_TO_MEMORY_A, KEPLER_CHANNEL_GPFIFO_A}, |
| 95 |
{"KEPLER_B", NULL, KEPLER_B, KEPLER_COMPUTE_B, KEPLER_DMA_COPY_A, KEPLER_INLINE_TO_MEMORY_B, KEPLER_CHANNEL_GPFIFO_B}, |
| 96 |
{"KEPLER_C", NULL, KEPLER_C, KEPLER_COMPUTE_B, KEPLER_DMA_COPY_A, KEPLER_INLINE_TO_MEMORY_B, KEPLER_CHANNEL_GPFIFO_C}, |
| 97 |
{"MAXWELL_A", "MAXWELL", MAXWELL_A, MAXWELL_COMPUTE_A, MAXWELL_DMA_COPY_A, KEPLER_INLINE_TO_MEMORY_B, MAXWELL_CHANNEL_GPFIFO_A}, |
| 98 |
{"MAXWELL_B", NULL, MAXWELL_B, MAXWELL_COMPUTE_B, MAXWELL_DMA_COPY_A, KEPLER_INLINE_TO_MEMORY_B, MAXWELL_CHANNEL_GPFIFO_A}, |
| 99 |
{"PASCAL_A", "PASCAL", PASCAL_A, PASCAL_COMPUTE_A, PASCAL_DMA_COPY_A, KEPLER_INLINE_TO_MEMORY_B, PASCAL_CHANNEL_GPFIFO_A}, |
| 100 |
{"PASCAL_B", NULL, PASCAL_B, PASCAL_COMPUTE_B, PASCAL_DMA_COPY_B, KEPLER_INLINE_TO_MEMORY_B, PASCAL_CHANNEL_GPFIFO_A}, |
| 101 |
{"VOLTA_A", "VOLTA", VOLTA_A, VOLTA_COMPUTE_A, VOLTA_DMA_COPY_A, KEPLER_INLINE_TO_MEMORY_B, VOLTA_CHANNEL_GPFIFO_A}, |
| 102 |
{"TURING_A", "TURING", TURING_A, TURING_COMPUTE_A, TURING_DMA_COPY_A, KEPLER_INLINE_TO_MEMORY_B, TURING_CHANNEL_GPFIFO_A}, |
| 103 |
{"AMPERE_A", "AMPERE", AMPERE_A, AMPERE_COMPUTE_A, AMPERE_DMA_COPY_A, KEPLER_INLINE_TO_MEMORY_B, AMPERE_CHANNEL_GPFIFO_A}, |
| 104 |
{"AMPERE_B", NULL, AMPERE_B, AMPERE_COMPUTE_B, AMPERE_DMA_COPY_A, KEPLER_INLINE_TO_MEMORY_B, AMPERE_CHANNEL_GPFIFO_B}, |
| 105 |
{"ADA_A", "ADA", ADA_A, ADA_COMPUTE_A, AMPERE_DMA_COPY_A, KEPLER_INLINE_TO_MEMORY_B, AMPERE_CHANNEL_GPFIFO_B}, |
| 106 |
{"HOPPER_A", "HOPPER", HOPPER_A, HOPPER_COMPUTE_A, AMPERE_DMA_COPY_A, KEPLER_INLINE_TO_MEMORY_B, HOPPER_CHANNEL_GPFIFO_A}, |
| 107 |
{"BLACKWELL_A", NULL, BLACKWELL_A, BLACKWELL_COMPUTE_A, BLACKWELL_DMA_COPY_A, KEPLER_INLINE_TO_MEMORY_B, BLACKWELL_CHANNEL_GPFIFO_A}, |
| 108 |
{"BLACKWELL_B", NULL, BLACKWELL_B, BLACKWELL_COMPUTE_B, BLACKWELL_DMA_COPY_B, KEPLER_INLINE_TO_MEMORY_B, BLACKWELL_CHANNEL_GPFIFO_B}, |
| 109 |
}; |
| 110 |
|
| 111 |
static struct nv_device_info |
| 112 |
get_fake_device_info(const char *arch_name) |
| 113 |
{ |
| 114 |
struct nv_device_info info; |
| 115 |
|
| 116 |
memset(&info, 0, sizeof(info)); |
| 117 |
info.cls_eng2d = FERMI_TWOD_A; |
| 118 |
|
| 119 |
for (int i = 0; i < ARRAY_SIZE(fake_devices); i++) { |
| 120 |
const struct device_info *fake_device = &fake_devices[i]; |
| 121 |
|
| 122 |
if ((fake_device->alias_name && !strcmp(arch_name, fake_device->alias_name)) || |
| 123 |
!strcmp(arch_name, fake_device->gen_name)) { |
| 124 |
info.cls_eng3d = fake_device->cls_eng3d; |
| 125 |
info.cls_compute = fake_device->cls_compute; |
| 126 |
info.cls_copy = fake_device->cls_copy; |
| 127 |
info.cls_m2mf = fake_device->cls_m2mf; |
| 128 |
info.cls_gpfifo = fake_device->cls_gpfifo; |
| 129 |
|
| 130 |
return info; |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
fprintf(stderr, "Unknown architecture \"%s\", defaulting to Turing", |
| 135 |
arch_name); |
| 136 |
info.cls_eng3d = TURING_A; |
| 137 |
info.cls_compute = TURING_COMPUTE_A; |
| 138 |
info.cls_copy = TURING_DMA_COPY_A; |
| 139 |
info.cls_gpfifo = TURING_CHANNEL_GPFIFO_A; |
| 140 |
info.cls_m2mf = KEPLER_INLINE_TO_MEMORY_B; |
| 141 |
|
| 142 |
return info; |
| 143 |
} |
| 144 |
|
| 145 |
int |
| 146 |
main(int argc, char **argv) |
| 147 |
{ |
| 148 |
const char *arch_name; |
| 149 |
const char *file_name; |
| 150 |
FILE *file; |
| 151 |
long file_size; |
| 152 |
uint32_t *data; |
| 153 |
struct nv_device_info device_info; |
| 154 |
struct nv_push pushbuf; |
| 155 |
|
| 156 |
if (argc != 3) { |
| 157 |
fprintf(stderr, "Usage: nv_push_dump file.bin " |
| 158 |
"<KEPLER|MAXWELL|VOLTA|TURING|AMPERE|ADA|HOPPER|BLACKWELL_A|BLACKWELL_B>\n"); |
| 159 |
return 1; |
| 160 |
} |
| 161 |
|
| 162 |
file_name = argv[1]; |
| 163 |
arch_name = argv[2]; |
| 164 |
|
| 165 |
device_info = get_fake_device_info(arch_name); |
| 166 |
|
| 167 |
file = fopen(file_name, "r"); |
| 168 |
|
| 169 |
if (file == NULL) { |
| 170 |
fprintf(stderr, "couldn't open file \"%s\"\n", file_name); |
| 171 |
return 1; |
| 172 |
} |
| 173 |
|
| 174 |
fseek(file, 0L, SEEK_END); |
| 175 |
file_size = ftell(file); |
| 176 |
fseek(file, 0L, SEEK_SET); |
| 177 |
|
| 178 |
if (file_size % 4 != 0) { |
| 179 |
fclose(file); |
| 180 |
|
| 181 |
fprintf(stderr, "invalid file, data isn't aligned to 4 bytes\n"); |
| 182 |
return 1; |
| 183 |
} |
| 184 |
|
| 185 |
data = malloc(file_size); |
| 186 |
|
| 187 |
if (data == NULL) { |
| 188 |
fclose(file); |
| 189 |
|
| 190 |
fprintf(stderr, "memory allocation failed\n"); |
| 191 |
return 1; |
| 192 |
} |
| 193 |
|
| 194 |
fread(data, file_size, 1, file); |
| 195 |
fclose(file); |
| 196 |
|
| 197 |
nv_push_init(&pushbuf, data, file_size / 4, SUBC_MASK_ALL); |
| 198 |
pushbuf.end = pushbuf.limit; |
| 199 |
|
| 200 |
vk_push_print(stdout, &pushbuf, &device_info); |
| 201 |
|
| 202 |
free(data); |
| 203 |
|
| 204 |
return 0; |
| 205 |
} |