intel_memory_region.h 3.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/* SPDX-License-Identifier: MIT */
/*
 * Copyright © 2019 Intel Corporation
 */

#ifndef __INTEL_MEMORY_REGION_H__
#define __INTEL_MEMORY_REGION_H__

#include <linux/ioport.h>
#include <linux/mutex.h>
#include <linux/io-mapping.h>
12
#include <drm/drm_mm.h>
13
#include <uapi/drm/i915_drm.h>
14 15 16

struct drm_i915_private;
struct drm_i915_gem_object;
17
struct drm_printer;
18 19
struct intel_memory_region;
struct sg_table;
20
struct ttm_resource;
21

M
Matthew Auld 已提交
22
enum intel_memory_type {
23 24
	INTEL_MEMORY_SYSTEM = I915_MEMORY_CLASS_SYSTEM,
	INTEL_MEMORY_LOCAL = I915_MEMORY_CLASS_DEVICE,
25
	INTEL_MEMORY_STOLEN_SYSTEM,
26
	INTEL_MEMORY_STOLEN_LOCAL,
27
	INTEL_MEMORY_MOCK,
M
Matthew Auld 已提交
28 29
};

30
enum intel_region_id {
M
Matthew Auld 已提交
31
	INTEL_REGION_SMEM = 0,
32
	INTEL_REGION_LMEM_0,
33 34 35
	INTEL_REGION_LMEM_1,
	INTEL_REGION_LMEM_2,
	INTEL_REGION_LMEM_3,
36
	INTEL_REGION_STOLEN_SMEM,
37
	INTEL_REGION_STOLEN_LMEM,
M
Matthew Auld 已提交
38
	INTEL_REGION_UNKNOWN, /* Should be last */
39 40
};

M
Matthew Auld 已提交
41
#define REGION_SMEM     BIT(INTEL_REGION_SMEM)
42
#define REGION_LMEM     BIT(INTEL_REGION_LMEM_0)
43
#define REGION_STOLEN_SMEM   BIT(INTEL_REGION_STOLEN_SMEM)
44
#define REGION_STOLEN_LMEM   BIT(INTEL_REGION_STOLEN_LMEM)
M
Matthew Auld 已提交
45

46
#define I915_ALLOC_CONTIGUOUS     BIT(0)
47

48 49 50 51
#define for_each_memory_region(mr, i915, id) \
	for (id = 0; id < ARRAY_SIZE((i915)->mm.regions); id++) \
		for_each_if((mr) = (i915)->mm.regions[id])

52 53 54 55
struct intel_memory_region_ops {
	unsigned int flags;

	int (*init)(struct intel_memory_region *mem);
56
	int (*release)(struct intel_memory_region *mem);
57

58 59
	int (*init_object)(struct intel_memory_region *mem,
			   struct drm_i915_gem_object *obj,
60
			   resource_size_t offset,
61
			   resource_size_t size,
62
			   resource_size_t page_size,
63
			   unsigned int flags);
64 65 66 67 68 69 70 71 72 73 74
};

struct intel_memory_region {
	struct drm_i915_private *i915;

	const struct intel_memory_region_ops *ops;

	struct io_mapping iomap;
	struct resource region;

	resource_size_t io_start;
M
Matthew Auld 已提交
75
	resource_size_t io_size;
76
	resource_size_t min_page_size;
77 78
	resource_size_t total;
	resource_size_t avail;
79

80 81 82
	u16 type;
	u16 instance;
	enum intel_region_id id;
83
	char name[16];
M
Matthew Auld 已提交
84
	bool private; /* not for userspace */
85 86 87 88 89

	struct {
		struct mutex lock; /* Protects access to objects */
		struct list_head list;
	} objects;
90 91 92 93

	bool is_range_manager;

	void *region_private;
94 95
};

96 97 98 99
struct intel_memory_region *
intel_memory_region_lookup(struct drm_i915_private *i915,
			   u16 class, u16 instance);

100 101 102 103 104 105
struct intel_memory_region *
intel_memory_region_create(struct drm_i915_private *i915,
			   resource_size_t start,
			   resource_size_t size,
			   resource_size_t min_page_size,
			   resource_size_t io_start,
M
Matthew Auld 已提交
106
			   resource_size_t io_size,
107 108
			   u16 type,
			   u16 instance,
109 110
			   const struct intel_memory_region_ops *ops);

111
void intel_memory_region_destroy(struct intel_memory_region *mem);
112

113 114
int intel_memory_regions_hw_probe(struct drm_i915_private *i915);
void intel_memory_regions_driver_release(struct drm_i915_private *i915);
115 116 117
struct intel_memory_region *
intel_memory_region_by_type(struct drm_i915_private *i915,
			    enum intel_memory_type mem_type);
118

119 120 121 122
__printf(2, 3) void
intel_memory_region_set_name(struct intel_memory_region *mem,
			     const char *fmt, ...);

123 124 125
int intel_memory_region_reserve(struct intel_memory_region *mem,
				resource_size_t offset,
				resource_size_t size);
126

127 128 129
void intel_memory_region_debug(struct intel_memory_region *mr,
			       struct drm_printer *printer);

130 131 132
void intel_memory_region_avail(struct intel_memory_region *mr,
			       u64 *avail, u64 *visible_avail);

133 134 135 136 137 138 139
struct intel_memory_region *
i915_gem_ttm_system_setup(struct drm_i915_private *i915,
			  u16 type, u16 instance);
struct intel_memory_region *
i915_gem_shmem_setup(struct drm_i915_private *i915,
		     u16 type, u16 instance);

140
#endif