18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/**************************************************************************
38c2ecf20Sopenharmony_ci * Copyright (c) 2007-2008, Intel Corporation.
48c2ecf20Sopenharmony_ci * All Rights Reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci **************************************************************************/
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _PSB_GTT_H_
98c2ecf20Sopenharmony_ci#define _PSB_GTT_H_
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <drm/drm_gem.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* This wants cleaning up with respect to the psb_dev and un-needed stuff */
148c2ecf20Sopenharmony_cistruct psb_gtt {
158c2ecf20Sopenharmony_ci	uint32_t gatt_start;
168c2ecf20Sopenharmony_ci	uint32_t mmu_gatt_start;
178c2ecf20Sopenharmony_ci	uint32_t gtt_start;
188c2ecf20Sopenharmony_ci	uint32_t gtt_phys_start;
198c2ecf20Sopenharmony_ci	unsigned gtt_pages;
208c2ecf20Sopenharmony_ci	unsigned gatt_pages;
218c2ecf20Sopenharmony_ci	unsigned long stolen_size;
228c2ecf20Sopenharmony_ci	unsigned long vram_stolen_size;
238c2ecf20Sopenharmony_ci	struct rw_semaphore sem;
248c2ecf20Sopenharmony_ci};
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/* Exported functions */
278c2ecf20Sopenharmony_ciextern int psb_gtt_init(struct drm_device *dev, int resume);
288c2ecf20Sopenharmony_ciextern void psb_gtt_takedown(struct drm_device *dev);
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* Each gtt_range describes an allocation in the GTT area */
318c2ecf20Sopenharmony_cistruct gtt_range {
328c2ecf20Sopenharmony_ci	struct resource resource;	/* Resource for our allocation */
338c2ecf20Sopenharmony_ci	u32 offset;			/* GTT offset of our object */
348c2ecf20Sopenharmony_ci	struct drm_gem_object gem;	/* GEM high level stuff */
358c2ecf20Sopenharmony_ci	int in_gart;			/* Currently in the GART (ref ct) */
368c2ecf20Sopenharmony_ci	bool stolen;			/* Backed from stolen RAM */
378c2ecf20Sopenharmony_ci	bool mmapping;			/* Is mmappable */
388c2ecf20Sopenharmony_ci	struct page **pages;		/* Backing pages if present */
398c2ecf20Sopenharmony_ci	int npage;			/* Number of backing pages */
408c2ecf20Sopenharmony_ci	int roll;			/* Roll applied to the GTT entries */
418c2ecf20Sopenharmony_ci};
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define to_gtt_range(x) container_of(x, struct gtt_range, gem)
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ciextern struct gtt_range *psb_gtt_alloc_range(struct drm_device *dev, int len,
468c2ecf20Sopenharmony_ci					     const char *name, int backed,
478c2ecf20Sopenharmony_ci					     u32 align);
488c2ecf20Sopenharmony_ciextern void psb_gtt_kref_put(struct gtt_range *gt);
498c2ecf20Sopenharmony_ciextern void psb_gtt_free_range(struct drm_device *dev, struct gtt_range *gt);
508c2ecf20Sopenharmony_ciextern int psb_gtt_pin(struct gtt_range *gt);
518c2ecf20Sopenharmony_ciextern void psb_gtt_unpin(struct gtt_range *gt);
528c2ecf20Sopenharmony_ciextern void psb_gtt_roll(struct drm_device *dev,
538c2ecf20Sopenharmony_ci					struct gtt_range *gt, int roll);
548c2ecf20Sopenharmony_ciextern int psb_gtt_restore(struct drm_device *dev);
558c2ecf20Sopenharmony_ci#endif
56