Skip to content

Commit 8ec8ad0

Browse files
matt-aulddanvet
authored andcommitted
drm/i915: cleanup the region class/instance encoding
Get rid of the strange REGION_MAP encoding stuff and just use an explicit class/instance pair for each region. This better matches our future uAPI where all queryable regions are identified with a u16 class and u16 instance. v2: fix whitespace Signed-off-by: Matthew Auld <[email protected]> Reviewed-by: Chris Wilson <[email protected]> Signed-off-by: Chris Wilson <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Daniel Vetter <[email protected]>
1 parent 2827ce6 commit 8ec8ad0

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

drivers/gpu/drm/i915/intel_memory_region.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,22 @@
66
#include "intel_memory_region.h"
77
#include "i915_drv.h"
88

9-
/* XXX: Hysterical raisins. BIT(inst) needs to just be (inst) at some point. */
10-
#define REGION_MAP(type, inst) \
11-
BIT((type) + INTEL_MEMORY_TYPE_SHIFT) | BIT(inst)
12-
13-
static const u32 intel_region_map[] = {
14-
[INTEL_REGION_SMEM] = REGION_MAP(INTEL_MEMORY_SYSTEM, 0),
15-
[INTEL_REGION_LMEM] = REGION_MAP(INTEL_MEMORY_LOCAL, 0),
16-
[INTEL_REGION_STOLEN] = REGION_MAP(INTEL_MEMORY_STOLEN, 0),
9+
static const struct {
10+
u16 class;
11+
u16 instance;
12+
} intel_region_map[] = {
13+
[INTEL_REGION_SMEM] = {
14+
.class = INTEL_MEMORY_SYSTEM,
15+
.instance = 0,
16+
},
17+
[INTEL_REGION_LMEM] = {
18+
.class = INTEL_MEMORY_LOCAL,
19+
.instance = 0,
20+
},
21+
[INTEL_REGION_STOLEN] = {
22+
.class = INTEL_MEMORY_STOLEN,
23+
.instance = 0,
24+
},
1725
};
1826

1927
struct intel_memory_region *
@@ -259,12 +267,13 @@ int intel_memory_regions_hw_probe(struct drm_i915_private *i915)
259267

260268
for (i = 0; i < ARRAY_SIZE(i915->mm.regions); i++) {
261269
struct intel_memory_region *mem = ERR_PTR(-ENODEV);
262-
u32 type;
270+
u16 type, instance;
263271

264272
if (!HAS_REGION(i915, BIT(i)))
265273
continue;
266274

267-
type = MEMORY_TYPE_FROM_REGION(intel_region_map[i]);
275+
type = intel_region_map[i].class;
276+
instance = intel_region_map[i].instance;
268277
switch (type) {
269278
case INTEL_MEMORY_SYSTEM:
270279
mem = i915_gem_shmem_setup(i915);
@@ -284,9 +293,9 @@ int intel_memory_regions_hw_probe(struct drm_i915_private *i915)
284293
goto out_cleanup;
285294
}
286295

287-
mem->id = intel_region_map[i];
296+
mem->id = i;
288297
mem->type = type;
289-
mem->instance = MEMORY_INSTANCE_FROM_REGION(intel_region_map[i]);
298+
mem->instance = instance;
290299

291300
i915->mm.regions[i] = mem;
292301
}

drivers/gpu/drm/i915/intel_memory_region.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ enum intel_region_id {
3939
#define REGION_LMEM BIT(INTEL_REGION_LMEM)
4040
#define REGION_STOLEN BIT(INTEL_REGION_STOLEN)
4141

42-
#define INTEL_MEMORY_TYPE_SHIFT 16
43-
44-
#define MEMORY_TYPE_FROM_REGION(r) (ilog2((r) >> INTEL_MEMORY_TYPE_SHIFT))
45-
#define MEMORY_INSTANCE_FROM_REGION(r) (ilog2((r) & 0xffff))
46-
4742
#define I915_ALLOC_MIN_PAGE_SIZE BIT(0)
4843
#define I915_ALLOC_CONTIGUOUS BIT(1)
4944

@@ -84,9 +79,9 @@ struct intel_memory_region {
8479
resource_size_t total;
8580
resource_size_t avail;
8681

87-
unsigned int type;
88-
unsigned int instance;
89-
unsigned int id;
82+
u16 type;
83+
u16 instance;
84+
enum intel_region_id id;
9085
char name[8];
9186

9287
struct list_head reserved;

0 commit comments

Comments
 (0)