mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-03-22 07:27:12 +08:00
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>
This commit is contained in:
committed by
Matt Roper
parent
ac1317df03
commit
382876afa7
@@ -98,6 +98,7 @@ xe-y += xe_bb.o \
|
||||
xe_page_reclaim.o \
|
||||
xe_pat.o \
|
||||
xe_pci.o \
|
||||
xe_pci_rebar.o \
|
||||
xe_pcode.o \
|
||||
xe_pm.o \
|
||||
xe_preempt_fence.o \
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "xe_macros.h"
|
||||
#include "xe_mmio.h"
|
||||
#include "xe_module.h"
|
||||
#include "xe_pci_rebar.h"
|
||||
#include "xe_pci_sriov.h"
|
||||
#include "xe_pci_types.h"
|
||||
#include "xe_pm.h"
|
||||
@@ -1021,7 +1022,7 @@ static int xe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
xe_vram_resize_bar(xe);
|
||||
xe_pci_rebar_resize(xe);
|
||||
|
||||
err = xe_device_probe_early(xe);
|
||||
/*
|
||||
|
||||
108
drivers/gpu/drm/xe/xe_pci_rebar.c
Normal file
108
drivers/gpu/drm/xe/xe_pci_rebar.c
Normal file
@@ -0,0 +1,108 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
/*
|
||||
* Copyright © 2025 Intel Corporation
|
||||
*/
|
||||
|
||||
#include <linux/pci.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
#include <drm/drm_print.h>
|
||||
|
||||
#include "regs/xe_bars.h"
|
||||
#include "xe_device_types.h"
|
||||
#include "xe_module.h"
|
||||
#include "xe_pci_rebar.h"
|
||||
|
||||
static void resize_bar(struct xe_device *xe, int resno, resource_size_t size)
|
||||
{
|
||||
struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
|
||||
int bar_size = pci_rebar_bytes_to_size(size);
|
||||
int ret;
|
||||
|
||||
ret = pci_resize_resource(pdev, resno, bar_size, 0);
|
||||
if (ret) {
|
||||
drm_info(&xe->drm, "Failed to resize BAR%d to %dM (%pe). Consider enabling 'Resizable BAR' support in your BIOS\n",
|
||||
resno, 1 << bar_size, ERR_PTR(ret));
|
||||
return;
|
||||
}
|
||||
|
||||
drm_info(&xe->drm, "BAR%d resized to %dM\n", resno, 1 << bar_size);
|
||||
}
|
||||
|
||||
/*
|
||||
* xe_pci_rebar_resize - Resize the LMEMBAR
|
||||
* @xe: xe device instance
|
||||
*
|
||||
* If vram_bar_size module param is set, attempt to set to the requested size
|
||||
* else set to maximum possible size.
|
||||
*/
|
||||
void xe_pci_rebar_resize(struct xe_device *xe)
|
||||
{
|
||||
int force_vram_bar_size = xe_modparam.force_vram_bar_size;
|
||||
struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
|
||||
struct pci_bus *root = pdev->bus;
|
||||
resource_size_t current_size;
|
||||
resource_size_t rebar_size;
|
||||
struct resource *root_res;
|
||||
int max_size, i;
|
||||
u32 pci_cmd;
|
||||
|
||||
/* gather some relevant info */
|
||||
current_size = pci_resource_len(pdev, LMEM_BAR);
|
||||
|
||||
if (force_vram_bar_size < 0)
|
||||
return;
|
||||
|
||||
/* set to a specific size? */
|
||||
if (force_vram_bar_size) {
|
||||
rebar_size = pci_rebar_bytes_to_size(force_vram_bar_size *
|
||||
(resource_size_t)SZ_1M);
|
||||
|
||||
if (!pci_rebar_size_supported(pdev, LMEM_BAR, rebar_size)) {
|
||||
drm_info(&xe->drm,
|
||||
"Requested size: %lluMiB is not supported by rebar sizes: 0x%llx. Leaving default: %lluMiB\n",
|
||||
(u64)pci_rebar_size_to_bytes(rebar_size) >> 20,
|
||||
pci_rebar_get_possible_sizes(pdev, LMEM_BAR),
|
||||
(u64)current_size >> 20);
|
||||
return;
|
||||
}
|
||||
|
||||
rebar_size = pci_rebar_size_to_bytes(rebar_size);
|
||||
if (rebar_size == current_size)
|
||||
return;
|
||||
} else {
|
||||
max_size = pci_rebar_get_max_size(pdev, LMEM_BAR);
|
||||
if (max_size < 0)
|
||||
return;
|
||||
rebar_size = pci_rebar_size_to_bytes(max_size);
|
||||
|
||||
/* only resize if larger than current */
|
||||
if (rebar_size <= current_size)
|
||||
return;
|
||||
}
|
||||
|
||||
drm_info(&xe->drm, "Attempting to resize bar from %lluMiB -> %lluMiB\n",
|
||||
(u64)current_size >> 20, (u64)rebar_size >> 20);
|
||||
|
||||
while (root->parent)
|
||||
root = root->parent;
|
||||
|
||||
pci_bus_for_each_resource(root, root_res, i) {
|
||||
if (root_res && root_res->flags & (IORESOURCE_MEM | IORESOURCE_MEM_64) &&
|
||||
(u64)root_res->start > 0x100000000ul)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!root_res) {
|
||||
drm_info(&xe->drm, "Can't resize VRAM BAR - platform support is missing. Consider enabling 'Resizable BAR' support in your BIOS\n");
|
||||
return;
|
||||
}
|
||||
|
||||
pci_read_config_dword(pdev, PCI_COMMAND, &pci_cmd);
|
||||
pci_write_config_dword(pdev, PCI_COMMAND, pci_cmd & ~PCI_COMMAND_MEMORY);
|
||||
|
||||
resize_bar(xe, LMEM_BAR, rebar_size);
|
||||
|
||||
pci_assign_unassigned_bus_resources(pdev->bus);
|
||||
pci_write_config_dword(pdev, PCI_COMMAND, pci_cmd);
|
||||
}
|
||||
13
drivers/gpu/drm/xe/xe_pci_rebar.h
Normal file
13
drivers/gpu/drm/xe/xe_pci_rebar.h
Normal file
@@ -0,0 +1,13 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
/*
|
||||
* Copyright © 2025 Intel Corporation
|
||||
*/
|
||||
|
||||
#ifndef _XE_PCI_REBAR_H_
|
||||
#define _XE_PCI_REBAR_H_
|
||||
|
||||
struct xe_device;
|
||||
|
||||
void xe_pci_rebar_resize(struct xe_device *xe);
|
||||
|
||||
#endif
|
||||
@@ -25,97 +25,6 @@
|
||||
#include "xe_vram.h"
|
||||
#include "xe_vram_types.h"
|
||||
|
||||
static void resize_bar(struct xe_device *xe, int resno, resource_size_t size)
|
||||
{
|
||||
struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
|
||||
int bar_size = pci_rebar_bytes_to_size(size);
|
||||
int ret;
|
||||
|
||||
ret = pci_resize_resource(pdev, resno, bar_size, 0);
|
||||
if (ret) {
|
||||
drm_info(&xe->drm, "Failed to resize BAR%d to %dM (%pe). Consider enabling 'Resizable BAR' support in your BIOS\n",
|
||||
resno, 1 << bar_size, ERR_PTR(ret));
|
||||
return;
|
||||
}
|
||||
|
||||
drm_info(&xe->drm, "BAR%d resized to %dM\n", resno, 1 << bar_size);
|
||||
}
|
||||
|
||||
/*
|
||||
* if force_vram_bar_size is set, attempt to set to the requested size
|
||||
* else set to maximum possible size
|
||||
*/
|
||||
void xe_vram_resize_bar(struct xe_device *xe)
|
||||
{
|
||||
int force_vram_bar_size = xe_modparam.force_vram_bar_size;
|
||||
struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
|
||||
struct pci_bus *root = pdev->bus;
|
||||
resource_size_t current_size;
|
||||
resource_size_t rebar_size;
|
||||
struct resource *root_res;
|
||||
int max_size, i;
|
||||
u32 pci_cmd;
|
||||
|
||||
/* gather some relevant info */
|
||||
current_size = pci_resource_len(pdev, LMEM_BAR);
|
||||
|
||||
if (force_vram_bar_size < 0)
|
||||
return;
|
||||
|
||||
/* set to a specific size? */
|
||||
if (force_vram_bar_size) {
|
||||
rebar_size = pci_rebar_bytes_to_size(force_vram_bar_size *
|
||||
(resource_size_t)SZ_1M);
|
||||
|
||||
if (!pci_rebar_size_supported(pdev, LMEM_BAR, rebar_size)) {
|
||||
drm_info(&xe->drm,
|
||||
"Requested size: %lluMiB is not supported by rebar sizes: 0x%llx. Leaving default: %lluMiB\n",
|
||||
(u64)pci_rebar_size_to_bytes(rebar_size) >> 20,
|
||||
pci_rebar_get_possible_sizes(pdev, LMEM_BAR),
|
||||
(u64)current_size >> 20);
|
||||
return;
|
||||
}
|
||||
|
||||
rebar_size = pci_rebar_size_to_bytes(rebar_size);
|
||||
if (rebar_size == current_size)
|
||||
return;
|
||||
} else {
|
||||
max_size = pci_rebar_get_max_size(pdev, LMEM_BAR);
|
||||
if (max_size < 0)
|
||||
return;
|
||||
rebar_size = pci_rebar_size_to_bytes(max_size);
|
||||
|
||||
/* only resize if larger than current */
|
||||
if (rebar_size <= current_size)
|
||||
return;
|
||||
}
|
||||
|
||||
drm_info(&xe->drm, "Attempting to resize bar from %lluMiB -> %lluMiB\n",
|
||||
(u64)current_size >> 20, (u64)rebar_size >> 20);
|
||||
|
||||
while (root->parent)
|
||||
root = root->parent;
|
||||
|
||||
pci_bus_for_each_resource(root, root_res, i) {
|
||||
if (root_res && root_res->flags & (IORESOURCE_MEM | IORESOURCE_MEM_64) &&
|
||||
(u64)root_res->start > 0x100000000ul)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!root_res) {
|
||||
drm_info(&xe->drm, "Can't resize VRAM BAR - platform support is missing. Consider enabling 'Resizable BAR' support in your BIOS\n");
|
||||
return;
|
||||
}
|
||||
|
||||
pci_read_config_dword(pdev, PCI_COMMAND, &pci_cmd);
|
||||
pci_write_config_dword(pdev, PCI_COMMAND, pci_cmd & ~PCI_COMMAND_MEMORY);
|
||||
|
||||
resize_bar(xe, LMEM_BAR, rebar_size);
|
||||
|
||||
pci_assign_unassigned_bus_resources(pdev->bus);
|
||||
pci_write_config_dword(pdev, PCI_COMMAND, pci_cmd);
|
||||
}
|
||||
|
||||
static bool resource_is_valid(struct pci_dev *pdev, int bar)
|
||||
{
|
||||
if (!pci_resource_flags(pdev, bar))
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
struct xe_device;
|
||||
struct xe_vram_region;
|
||||
|
||||
void xe_vram_resize_bar(struct xe_device *xe);
|
||||
int xe_vram_probe(struct xe_device *xe);
|
||||
|
||||
struct xe_vram_region *xe_vram_region_alloc(struct xe_device *xe, u8 id, u32 placement);
|
||||
|
||||
Reference in New Issue
Block a user