Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/xe: Add sysfs entry for tile

We have recently introduced tile for each gpu,
so lets add sysfs entry per tile for userspace
to provide required information specific to tile.

V5:
- define ktype as const
V4:
- Reorder headers - Aravind
V3:
- Make API to return void and add drm_warn - Aravind
V2:
- Add logs in failure path

Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@intel.com>
Signed-off-by: Tejas Upadhyay <tejas.upadhyay@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

authored by

Tejas Upadhyay and committed by
Rodrigo Vivi
e5a845fd 5572a004

+114
+1
drivers/gpu/drm/xe/Makefile
··· 103 103 xe_step.o \ 104 104 xe_sync.o \ 105 105 xe_tile.o \ 106 + xe_tile_sysfs.o \ 106 107 xe_trace.o \ 107 108 xe_ttm_sys_mgr.o \ 108 109 xe_ttm_stolen_mgr.o \
+3
drivers/gpu/drm/xe/xe_device_types.h
··· 144 144 145 145 /** @migrate: Migration helper for vram blits and clearing */ 146 146 struct xe_migrate *migrate; 147 + 148 + /** @sysfs: sysfs' kobj used by xe_tile_sysfs */ 149 + struct kobject *sysfs; 147 150 }; 148 151 149 152 /**
+3
drivers/gpu/drm/xe/xe_tile.c
··· 10 10 #include "xe_migrate.h" 11 11 #include "xe_sa.h" 12 12 #include "xe_tile.h" 13 + #include "xe_tile_sysfs.h" 13 14 #include "xe_ttm_vram_mgr.h" 14 15 15 16 /** ··· 142 141 tile->mem.kernel_bb_pool = xe_sa_bo_manager_init(tile, SZ_1M, 16); 143 142 if (IS_ERR(tile->mem.kernel_bb_pool)) 144 143 err = PTR_ERR(tile->mem.kernel_bb_pool); 144 + 145 + xe_tile_sysfs_init(tile); 145 146 146 147 err_mem_access: 147 148 xe_device_mem_access_put(tile_to_xe(tile));
+2
drivers/gpu/drm/xe/xe_tile.h
··· 6 6 #ifndef _XE_TILE_H_ 7 7 #define _XE_TILE_H_ 8 8 9 + #include "xe_device_types.h" 10 + 9 11 struct xe_tile; 10 12 11 13 int xe_tile_alloc(struct xe_tile *tile);
+59
drivers/gpu/drm/xe/xe_tile_sysfs.c
··· 1 + // SPDX-License-Identifier: MIT 2 + /* 3 + * Copyright © 2023 Intel Corporation 4 + */ 5 + 6 + #include <linux/kobject.h> 7 + #include <linux/sysfs.h> 8 + #include <drm/drm_managed.h> 9 + 10 + #include "xe_tile.h" 11 + #include "xe_tile_sysfs.h" 12 + 13 + static void xe_tile_sysfs_kobj_release(struct kobject *kobj) 14 + { 15 + kfree(kobj); 16 + } 17 + 18 + static const struct kobj_type xe_tile_sysfs_kobj_type = { 19 + .release = xe_tile_sysfs_kobj_release, 20 + .sysfs_ops = &kobj_sysfs_ops, 21 + }; 22 + 23 + static void tile_sysfs_fini(struct drm_device *drm, void *arg) 24 + { 25 + struct xe_tile *tile = arg; 26 + 27 + kobject_put(tile->sysfs); 28 + } 29 + 30 + void xe_tile_sysfs_init(struct xe_tile *tile) 31 + { 32 + struct xe_device *xe = tile_to_xe(tile); 33 + struct device *dev = xe->drm.dev; 34 + struct kobj_tile *kt; 35 + int err; 36 + 37 + kt = kzalloc(sizeof(*kt), GFP_KERNEL); 38 + if (!kt) 39 + return; 40 + 41 + kobject_init(&kt->base, &xe_tile_sysfs_kobj_type); 42 + kt->tile = tile; 43 + 44 + err = kobject_add(&kt->base, &dev->kobj, "tile%d", tile->id); 45 + if (err) { 46 + kobject_put(&kt->base); 47 + drm_warn(&xe->drm, "failed to register TILE sysfs directory, err: %d\n", err); 48 + return; 49 + } 50 + 51 + tile->sysfs = &kt->base; 52 + 53 + err = drmm_add_action_or_reset(&xe->drm, tile_sysfs_fini, tile); 54 + if (err) { 55 + drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n", 56 + __func__, err); 57 + return; 58 + } 59 + }
+19
drivers/gpu/drm/xe/xe_tile_sysfs.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2023 Intel Corporation 4 + */ 5 + 6 + #ifndef _XE_TILE_SYSFS_H_ 7 + #define _XE_TILE_SYSFS_H_ 8 + 9 + #include "xe_tile_sysfs_types.h" 10 + 11 + void xe_tile_sysfs_init(struct xe_tile *tile); 12 + 13 + static inline struct xe_tile * 14 + kobj_to_tile(struct kobject *kobj) 15 + { 16 + return container_of(kobj, struct kobj_tile, base)->tile; 17 + } 18 + 19 + #endif /* _XE_TILE_SYSFS_H_ */
+27
drivers/gpu/drm/xe/xe_tile_sysfs_types.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2023 Intel Corporation 4 + */ 5 + 6 + #ifndef _XE_TILE_SYSFS_TYPES_H_ 7 + #define _XE_TILE_SYSFS_TYPES_H_ 8 + 9 + #include <linux/kobject.h> 10 + 11 + struct xe_tile; 12 + 13 + /** 14 + * struct kobj_tile - A tile's kobject struct that connects the kobject 15 + * and the TILE 16 + * 17 + * When dealing with multiple TILEs, this struct helps to understand which 18 + * TILE needs to be addressed on a given sysfs call. 19 + */ 20 + struct kobj_tile { 21 + /** @base: The actual kobject */ 22 + struct kobject base; 23 + /** @tile: A pointer to the tile itself */ 24 + struct xe_tile *tile; 25 + }; 26 + 27 + #endif /* _XE_TILE_SYSFS_TYPES_H_ */