diff options
| author | Joshua Bakita <bakitajoshua@gmail.com> | 2023-06-28 18:24:25 -0400 |
|---|---|---|
| committer | Joshua Bakita <bakitajoshua@gmail.com> | 2023-06-28 18:24:25 -0400 |
| commit | 01e6fac4d61fdd7fff5433942ec93fc2ea1e4df1 (patch) | |
| tree | 4ef34501728a087be24f4ba0af90f91486bf780b /include/os/linux/ecc_sysfs.c | |
| parent | 306a03d18b305e4e573be3b2931978fa10679eb9 (diff) | |
Include nvgpu headers
These are needed to build on NVIDIA's Jetson boards for the time
being. Only a couple structs are required, so it should be fairly
easy to remove this dependency at some point in the future.
Diffstat (limited to 'include/os/linux/ecc_sysfs.c')
| -rw-r--r-- | include/os/linux/ecc_sysfs.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/include/os/linux/ecc_sysfs.c b/include/os/linux/ecc_sysfs.c new file mode 100644 index 0000000..73ae3dc --- /dev/null +++ b/include/os/linux/ecc_sysfs.c | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or modify it | ||
| 5 | * under the terms and conditions of the GNU General Public License, | ||
| 6 | * version 2, as published by the Free Software Foundation. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 11 | * more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <nvgpu/ecc.h> | ||
| 18 | #include <nvgpu/gk20a.h> | ||
| 19 | |||
| 20 | #include "os_linux.h" | ||
| 21 | |||
| 22 | int nvgpu_ecc_sysfs_init(struct gk20a *g) | ||
| 23 | { | ||
| 24 | struct device *dev = dev_from_gk20a(g); | ||
| 25 | struct nvgpu_ecc *ecc = &g->ecc; | ||
| 26 | struct dev_ext_attribute *attr; | ||
| 27 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
| 28 | struct nvgpu_ecc_stat *stat; | ||
| 29 | int i = 0, err; | ||
| 30 | |||
| 31 | attr = nvgpu_kzalloc(g, sizeof(*attr) * ecc->stats_count); | ||
| 32 | if (!attr) | ||
| 33 | return -ENOMEM; | ||
| 34 | |||
| 35 | nvgpu_list_for_each_entry(stat, | ||
| 36 | &ecc->stats_list, nvgpu_ecc_stat, node) { | ||
| 37 | if (i >= ecc->stats_count) { | ||
| 38 | err = -EINVAL; | ||
| 39 | nvgpu_err(g, "stats_list longer than stats_count %d", | ||
| 40 | ecc->stats_count); | ||
| 41 | break; | ||
| 42 | } | ||
| 43 | sysfs_attr_init(&attr[i].attr.attr); | ||
| 44 | attr[i].attr.attr.name = stat->name; | ||
| 45 | attr[i].attr.attr.mode = VERIFY_OCTAL_PERMISSIONS(S_IRUGO); | ||
| 46 | attr[i].var = &stat->counter; | ||
| 47 | attr[i].attr.show = device_show_int; | ||
| 48 | err = device_create_file(dev, &attr[i].attr); | ||
| 49 | if (err) { | ||
| 50 | nvgpu_err(g, "sysfs node create failed for %s\n", | ||
| 51 | stat->name); | ||
| 52 | break; | ||
| 53 | } | ||
| 54 | i++; | ||
| 55 | } | ||
| 56 | |||
| 57 | if (err) { | ||
| 58 | while (i-- > 0) | ||
| 59 | device_remove_file(dev, &attr[i].attr); | ||
| 60 | nvgpu_kfree(g, attr); | ||
| 61 | return err; | ||
| 62 | } | ||
| 63 | |||
| 64 | l->ecc_attrs = attr; | ||
| 65 | |||
| 66 | return 0; | ||
| 67 | } | ||
| 68 | |||
| 69 | void nvgpu_ecc_sysfs_remove(struct gk20a *g) | ||
| 70 | { | ||
| 71 | struct device *dev = dev_from_gk20a(g); | ||
| 72 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
| 73 | struct nvgpu_ecc *ecc = &g->ecc; | ||
| 74 | int i; | ||
| 75 | |||
| 76 | for (i = 0; i < ecc->stats_count; i++) | ||
| 77 | device_remove_file(dev, &l->ecc_attrs[i].attr); | ||
| 78 | nvgpu_kfree(g, l->ecc_attrs); | ||
| 79 | l->ecc_attrs = NULL; | ||
| 80 | } | ||
