1 /* SPDX-License-Identifier: MIT */
3 * Copyright © 2019 Intel Corporation
6 #ifndef __INTEL_MEMORY_REGION_H__
7 #define __INTEL_MEMORY_REGION_H__
9 #include <linux/kref.h>
10 #include <linux/ioport.h>
11 #include <linux/mutex.h>
12 #include <linux/io-mapping.h>
13 #include <drm/drm_mm.h>
15 #include "i915_buddy.h"
17 struct drm_i915_private
;
18 struct drm_i915_gem_object
;
19 struct intel_memory_region
;
25 enum intel_memory_type
{
26 INTEL_MEMORY_SYSTEM
= 0,
31 enum intel_region_id
{
32 INTEL_REGION_SMEM
= 0,
35 INTEL_REGION_UNKNOWN
, /* Should be last */
38 #define REGION_SMEM BIT(INTEL_REGION_SMEM)
39 #define REGION_LMEM BIT(INTEL_REGION_LMEM)
40 #define REGION_STOLEN BIT(INTEL_REGION_STOLEN)
42 #define INTEL_MEMORY_TYPE_SHIFT 16
44 #define MEMORY_TYPE_FROM_REGION(r) (ilog2((r) >> INTEL_MEMORY_TYPE_SHIFT))
45 #define MEMORY_INSTANCE_FROM_REGION(r) (ilog2((r) & 0xffff))
47 #define I915_ALLOC_MIN_PAGE_SIZE BIT(0)
48 #define I915_ALLOC_CONTIGUOUS BIT(1)
50 #define for_each_memory_region(mr, i915, id) \
51 for (id = 0; id < ARRAY_SIZE((i915)->mm.regions); id++) \
52 for_each_if((mr) = (i915)->mm.regions[id])
55 * Memory regions encoded as type | instance
57 extern const u32 intel_region_map
[];
59 struct intel_memory_region_ops
{
62 int (*init
)(struct intel_memory_region
*mem
);
63 void (*release
)(struct intel_memory_region
*mem
);
65 struct drm_i915_gem_object
*
66 (*create_object
)(struct intel_memory_region
*mem
,
71 struct intel_memory_region
{
72 struct drm_i915_private
*i915
;
74 const struct intel_memory_region_ops
*ops
;
76 struct io_mapping iomap
;
77 struct resource region
;
80 struct drm_mm_node fake_mappable
;
82 struct i915_buddy_mm mm
;
87 resource_size_t io_start
;
88 resource_size_t min_page_size
;
89 resource_size_t total
;
90 resource_size_t avail
;
93 unsigned int instance
;
97 dma_addr_t remap_addr
;
100 struct mutex lock
; /* Protects access to objects */
101 struct list_head list
;
102 struct list_head purgeable
;
106 int intel_memory_region_init_buddy(struct intel_memory_region
*mem
);
107 void intel_memory_region_release_buddy(struct intel_memory_region
*mem
);
109 int __intel_memory_region_get_pages_buddy(struct intel_memory_region
*mem
,
110 resource_size_t size
,
112 struct list_head
*blocks
);
113 struct i915_buddy_block
*
114 __intel_memory_region_get_block_buddy(struct intel_memory_region
*mem
,
115 resource_size_t size
,
117 void __intel_memory_region_put_pages_buddy(struct intel_memory_region
*mem
,
118 struct list_head
*blocks
);
119 void __intel_memory_region_put_block_buddy(struct i915_buddy_block
*block
);
121 struct intel_memory_region
*
122 intel_memory_region_create(struct drm_i915_private
*i915
,
123 resource_size_t start
,
124 resource_size_t size
,
125 resource_size_t min_page_size
,
126 resource_size_t io_start
,
127 const struct intel_memory_region_ops
*ops
);
129 struct intel_memory_region
*
130 intel_memory_region_get(struct intel_memory_region
*mem
);
131 void intel_memory_region_put(struct intel_memory_region
*mem
);
133 int intel_memory_regions_hw_probe(struct drm_i915_private
*i915
);
134 void intel_memory_regions_driver_release(struct drm_i915_private
*i915
);
135 struct intel_memory_region
*
136 intel_memory_region_by_type(struct drm_i915_private
*i915
,
137 enum intel_memory_type mem_type
);
140 intel_memory_region_set_name(struct intel_memory_region
*mem
,
141 const char *fmt
, ...);