blob: 36f8ba2f5c849941b665e24ce0fd6cfd4fb143eb [file] [log] [blame]
Rob Clarkc8afe682013-06-26 12:44:06 -04001/*
2 * Copyright (C) 2013 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __MSM_DRV_H__
19#define __MSM_DRV_H__
20
21#include <linux/kernel.h>
22#include <linux/clk.h>
23#include <linux/cpufreq.h>
24#include <linux/module.h>
25#include <linux/platform_device.h>
26#include <linux/pm.h>
27#include <linux/pm_runtime.h>
28#include <linux/slab.h>
29#include <linux/list.h>
30#include <linux/iommu.h>
31#include <linux/types.h>
32#include <asm/sizes.h>
33
34#ifndef CONFIG_OF
35#include <mach/board.h>
36#include <mach/socinfo.h>
37#include <mach/iommu_domains.h>
38#endif
39
40#include <drm/drmP.h>
41#include <drm/drm_crtc_helper.h>
42#include <drm/drm_fb_helper.h>
43
44struct msm_kms;
45
46#define NUM_DOMAINS 1 /* one for KMS, then one per gpu core (?) */
47
48struct msm_drm_private {
49
50 struct msm_kms *kms;
51
52 struct drm_fb_helper *fbdev;
53
54 /* list of GEM objects: */
55 struct list_head inactive_list;
56
57 struct workqueue_struct *wq;
58
59 /* registered IOMMU domains: */
60 unsigned int num_iommus;
61 struct iommu_domain *iommus[NUM_DOMAINS];
62
63 unsigned int num_crtcs;
64 struct drm_crtc *crtcs[8];
65
66 unsigned int num_encoders;
67 struct drm_encoder *encoders[8];
68
69 unsigned int num_connectors;
70 struct drm_connector *connectors[8];
71};
72
73struct msm_format {
74 uint32_t pixel_format;
75};
76
77/* As there are different display controller blocks depending on the
78 * snapdragon version, the kms support is split out and the appropriate
79 * implementation is loaded at runtime. The kms module is responsible
80 * for constructing the appropriate planes/crtcs/encoders/connectors.
81 */
82struct msm_kms_funcs {
83 /* hw initialization: */
84 int (*hw_init)(struct msm_kms *kms);
85 /* irq handling: */
86 void (*irq_preinstall)(struct msm_kms *kms);
87 int (*irq_postinstall)(struct msm_kms *kms);
88 void (*irq_uninstall)(struct msm_kms *kms);
89 irqreturn_t (*irq)(struct msm_kms *kms);
90 int (*enable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
91 void (*disable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
92 /* misc: */
93 const struct msm_format *(*get_format)(struct msm_kms *kms, uint32_t format);
94 long (*round_pixclk)(struct msm_kms *kms, unsigned long rate,
95 struct drm_encoder *encoder);
96 /* cleanup: */
97 void (*preclose)(struct msm_kms *kms, struct drm_file *file);
98 void (*destroy)(struct msm_kms *kms);
99};
100
101struct msm_kms {
102 const struct msm_kms_funcs *funcs;
103};
104
105struct msm_kms *mdp4_kms_init(struct drm_device *dev);
106
107int msm_register_iommu(struct drm_device *dev, struct iommu_domain *iommu);
108int msm_iommu_attach(struct drm_device *dev, struct iommu_domain *iommu,
109 const char **names, int cnt);
110
111int msm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
112int msm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
113uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj);
114int msm_gem_get_iova_locked(struct drm_gem_object *obj, int id,
115 uint32_t *iova);
116int msm_gem_get_iova(struct drm_gem_object *obj, int id, uint32_t *iova);
117void msm_gem_put_iova(struct drm_gem_object *obj, int id);
118int msm_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
119 struct drm_mode_create_dumb *args);
120int msm_gem_dumb_destroy(struct drm_file *file, struct drm_device *dev,
121 uint32_t handle);
122int msm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
123 uint32_t handle, uint64_t *offset);
124void *msm_gem_vaddr_locked(struct drm_gem_object *obj);
125void *msm_gem_vaddr(struct drm_gem_object *obj);
126int msm_gem_queue_inactive_work(struct drm_gem_object *obj,
127 struct work_struct *work);
128void msm_gem_free_object(struct drm_gem_object *obj);
129int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file,
130 uint32_t size, uint32_t flags, uint32_t *handle);
131struct drm_gem_object *msm_gem_new(struct drm_device *dev,
132 uint32_t size, uint32_t flags);
133
134struct drm_gem_object *msm_framebuffer_bo(struct drm_framebuffer *fb, int plane);
135const struct msm_format *msm_framebuffer_format(struct drm_framebuffer *fb);
136struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev,
137 struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos);
138struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev,
139 struct drm_file *file, struct drm_mode_fb_cmd2 *mode_cmd);
140
141struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev);
142
143struct drm_connector *hdmi_connector_init(struct drm_device *dev,
144 struct drm_encoder *encoder);
145void __init hdmi_register(void);
146void __exit hdmi_unregister(void);
147
148#ifdef CONFIG_DEBUG_FS
149void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m);
150void msm_gem_describe_objects(struct list_head *list, struct seq_file *m);
151void msm_framebuffer_describe(struct drm_framebuffer *fb, struct seq_file *m);
152#endif
153
154void __iomem *msm_ioremap(struct platform_device *pdev, const char *name,
155 const char *dbgname);
156void msm_writel(u32 data, void __iomem *addr);
157u32 msm_readl(const void __iomem *addr);
158
159#define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
160#define VERB(fmt, ...) if (0) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
161
162static inline int align_pitch(int width, int bpp)
163{
164 int bytespp = (bpp + 7) / 8;
165 /* adreno needs pitch aligned to 32 pixels: */
166 return bytespp * ALIGN(width, 32);
167}
168
169/* for the generated headers: */
170#define INVALID_IDX(idx) ({BUG(); 0;})
171
172#define FIELD(val, name) (((val) & name ## __MASK) >> name ## __SHIFT)
173
174/* for conditionally setting boolean flag(s): */
175#define COND(bool, val) ((bool) ? (val) : 0)
176
177/* just put these here until we start adding driver private ioctls: */
178// TODO might shuffle these around.. just need something for now..
179#define MSM_BO_CACHE_MASK 0x0000000f
180#define MSM_BO_SCANOUT 0x00010000 /* scanout capable */
181
182#define MSM_BO_CACHED 0x00000001 /* default */
183#define MSM_BO_WC 0x0000002
184#define MSM_BO_UNCACHED 0x00000004
185
186
187#endif /* __MSM_DRV_H__ */