Skip to content

Commit 382876a

Browse files
Lucas De Marchimattrope
authored andcommitted
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>
1 parent ac1317d commit 382876a

6 files changed

Lines changed: 124 additions & 93 deletions

File tree

drivers/gpu/drm/xe/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ xe-y += xe_bb.o \
9898
xe_page_reclaim.o \
9999
xe_pat.o \
100100
xe_pci.o \
101+
xe_pci_rebar.o \
101102
xe_pcode.o \
102103
xe_pm.o \
103104
xe_preempt_fence.o \

drivers/gpu/drm/xe/xe_pci.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "xe_macros.h"
2828
#include "xe_mmio.h"
2929
#include "xe_module.h"
30+
#include "xe_pci_rebar.h"
3031
#include "xe_pci_sriov.h"
3132
#include "xe_pci_types.h"
3233
#include "xe_pm.h"
@@ -1021,7 +1022,7 @@ static int xe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
10211022
if (err)
10221023
return err;
10231024

1024-
xe_vram_resize_bar(xe);
1025+
xe_pci_rebar_resize(xe);
10251026

10261027
err = xe_device_probe_early(xe);
10271028
/*

drivers/gpu/drm/xe/xe_pci_rebar.c

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
}

drivers/gpu/drm/xe/xe_pci_rebar.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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

drivers/gpu/drm/xe/xe_vram.c

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -25,97 +25,6 @@
2525
#include "xe_vram.h"
2626
#include "xe_vram_types.h"
2727

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-
11928
static bool resource_is_valid(struct pci_dev *pdev, int bar)
12029
{
12130
if (!pci_resource_flags(pdev, bar))

drivers/gpu/drm/xe/xe_vram.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
struct xe_device;
1212
struct xe_vram_region;
1313

14-
void xe_vram_resize_bar(struct xe_device *xe);
1514
int xe_vram_probe(struct xe_device *xe);
1615

1716
struct xe_vram_region *xe_vram_region_alloc(struct xe_device *xe, u8 id, u32 placement);

0 commit comments

Comments
 (0)