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/kref.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>
|
2021-04-29 10:30:50 +00:00
|
|
|
#include <drm/i915_drm.h>
|
2019-10-08 16:01:14 +00:00
|
|
|
|
|
|
|
struct drm_i915_private;
|
|
|
|
struct drm_i915_gem_object;
|
|
|
|
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,
|
|
|
|
INTEL_REGION_LMEM,
|
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)
|
|
|
|
#define REGION_LMEM BIT(INTEL_REGION_LMEM)
|
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);
|
|
|
|
void (*release)(struct intel_memory_region *mem);
|
|
|
|
|
2021-01-14 18:24:02 +00:00
|
|
|
int (*init_object)(struct intel_memory_region *mem,
|
|
|
|
struct drm_i915_gem_object *obj,
|
|
|
|
resource_size_t size,
|
|
|
|
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;
|
|
|
|
|
2019-10-30 17:33:20 +00:00
|
|
|
/* For fake LMEM */
|
|
|
|
struct drm_mm_node fake_mappable;
|
|
|
|
|
2019-10-08 16:01:14 +00:00
|
|
|
struct kref kref;
|
|
|
|
|
|
|
|
resource_size_t io_start;
|
|
|
|
resource_size_t min_page_size;
|
2019-12-27 13:37:48 +00:00
|
|
|
resource_size_t total;
|
|
|
|
resource_size_t avail;
|
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
|
|
|
|
2019-10-30 17:33:20 +00:00
|
|
|
dma_addr_t remap_addr;
|
|
|
|
|
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,
|
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);
|
|
|
|
|
|
|
|
struct intel_memory_region *
|
|
|
|
intel_memory_region_get(struct intel_memory_region *mem);
|
|
|
|
void intel_memory_region_put(struct intel_memory_region *mem);
|
|
|
|
|
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);
|
2019-10-08 16:01:14 +00:00
|
|
|
#endif
|