2019-10-08 16:01:14 +00:00
|
|
|
/* 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>
|
2019-10-30 17:33:20 +00:00
|
|
|
#include <drm/drm_mm.h>
|
2022-03-11 10:06:39 +00:00
|
|
|
#include <uapi/drm/i915_drm.h>
|
2019-10-08 16:01:14 +00:00
|
|
|
|
|
|
|
struct drm_i915_private;
|
|
|
|
struct drm_i915_gem_object;
|
2021-08-19 09:34:19 +00:00
|
|
|
struct drm_printer;
|
2019-10-08 16:01:14 +00:00
|
|
|
struct intel_memory_region;
|
|
|
|
struct sg_table;
|
2021-06-11 03:34:42 +00:00
|
|
|
struct ttm_resource;
|
2019-10-08 16:01:14 +00:00
|
|
|
|
2019-10-18 09:07:50 +00:00
|
|
|
enum intel_memory_type {
|
2021-04-29 10:30:50 +00:00
|
|
|
INTEL_MEMORY_SYSTEM = I915_MEMORY_CLASS_SYSTEM,
|
|
|
|
INTEL_MEMORY_LOCAL = I915_MEMORY_CLASS_DEVICE,
|
2021-02-05 10:20:26 +00:00
|
|
|
INTEL_MEMORY_STOLEN_SYSTEM,
|
2021-04-21 10:46:55 +00:00
|
|
|
INTEL_MEMORY_STOLEN_LOCAL,
|
2021-06-02 08:38:08 +00:00
|
|
|
INTEL_MEMORY_MOCK,
|
2019-10-18 09:07:50 +00:00
|
|
|
};
|
|
|
|
|
2019-10-18 09:07:49 +00:00
|
|
|
enum intel_region_id {
|
2019-10-18 09:07:50 +00:00
|
|
|
INTEL_REGION_SMEM = 0,
|
2022-03-18 23:39:31 +00:00
|
|
|
INTEL_REGION_LMEM_0,
|
2022-03-18 23:39:33 +00:00
|
|
|
INTEL_REGION_LMEM_1,
|
|
|
|
INTEL_REGION_LMEM_2,
|
|
|
|
INTEL_REGION_LMEM_3,
|
2021-02-05 10:20:26 +00:00
|
|
|
INTEL_REGION_STOLEN_SMEM,
|
2021-04-21 10:46:55 +00:00
|
|
|
INTEL_REGION_STOLEN_LMEM,
|
2019-10-18 09:07:50 +00:00
|
|
|
INTEL_REGION_UNKNOWN, /* Should be last */
|
2019-10-18 09:07:49 +00:00
|
|
|
};
|
|
|
|
|
2019-10-18 09:07:50 +00:00
|
|
|
#define REGION_SMEM BIT(INTEL_REGION_SMEM)
|
2022-03-18 23:39:31 +00:00
|
|
|
#define REGION_LMEM BIT(INTEL_REGION_LMEM_0)
|
2021-02-05 10:20:26 +00:00
|
|
|
#define REGION_STOLEN_SMEM BIT(INTEL_REGION_STOLEN_SMEM)
|
2021-04-21 10:46:55 +00:00
|
|
|
#define REGION_STOLEN_LMEM BIT(INTEL_REGION_STOLEN_LMEM)
|
2019-10-18 09:07:50 +00:00
|
|
|
|
2021-06-16 15:25:01 +00:00
|
|
|
#define I915_ALLOC_CONTIGUOUS BIT(0)
|
2019-10-08 16:01:14 +00:00
|
|
|
|
2019-12-27 13:37:48 +00:00
|
|
|
#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])
|
|
|
|
|
2019-10-08 16:01:14 +00:00
|
|
|
struct intel_memory_region_ops {
|
|
|
|
unsigned int flags;
|
|
|
|
|
|
|
|
int (*init)(struct intel_memory_region *mem);
|
2021-11-22 21:45:51 +00:00
|
|
|
int (*release)(struct intel_memory_region *mem);
|
2019-10-08 16:01:14 +00:00
|
|
|
|
2021-01-14 18:24:02 +00:00
|
|
|
int (*init_object)(struct intel_memory_region *mem,
|
|
|
|
struct drm_i915_gem_object *obj,
|
2022-03-15 18:14:22 +00:00
|
|
|
resource_size_t offset,
|
2021-01-14 18:24:02 +00:00
|
|
|
resource_size_t size,
|
2021-06-25 10:38:23 +00:00
|
|
|
resource_size_t page_size,
|
2021-01-14 18:24:02 +00:00
|
|
|
unsigned int flags);
|
2019-10-08 16:01:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2022-02-25 14:54:56 +00:00
|
|
|
resource_size_t io_size;
|
2019-10-08 16:01:14 +00:00
|
|
|
resource_size_t min_page_size;
|
2019-12-27 13:37:48 +00:00
|
|
|
resource_size_t total;
|
2019-10-08 16:01:14 +00:00
|
|
|
|
2021-02-05 10:20:25 +00:00
|
|
|
u16 type;
|
|
|
|
u16 instance;
|
|
|
|
enum intel_region_id id;
|
2021-04-21 10:46:55 +00:00
|
|
|
char name[16];
|
2021-04-29 10:30:49 +00:00
|
|
|
bool private; /* not for userspace */
|
2019-10-08 16:01:16 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
struct mutex lock; /* Protects access to objects */
|
|
|
|
struct list_head list;
|
|
|
|
} objects;
|
2021-06-02 08:38:08 +00:00
|
|
|
|
|
|
|
bool is_range_manager;
|
|
|
|
|
|
|
|
void *region_private;
|
2019-10-08 16:01:14 +00:00
|
|
|
};
|
|
|
|
|
2021-04-29 10:30:53 +00:00
|
|
|
struct intel_memory_region *
|
|
|
|
intel_memory_region_lookup(struct drm_i915_private *i915,
|
|
|
|
u16 class, u16 instance);
|
|
|
|
|
2019-10-08 16:01:14 +00:00
|
|
|
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,
|
2022-02-25 14:54:56 +00:00
|
|
|
resource_size_t io_size,
|
2021-06-02 08:38:08 +00:00
|
|
|
u16 type,
|
|
|
|
u16 instance,
|
2019-10-08 16:01:14 +00:00
|
|
|
const struct intel_memory_region_ops *ops);
|
|
|
|
|
2021-11-22 21:45:51 +00:00
|
|
|
void intel_memory_region_destroy(struct intel_memory_region *mem);
|
2019-10-08 16:01:14 +00:00
|
|
|
|
2019-10-26 20:20:32 +00:00
|
|
|
int intel_memory_regions_hw_probe(struct drm_i915_private *i915);
|
|
|
|
void intel_memory_regions_driver_release(struct drm_i915_private *i915);
|
2020-01-04 19:10:42 +00:00
|
|
|
struct intel_memory_region *
|
|
|
|
intel_memory_region_by_type(struct drm_i915_private *i915,
|
|
|
|
enum intel_memory_type mem_type);
|
2019-10-26 20:20:32 +00:00
|
|
|
|
2019-12-27 13:37:48 +00:00
|
|
|
__printf(2, 3) void
|
|
|
|
intel_memory_region_set_name(struct intel_memory_region *mem,
|
|
|
|
const char *fmt, ...);
|
|
|
|
|
2021-06-02 08:38:08 +00:00
|
|
|
int intel_memory_region_reserve(struct intel_memory_region *mem,
|
|
|
|
resource_size_t offset,
|
|
|
|
resource_size_t size);
|
2021-06-24 08:42:40 +00:00
|
|
|
|
2021-08-19 09:34:19 +00:00
|
|
|
void intel_memory_region_debug(struct intel_memory_region *mr,
|
|
|
|
struct drm_printer *printer);
|
|
|
|
|
2022-06-29 17:43:40 +00:00
|
|
|
void intel_memory_region_avail(struct intel_memory_region *mr,
|
|
|
|
u64 *avail, u64 *visible_avail);
|
|
|
|
|
2021-06-24 08:42:40 +00:00
|
|
|
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);
|
|
|
|
|
2019-10-08 16:01:14 +00:00
|
|
|
#endif
|