1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 3 #ifndef DRM_SYSFB_HELPER_H 4 #define DRM_SYSFB_HELPER_H 5 6 #include <linux/container_of.h> 7 #include <linux/iosys-map.h> 8 9 #include <video/pixel_format.h> 10 11 #include <drm/drm_crtc.h> 12 #include <drm/drm_device.h> 13 #include <drm/drm_modes.h> 14 15 struct drm_format_info; 16 struct drm_scanout_buffer; 17 struct screen_info; 18 19 /* 20 * Input parsing 21 */ 22 23 struct drm_sysfb_format { 24 struct pixel_format pixel; 25 u32 fourcc; 26 }; 27 28 int drm_sysfb_get_validated_int(struct drm_device *dev, const char *name, 29 u64 value, u32 max); 30 int drm_sysfb_get_validated_int0(struct drm_device *dev, const char *name, 31 u64 value, u32 max); 32 33 #if defined(CONFIG_SCREEN_INFO) 34 int drm_sysfb_get_width_si(struct drm_device *dev, const struct screen_info *si); 35 int drm_sysfb_get_height_si(struct drm_device *dev, const struct screen_info *si); 36 struct resource *drm_sysfb_get_memory_si(struct drm_device *dev, 37 const struct screen_info *si, 38 struct resource *res); 39 int drm_sysfb_get_stride_si(struct drm_device *dev, const struct screen_info *si, 40 const struct drm_format_info *format, 41 unsigned int width, unsigned int height, u64 size); 42 u64 drm_sysfb_get_visible_size_si(struct drm_device *dev, const struct screen_info *si, 43 unsigned int height, unsigned int stride, u64 size); 44 const struct drm_format_info *drm_sysfb_get_format_si(struct drm_device *dev, 45 const struct drm_sysfb_format *formats, 46 size_t nformats, 47 const struct screen_info *si); 48 #endif 49 50 /* 51 * Input parsing 52 */ 53 54 int drm_sysfb_get_validated_int(struct drm_device *dev, const char *name, 55 u64 value, u32 max); 56 int drm_sysfb_get_validated_int0(struct drm_device *dev, const char *name, 57 u64 value, u32 max); 58 59 /* 60 * Display modes 61 */ 62 63 struct drm_display_mode drm_sysfb_mode(unsigned int width, 64 unsigned int height, 65 unsigned int width_mm, 66 unsigned int height_mm); 67 68 /* 69 * Device 70 */ 71 72 struct drm_sysfb_device { 73 struct drm_device dev; 74 75 const u8 *edid; /* can be NULL */ 76 77 /* hardware settings */ 78 struct drm_display_mode fb_mode; 79 const struct drm_format_info *fb_format; 80 unsigned int fb_pitch; 81 unsigned int fb_gamma_lut_size; 82 83 /* hardware-framebuffer kernel address */ 84 struct iosys_map fb_addr; 85 }; 86 87 static inline struct drm_sysfb_device *to_drm_sysfb_device(struct drm_device *dev) 88 { 89 return container_of(dev, struct drm_sysfb_device, dev); 90 } 91 92 /* 93 * Plane 94 */ 95 96 size_t drm_sysfb_build_fourcc_list(struct drm_device *dev, 97 const u32 *native_fourccs, size_t native_nfourccs, 98 u32 *fourccs_out, size_t nfourccs_out); 99 100 int drm_sysfb_plane_helper_atomic_check(struct drm_plane *plane, 101 struct drm_atomic_state *new_state); 102 void drm_sysfb_plane_helper_atomic_update(struct drm_plane *plane, 103 struct drm_atomic_state *state); 104 void drm_sysfb_plane_helper_atomic_disable(struct drm_plane *plane, 105 struct drm_atomic_state *state); 106 int drm_sysfb_plane_helper_get_scanout_buffer(struct drm_plane *plane, 107 struct drm_scanout_buffer *sb); 108 109 #define DRM_SYSFB_PLANE_NFORMATS(_num_native) \ 110 ((_num_native) + 1) 111 112 #define DRM_SYSFB_PLANE_FORMAT_MODIFIERS \ 113 DRM_FORMAT_MOD_LINEAR, \ 114 DRM_FORMAT_MOD_INVALID 115 116 #define DRM_SYSFB_PLANE_HELPER_FUNCS \ 117 DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, \ 118 .atomic_check = drm_sysfb_plane_helper_atomic_check, \ 119 .atomic_update = drm_sysfb_plane_helper_atomic_update, \ 120 .atomic_disable = drm_sysfb_plane_helper_atomic_disable, \ 121 .get_scanout_buffer = drm_sysfb_plane_helper_get_scanout_buffer 122 123 #define DRM_SYSFB_PLANE_FUNCS \ 124 .update_plane = drm_atomic_helper_update_plane, \ 125 .disable_plane = drm_atomic_helper_disable_plane, \ 126 DRM_GEM_SHADOW_PLANE_FUNCS 127 128 /* 129 * CRTC 130 */ 131 132 struct drm_sysfb_crtc_state { 133 struct drm_crtc_state base; 134 135 /* Primary-plane format; required for color mgmt. */ 136 const struct drm_format_info *format; 137 }; 138 139 static inline struct drm_sysfb_crtc_state * 140 to_drm_sysfb_crtc_state(struct drm_crtc_state *base) 141 { 142 return container_of(base, struct drm_sysfb_crtc_state, base); 143 } 144 145 enum drm_mode_status drm_sysfb_crtc_helper_mode_valid(struct drm_crtc *crtc, 146 const struct drm_display_mode *mode); 147 int drm_sysfb_crtc_helper_atomic_check(struct drm_crtc *crtc, struct drm_atomic_state *new_state); 148 149 #define DRM_SYSFB_CRTC_HELPER_FUNCS \ 150 .mode_valid = drm_sysfb_crtc_helper_mode_valid, \ 151 .atomic_check = drm_sysfb_crtc_helper_atomic_check 152 153 void drm_sysfb_crtc_reset(struct drm_crtc *crtc); 154 struct drm_crtc_state *drm_sysfb_crtc_atomic_duplicate_state(struct drm_crtc *crtc); 155 void drm_sysfb_crtc_atomic_destroy_state(struct drm_crtc *crtc, struct drm_crtc_state *crtc_state); 156 157 #define DRM_SYSFB_CRTC_FUNCS \ 158 .reset = drm_sysfb_crtc_reset, \ 159 .set_config = drm_atomic_helper_set_config, \ 160 .page_flip = drm_atomic_helper_page_flip, \ 161 .atomic_duplicate_state = drm_sysfb_crtc_atomic_duplicate_state, \ 162 .atomic_destroy_state = drm_sysfb_crtc_atomic_destroy_state 163 164 /* 165 * Connector 166 */ 167 168 int drm_sysfb_connector_helper_get_modes(struct drm_connector *connector); 169 170 #define DRM_SYSFB_CONNECTOR_HELPER_FUNCS \ 171 .get_modes = drm_sysfb_connector_helper_get_modes 172 173 #define DRM_SYSFB_CONNECTOR_FUNCS \ 174 .reset = drm_atomic_helper_connector_reset, \ 175 .fill_modes = drm_helper_probe_single_connector_modes, \ 176 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, \ 177 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state 178 179 /* 180 * Mode config 181 */ 182 183 #define DRM_SYSFB_MODE_CONFIG_FUNCS \ 184 .fb_create = drm_gem_fb_create_with_dirty, \ 185 .atomic_check = drm_atomic_helper_check, \ 186 .atomic_commit = drm_atomic_helper_commit 187 188 #endif 189