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

Configure Feed

Select the types of activity you want to include in your feed.

drm/xe: Move rebar to its own file

Now that xe_pci.c calls the rebar directly, it doesn't make sense to
keep it in xe_vram.c since it's closer to the PCI initialization than to
the VRAM. Move it to its own file.

While at it, add a better comment to document the possible values for
the vram_bar_size module parameter.

Reviewed-by: Matt Roper <matthew.d.roper@intel.com>
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://patch.msgid.link/20251219211650.1908961-5-matthew.d.roper@intel.com
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>

authored by

Lucas De Marchi and committed by
Matt Roper
382876af ac1317df

+124 -93
+1
drivers/gpu/drm/xe/Makefile
··· 98 98 xe_page_reclaim.o \ 99 99 xe_pat.o \ 100 100 xe_pci.o \ 101 + xe_pci_rebar.o \ 101 102 xe_pcode.o \ 102 103 xe_pm.o \ 103 104 xe_preempt_fence.o \
+2 -1
drivers/gpu/drm/xe/xe_pci.c
··· 27 27 #include "xe_macros.h" 28 28 #include "xe_mmio.h" 29 29 #include "xe_module.h" 30 + #include "xe_pci_rebar.h" 30 31 #include "xe_pci_sriov.h" 31 32 #include "xe_pci_types.h" 32 33 #include "xe_pm.h" ··· 1022 1021 if (err) 1023 1022 return err; 1024 1023 1025 - xe_vram_resize_bar(xe); 1024 + xe_pci_rebar_resize(xe); 1026 1025 1027 1026 err = xe_device_probe_early(xe); 1028 1027 /*
+108
drivers/gpu/drm/xe/xe_pci_rebar.c
··· 1 + // SPDX-License-Identifier: MIT 2 + /* 3 + * Copyright © 2025 Intel Corporation 4 + */ 5 + 6 + #include <linux/pci.h> 7 + #include <linux/types.h> 8 + 9 + #include <drm/drm_print.h> 10 + 11 + #include "regs/xe_bars.h" 12 + #include "xe_device_types.h" 13 + #include "xe_module.h" 14 + #include "xe_pci_rebar.h" 15 + 16 + static void resize_bar(struct xe_device *xe, int resno, resource_size_t size) 17 + { 18 + struct pci_dev *pdev = to_pci_dev(xe->drm.dev); 19 + int bar_size = pci_rebar_bytes_to_size(size); 20 + int ret; 21 + 22 + ret = pci_resize_resource(pdev, resno, bar_size, 0); 23 + if (ret) { 24 + drm_info(&xe->drm, "Failed to resize BAR%d to %dM (%pe). Consider enabling 'Resizable BAR' support in your BIOS\n", 25 + resno, 1 << bar_size, ERR_PTR(ret)); 26 + return; 27 + } 28 + 29 + drm_info(&xe->drm, "BAR%d resized to %dM\n", resno, 1 << bar_size); 30 + } 31 + 32 + /* 33 + * xe_pci_rebar_resize - Resize the LMEMBAR 34 + * @xe: xe device instance 35 + * 36 + * If vram_bar_size module param is set, attempt to set to the requested size 37 + * else set to maximum possible size. 38 + */ 39 + void xe_pci_rebar_resize(struct xe_device *xe) 40 + { 41 + int force_vram_bar_size = xe_modparam.force_vram_bar_size; 42 + struct pci_dev *pdev = to_pci_dev(xe->drm.dev); 43 + struct pci_bus *root = pdev->bus; 44 + resource_size_t current_size; 45 + resource_size_t rebar_size; 46 + struct resource *root_res; 47 + int max_size, i; 48 + u32 pci_cmd; 49 + 50 + /* gather some relevant info */ 51 + current_size = pci_resource_len(pdev, LMEM_BAR); 52 + 53 + if (force_vram_bar_size < 0) 54 + return; 55 + 56 + /* set to a specific size? */ 57 + if (force_vram_bar_size) { 58 + rebar_size = pci_rebar_bytes_to_size(force_vram_bar_size * 59 + (resource_size_t)SZ_1M); 60 + 61 + if (!pci_rebar_size_supported(pdev, LMEM_BAR, rebar_size)) { 62 + drm_info(&xe->drm, 63 + "Requested size: %lluMiB is not supported by rebar sizes: 0x%llx. Leaving default: %lluMiB\n", 64 + (u64)pci_rebar_size_to_bytes(rebar_size) >> 20, 65 + pci_rebar_get_possible_sizes(pdev, LMEM_BAR), 66 + (u64)current_size >> 20); 67 + return; 68 + } 69 + 70 + rebar_size = pci_rebar_size_to_bytes(rebar_size); 71 + if (rebar_size == current_size) 72 + return; 73 + } else { 74 + max_size = pci_rebar_get_max_size(pdev, LMEM_BAR); 75 + if (max_size < 0) 76 + return; 77 + rebar_size = pci_rebar_size_to_bytes(max_size); 78 + 79 + /* only resize if larger than current */ 80 + if (rebar_size <= current_size) 81 + return; 82 + } 83 + 84 + drm_info(&xe->drm, "Attempting to resize bar from %lluMiB -> %lluMiB\n", 85 + (u64)current_size >> 20, (u64)rebar_size >> 20); 86 + 87 + while (root->parent) 88 + root = root->parent; 89 + 90 + pci_bus_for_each_resource(root, root_res, i) { 91 + if (root_res && root_res->flags & (IORESOURCE_MEM | IORESOURCE_MEM_64) && 92 + (u64)root_res->start > 0x100000000ul) 93 + break; 94 + } 95 + 96 + if (!root_res) { 97 + drm_info(&xe->drm, "Can't resize VRAM BAR - platform support is missing. Consider enabling 'Resizable BAR' support in your BIOS\n"); 98 + return; 99 + } 100 + 101 + pci_read_config_dword(pdev, PCI_COMMAND, &pci_cmd); 102 + pci_write_config_dword(pdev, PCI_COMMAND, pci_cmd & ~PCI_COMMAND_MEMORY); 103 + 104 + resize_bar(xe, LMEM_BAR, rebar_size); 105 + 106 + pci_assign_unassigned_bus_resources(pdev->bus); 107 + pci_write_config_dword(pdev, PCI_COMMAND, pci_cmd); 108 + }
+13
drivers/gpu/drm/xe/xe_pci_rebar.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2025 Intel Corporation 4 + */ 5 + 6 + #ifndef _XE_PCI_REBAR_H_ 7 + #define _XE_PCI_REBAR_H_ 8 + 9 + struct xe_device; 10 + 11 + void xe_pci_rebar_resize(struct xe_device *xe); 12 + 13 + #endif
-91
drivers/gpu/drm/xe/xe_vram.c
··· 25 25 #include "xe_vram.h" 26 26 #include "xe_vram_types.h" 27 27 28 - static void resize_bar(struct xe_device *xe, int resno, resource_size_t size) 29 - { 30 - struct pci_dev *pdev = to_pci_dev(xe->drm.dev); 31 - int bar_size = pci_rebar_bytes_to_size(size); 32 - int ret; 33 - 34 - ret = pci_resize_resource(pdev, resno, bar_size, 0); 35 - if (ret) { 36 - drm_info(&xe->drm, "Failed to resize BAR%d to %dM (%pe). Consider enabling 'Resizable BAR' support in your BIOS\n", 37 - resno, 1 << bar_size, ERR_PTR(ret)); 38 - return; 39 - } 40 - 41 - drm_info(&xe->drm, "BAR%d resized to %dM\n", resno, 1 << bar_size); 42 - } 43 - 44 - /* 45 - * if force_vram_bar_size is set, attempt to set to the requested size 46 - * else set to maximum possible size 47 - */ 48 - void xe_vram_resize_bar(struct xe_device *xe) 49 - { 50 - int force_vram_bar_size = xe_modparam.force_vram_bar_size; 51 - struct pci_dev *pdev = to_pci_dev(xe->drm.dev); 52 - struct pci_bus *root = pdev->bus; 53 - resource_size_t current_size; 54 - resource_size_t rebar_size; 55 - struct resource *root_res; 56 - int max_size, i; 57 - u32 pci_cmd; 58 - 59 - /* gather some relevant info */ 60 - current_size = pci_resource_len(pdev, LMEM_BAR); 61 - 62 - if (force_vram_bar_size < 0) 63 - return; 64 - 65 - /* set to a specific size? */ 66 - if (force_vram_bar_size) { 67 - rebar_size = pci_rebar_bytes_to_size(force_vram_bar_size * 68 - (resource_size_t)SZ_1M); 69 - 70 - if (!pci_rebar_size_supported(pdev, LMEM_BAR, rebar_size)) { 71 - drm_info(&xe->drm, 72 - "Requested size: %lluMiB is not supported by rebar sizes: 0x%llx. Leaving default: %lluMiB\n", 73 - (u64)pci_rebar_size_to_bytes(rebar_size) >> 20, 74 - pci_rebar_get_possible_sizes(pdev, LMEM_BAR), 75 - (u64)current_size >> 20); 76 - return; 77 - } 78 - 79 - rebar_size = pci_rebar_size_to_bytes(rebar_size); 80 - if (rebar_size == current_size) 81 - return; 82 - } else { 83 - max_size = pci_rebar_get_max_size(pdev, LMEM_BAR); 84 - if (max_size < 0) 85 - return; 86 - rebar_size = pci_rebar_size_to_bytes(max_size); 87 - 88 - /* only resize if larger than current */ 89 - if (rebar_size <= current_size) 90 - return; 91 - } 92 - 93 - drm_info(&xe->drm, "Attempting to resize bar from %lluMiB -> %lluMiB\n", 94 - (u64)current_size >> 20, (u64)rebar_size >> 20); 95 - 96 - while (root->parent) 97 - root = root->parent; 98 - 99 - pci_bus_for_each_resource(root, root_res, i) { 100 - if (root_res && root_res->flags & (IORESOURCE_MEM | IORESOURCE_MEM_64) && 101 - (u64)root_res->start > 0x100000000ul) 102 - break; 103 - } 104 - 105 - if (!root_res) { 106 - drm_info(&xe->drm, "Can't resize VRAM BAR - platform support is missing. Consider enabling 'Resizable BAR' support in your BIOS\n"); 107 - return; 108 - } 109 - 110 - pci_read_config_dword(pdev, PCI_COMMAND, &pci_cmd); 111 - pci_write_config_dword(pdev, PCI_COMMAND, pci_cmd & ~PCI_COMMAND_MEMORY); 112 - 113 - resize_bar(xe, LMEM_BAR, rebar_size); 114 - 115 - pci_assign_unassigned_bus_resources(pdev->bus); 116 - pci_write_config_dword(pdev, PCI_COMMAND, pci_cmd); 117 - } 118 - 119 28 static bool resource_is_valid(struct pci_dev *pdev, int bar) 120 29 { 121 30 if (!pci_resource_flags(pdev, bar))
-1
drivers/gpu/drm/xe/xe_vram.h
··· 11 11 struct xe_device; 12 12 struct xe_vram_region; 13 13 14 - void xe_vram_resize_bar(struct xe_device *xe); 15 14 int xe_vram_probe(struct xe_device *xe); 16 15 17 16 struct xe_vram_region *xe_vram_region_alloc(struct xe_device *xe, u8 id, u32 placement);