73 lines · c
1/* SPDX-License-Identifier: MIT */2/*3 * Copyright © 2021 Intel Corporation4 */5 6#ifndef __I915_TTM_BUDDY_MANAGER_H__7#define __I915_TTM_BUDDY_MANAGER_H__8 9#include <linux/list.h>10#include <linux/types.h>11 12#include <drm/ttm/ttm_resource.h>13 14struct ttm_device;15struct ttm_resource_manager;16struct drm_buddy;17 18/**19 * struct i915_ttm_buddy_resource20 *21 * @base: struct ttm_resource base class we extend22 * @blocks: the list of struct i915_buddy_block for this resource/allocation23 * @flags: DRM_BUDDY_*_ALLOCATION flags24 * @used_visible_size: How much of this resource, if any, uses the CPU visible25 * portion, in pages.26 * @mm: the struct i915_buddy_mm for this resource27 *28 * Extends the struct ttm_resource to manage an address space allocation with29 * one or more struct i915_buddy_block.30 */31struct i915_ttm_buddy_resource {32 struct ttm_resource base;33 struct list_head blocks;34 unsigned long flags;35 unsigned long used_visible_size;36 struct drm_buddy *mm;37};38 39/**40 * to_ttm_buddy_resource41 *42 * @res: the resource to upcast43 *44 * Upcast the struct ttm_resource object into a struct i915_ttm_buddy_resource.45 */46static inline struct i915_ttm_buddy_resource *47to_ttm_buddy_resource(struct ttm_resource *res)48{49 return container_of(res, struct i915_ttm_buddy_resource, base);50}51 52int i915_ttm_buddy_man_init(struct ttm_device *bdev,53 unsigned type, bool use_tt,54 u64 size, u64 visible_size,55 u64 default_page_size, u64 chunk_size);56int i915_ttm_buddy_man_fini(struct ttm_device *bdev,57 unsigned int type);58 59int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,60 u64 start, u64 size);61 62u64 i915_ttm_buddy_man_visible_size(struct ttm_resource_manager *man);63 64void i915_ttm_buddy_man_avail(struct ttm_resource_manager *man,65 u64 *avail, u64 *avail_visible);66 67#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)68void i915_ttm_buddy_man_force_visible_size(struct ttm_resource_manager *man,69 u64 size);70#endif71 72#endif73