panfrost_device.h 2.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright 2018 Marty E. Plummer <hanetzer@startmail.com> */
/* Copyright 2019 Linaro, Ltd, Rob Herring <robh@kernel.org> */

#ifndef __PANFROST_DEVICE_H__
#define __PANFROST_DEVICE_H__

#include <linux/spinlock.h>
#include <drm/drm_device.h>
#include <drm/drm_mm.h>
#include <drm/gpu_scheduler.h>

struct panfrost_device;
struct panfrost_mmu;
struct panfrost_job_slot;
struct panfrost_job;
17
struct panfrost_perfcnt;
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

#define NUM_JOB_SLOTS 3

struct panfrost_features {
	u16 id;
	u16 revision;

	u64 shader_present;
	u64 tiler_present;
	u64 l2_present;
	u64 stack_present;
	u32 as_present;
	u32 js_present;

	u32 l2_features;
	u32 core_features;
	u32 tiler_features;
	u32 mem_features;
	u32 mmu_features;
	u32 thread_features;
	u32 max_threads;
	u32 thread_max_workgroup_sz;
	u32 thread_max_barrier_sz;
	u32 coherency_features;
	u32 texture_features[4];
	u32 js_features[16];

	u32 nr_core_groups;
46
	u32 thread_tls_alloc;
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

	unsigned long hw_features[64 / BITS_PER_LONG];
	unsigned long hw_issues[64 / BITS_PER_LONG];
};

struct panfrost_devfreq_slot {
	ktime_t busy_time;
	ktime_t idle_time;
	ktime_t time_last_update;
	bool busy;
};

struct panfrost_device {
	struct device *dev;
	struct drm_device *ddev;
	struct platform_device *pdev;

	spinlock_t hwaccess_lock;

	struct drm_mm mm;
	spinlock_t mm_lock;

	void __iomem *iomem;
	struct clk *clock;
71
	struct clk *bus_clock;
72 73 74 75 76 77 78 79 80 81 82
	struct regulator *regulator;
	struct reset_control *rstc;

	struct panfrost_features features;

	struct panfrost_mmu *mmu;
	struct panfrost_job_slot *js;

	struct panfrost_job *jobs[NUM_JOB_SLOTS];
	struct list_head scheduled_jobs;

83 84
	struct panfrost_perfcnt *perfcnt;

85
	struct mutex sched_lock;
86
	struct mutex reset_lock;
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

	struct {
		struct devfreq *devfreq;
		struct thermal_cooling_device *cooling;
		unsigned long cur_freq;
		unsigned long cur_volt;
		struct panfrost_devfreq_slot slot[NUM_JOB_SLOTS];
	} devfreq;
};

struct panfrost_file_priv {
	struct panfrost_device *pfdev;

	struct drm_sched_entity sched_entity[NUM_JOB_SLOTS];
};

static inline struct panfrost_device *to_panfrost_device(struct drm_device *ddev)
{
	return ddev->dev_private;
}

static inline int panfrost_model_cmp(struct panfrost_device *pfdev, s32 id)
{
	s32 match_id = pfdev->features.id;

	if (match_id & 0xf000)
		match_id &= 0xf00f;
	return match_id - id;
}

117 118 119 120 121
static inline bool panfrost_model_is_bifrost(struct panfrost_device *pfdev)
{
	return panfrost_model_cmp(pfdev, 0x1000) >= 0;
}

122 123 124 125 126
static inline bool panfrost_model_eq(struct panfrost_device *pfdev, s32 id)
{
	return !panfrost_model_cmp(pfdev, id);
}

127 128
int panfrost_unstable_ioctl_check(void);

129 130 131 132 133 134 135 136 137
int panfrost_device_init(struct panfrost_device *pfdev);
void panfrost_device_fini(struct panfrost_device *pfdev);

int panfrost_device_resume(struct device *dev);
int panfrost_device_suspend(struct device *dev);

const char *panfrost_exception_name(struct panfrost_device *pfdev, u32 exception_code);

#endif