Home | History | Annotate | Download | only in drm

Lines Matching refs:state

67  * @state: atomic state
73 void drm_atomic_state_default_release(struct drm_atomic_state *state)
75 kfree(state->connectors);
76 kfree(state->crtcs);
77 kfree(state->planes);
78 kfree(state->private_objs);
83 * drm_atomic_state_init - init new atomic state
85 * @state: atomic state
87 * Default implementation for filling in a new atomic state.
92 drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state)
94 kref_init(&state->ref);
99 state->allow_modeset = true;
101 state->crtcs = kcalloc(dev->mode_config.num_crtc,
102 sizeof(*state->crtcs), GFP_KERNEL);
103 if (!state->crtcs)
105 state->planes = kcalloc(dev->mode_config.num_total_plane,
106 sizeof(*state->planes), GFP_KERNEL);
107 if (!state->planes)
110 state->dev = dev;
112 DRM_DEBUG_ATOMIC("Allocated atomic state %p\n", state);
116 drm_atomic_state_default_release(state);
122 * drm_atomic_state_alloc - allocate atomic state
125 * This allocates an empty atomic state to track updates.
133 struct drm_atomic_state *state;
135 state = kzalloc(sizeof(*state), GFP_KERNEL);
136 if (!state)
138 if (drm_atomic_state_init(dev, state) < 0) {
139 kfree(state);
142 return state;
150 * drm_atomic_state_default_clear - clear base atomic state
151 * @state: atomic state
153 * Default implementation for clearing atomic state.
157 void drm_atomic_state_default_clear(struct drm_atomic_state *state)
159 struct drm_device *dev = state->dev;
163 DRM_DEBUG_ATOMIC("Clearing atomic state %p\n", state);
165 for (i = 0; i < state->num_connector; i++) {
166 struct drm_connector *connector = state->connectors[i].ptr;
172 state->connectors[i].state);
173 state->connectors[i].ptr = NULL;
174 state->connectors[i].state = NULL;
175 state->connectors[i].old_state = NULL;
176 state->connectors[i].new_state = NULL;
181 struct drm_crtc *crtc = state->crtcs[i].ptr;
187 state->crtcs[i].state);
189 state->crtcs[i].ptr = NULL;
190 state->crtcs[i].state = NULL;
191 state->crtcs[i].old_state = NULL;
192 state->crtcs[i].new_state = NULL;
194 if (state->crtcs[i].commit) {
195 drm_crtc_commit_put(state->crtcs[i].commit);
196 state->crtcs[i].commit = NULL;
201 struct drm_plane *plane = state->planes[i].ptr;
207 state->planes[i].state);
208 state->planes[i].ptr = NULL;
209 state->planes[i].state = NULL;
210 state->planes[i].old_state = NULL;
211 state->planes[i].new_state = NULL;
214 for (i = 0; i < state->num_private_objs; i++) {
215 struct drm_private_obj *obj = state->private_objs[i].ptr;
218 state->private_objs[i].state);
219 state->private_objs[i].ptr = NULL;
220 state->private_objs[i].state = NULL;
221 state->private_objs[i].old_state = NULL;
222 state->private_objs[i].new_state = NULL;
224 state->num_private_objs = 0;
226 if (state->fake_commit) {
227 drm_crtc_commit_put(state->fake_commit);
228 state->fake_commit = NULL;
234 * drm_atomic_state_clear - clear state object
235 * @state: atomic state
239 * configuration. Which means that all the state assembled in @state is no
240 * longer an atomic update to the current state, but to some arbitrary earlier
241 * state. Which could break assumptions the driver's
244 * Hence we must clear all cached state and completely start over, using this
247 void drm_atomic_state_clear(struct drm_atomic_state *state)
249 struct drm_device *dev = state->dev;
253 config->funcs->atomic_state_clear(state);
255 drm_atomic_state_default_clear(state);
260 * __drm_atomic_state_free - free all memory for an atomic state
261 * @ref: This atomic state to deallocate
263 * This frees all memory associated with an atomic state, including all the
264 * per-object state for planes, CRTCs and connectors.
268 struct drm_atomic_state *state = container_of(ref, typeof(*state), ref);
269 struct drm_mode_config *config = &state->dev->mode_config;
271 drm_atomic_state_clear(state);
273 DRM_DEBUG_ATOMIC("Freeing atomic state %p\n", state);
276 config->funcs->atomic_state_free(state);
278 drm_atomic_state_default_release(state);
279 kfree(state);
285 * drm_atomic_get_crtc_state - get CRTC state
286 * @state: global atomic state object
287 * @crtc: CRTC to get state object for
289 * This function returns the CRTC state for the given CRTC, allocating it if
290 * needed. It will also grab the relevant CRTC lock to make sure that the state
295 * Either the allocated state or the error code encoded into the pointer. When
300 drm_atomic_get_crtc_state(struct drm_atomic_state *state,
306 WARN_ON(!state->acquire_ctx);
308 crtc_state = drm_atomic_get_existing_crtc_state(state, crtc);
312 ret = drm_modeset_lock(&crtc->mutex, state->acquire_ctx);
320 state->crtcs[index].state = crtc_state;
321 state->crtcs[index].old_state = crtc->state;
322 state->crtcs[index].new_state = crtc_state;
323 state->crtcs[index].ptr = crtc;
324 crtc_state->state = state;
326 DRM_DEBUG_ATOMIC("Added [CRTC:%d:%s] %p state to %p\n",
327 crtc->base.id, crtc->name, crtc_state, state);
343 * TODO: Add generic modeset state checks once we support those.
352 /* The state->enable vs. state->mode_blob checks can be WARN_ON,
390 const struct drm_crtc_state *state)
392 struct drm_crtc *crtc = state->crtc;
395 drm_printf(p, "\tenable=%d\n", state->enable);
396 drm_printf(p, "\tactive=%d\n", state->active);
397 drm_printf(p, "\tself_refresh_active=%d\n", state->self_refresh_active);
398 drm_printf(p, "\tplanes_changed=%d\n", state->planes_changed);
399 drm_printf(p, "\tmode_changed=%d\n", state->mode_changed);
400 drm_printf(p, "\tactive_changed=%d\n", state->active_changed);
401 drm_printf(p, "\tconnectors_changed=%d\n", state->connectors_changed);
402 drm_printf(p, "\tcolor_mgmt_changed=%d\n", state->color_mgmt_changed);
403 drm_printf(p, "\tplane_mask=%x\n", state->plane_mask);
404 drm_printf(p, "\tconnector_mask=%x\n", state->connector_mask);
405 drm_printf(p, "\tencoder_mask=%x\n", state->encoder_mask);
406 drm_printf(p, "\tmode: " DRM_MODE_FMT "\n", DRM_MODE_ARG(&state->mode));
409 crtc->funcs->atomic_print_state(p, state);
413 struct drm_connector_state *state)
416 struct drm_writeback_job *writeback_job = state->writeback_job;
420 state->max_bpc = info->bpc ? info->bpc : 8;
422 state->max_bpc = min(state->max_bpc, state->max_requested_bpc);
427 if (writeback_job->fb && !state->crtc) {
433 if (state->crtc)
434 crtc_state = drm_atomic_get_existing_crtc_state(state->state,
435 state->crtc);
440 state->crtc->base.id);
452 state->writeback_job = NULL;
459 * drm_atomic_get_plane_state - get plane state
460 * @state: global atomic state object
461 * @plane: plane to get state object for
463 * This function returns the plane state for the given plane, allocating it if
464 * needed. It will also grab the relevant plane lock to make sure that the state
469 * Either the allocated state or the error code encoded into the pointer. When
474 drm_atomic_get_plane_state(struct drm_atomic_state *state,
480 WARN_ON(!state->acquire_ctx);
487 plane_state = drm_atomic_get_existing_plane_state(state, plane);
491 ret = drm_modeset_lock(&plane->mutex, state->acquire_ctx);
499 state->planes[index].state = plane_state;
500 state->planes[index].ptr = plane;
501 state->planes[index].old_state = plane->state;
502 state->planes[index].new_state = plane_state;
503 plane_state->state = state;
505 DRM_DEBUG_ATOMIC("Added [PLANE:%d:%s] %p state to %p\n",
506 plane->base.id, plane->name, plane_state, state);
511 crtc_state = drm_atomic_get_crtc_state(state,
534 * full OFF state.
540 * drm_atomic_plane_check - check plane state
541 * @old_plane_state: old plane state to check
542 * @new_plane_state: new plane state to check
544 * Provides core sanity checks for plane state.
571 /* if disabled, we don't care about the rest of the state: */
661 const struct drm_plane_state *state)
663 struct drm_plane *plane = state->plane;
664 struct drm_rect src = drm_plane_state_src(state);
665 struct drm_rect dest = drm_plane_state_dest(state);
668 drm_printf(p, "\tcrtc=%s\n", state->crtc ? state->crtc->name : "(null)");
669 drm_printf(p, "\tfb=%u\n", state->fb ? state->fb->base.id : 0);
670 if (state->fb)
671 drm_framebuffer_print_info(p, 2, state->fb);
674 drm_printf(p, "\trotation=%x\n", state->rotation);
675 drm_printf(p, "\tnormalized-zpos=%x\n", state->normalized_zpos);
677 drm_get_color_encoding_name(state->color_encoding));
679 drm_get_color_range_name(state->color_range));
682 plane->funcs->atomic_print_state(p, state);
686 * DOC: handling driver private state
693 * objects. Drivers then need to do similar state tracking and commit ordering for
698 * driver private state objects using struct &drm_private_obj, with the
699 * associated state struct &drm_private_state.
701 * Similar to userspace-exposed objects, private state structures can be
704 * directly. Sequence of the actual hardware state commit is not handled,
709 * All private state structures contained in a &drm_atomic_state update can be
712 * Drivers are recommended to wrap these for each type of driver private state
716 * An earlier way to handle driver private state was by subclassing struct
719 * commit instead" of "duplicate state, check, then either commit or release
720 * duplicated state) it is deprecated in favour of using &drm_private_state.
727 * @state: initial private object state
732 * driver private object that needs its own atomic state.
737 struct drm_private_state *state,
744 obj->state = state;
760 obj->funcs->atomic_destroy_state(obj, obj->state);
766 * drm_atomic_get_private_obj_state - get private object state
767 * @state: global atomic state
768 * @obj: private object to get the state for
770 * This function returns the private object state for the given private object,
771 * allocating the state if needed. It will also grab the relevant private
772 * object lock to make sure that the state is consistent.
776 * Either the allocated state or the error code encoded into a pointer.
779 drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
787 for (i = 0; i < state->num_private_objs; i++)
788 if (obj == state->private_objs[i].ptr)
789 return state->private_objs[i].state;
791 ret = drm_modeset_lock(&obj->lock, state->acquire_ctx);
795 num_objs = state->num_private_objs + 1;
796 size = sizeof(*state->private_objs) * num_objs;
797 arr = krealloc(state->private_objs, size, GFP_KERNEL);
801 state->private_objs = arr;
802 index = state->num_private_objs;
803 memset(&state->private_objs[index], 0, sizeof(*state->private_objs));
809 state->private_objs[index].state = obj_state;
810 state->private_objs[index].old_state = obj->state;
811 state->private_objs[index].new_state = obj_state;
812 state->private_objs[index].ptr = obj;
813 obj_state->state = state;
815 state->num_private_objs = num_objs;
817 DRM_DEBUG_ATOMIC("Added new private object %p state %p to %p\n",
818 obj, obj_state, state);
826 * @state: global atomic state object
829 * This function returns the old private object state for the given private_obj,
830 * or NULL if the private_obj is not part of the global atomic state.
833 drm_atomic_get_old_private_obj_state(struct drm_atomic_state *state,
838 for (i = 0; i < state->num_private_objs; i++)
839 if (obj == state->private_objs[i].ptr)
840 return state->private_objs[i].old_state;
848 * @state: global atomic state object
851 * This function returns the new private object state for the given private_obj,
852 * or NULL if the private_obj is not part of the global atomic state.
855 drm_atomic_get_new_private_obj_state(struct drm_atomic_state *state,
860 for (i = 0; i < state->num_private_objs; i++)
861 if (obj == state->private_objs[i].ptr)
862 return state->private_objs[i].new_state;
870 * @state: Atomic state
871 * @encoder: The encoder to fetch the connector state for
874 * as specified by the @state.
876 * If there is no connector in @state which previously had @encoder connected to
880 * state). This is especially true in enable hooks because the pipeline has
887 drm_atomic_get_old_connector_for_encoder(struct drm_atomic_state *state,
894 for_each_old_connector_in_state(state, connector, conn_state, i) {
905 * @state: Atomic state
906 * @encoder: The encoder to fetch the connector state for
909 * @encoder as specified by the @state.
911 * If there is no connector in @state which will have @encoder connected to it,
914 * attached to @encoder vs ones that do (and to inspect their state). This is
921 drm_atomic_get_new_connector_for_encoder(struct drm_atomic_state *state,
928 for_each_new_connector_in_state(state, connector, conn_state, i) {
938 * drm_atomic_get_connector_state - get connector state
939 * @state: global atomic state object
940 * @connector: connector to get state object for
942 * This function returns the connector state for the given connector,
944 * make sure that the state is consistent.
948 * Either the allocated state or the error code encoded into the pointer. When
953 drm_atomic_get_connector_state(struct drm_atomic_state *state,
960 WARN_ON(!state->acquire_ctx);
962 ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
968 if (index >= state->num_connector) {
972 c = krealloc(state->connectors, alloc * sizeof(*state->connectors), GFP_KERNEL);
976 state->connectors = c;
977 memset(&state->connectors[state->num_connector], 0,
978 sizeof(*state->connectors) * (alloc - state->num_connector));
980 state->num_connector = alloc;
983 if (state->connectors[index].state)
984 return state->connectors[index].state;
991 state->connectors[index].state = connector_state;
992 state->connectors[index].old_state = connector->state;
993 state->connectors[index].new_state = connector_state;
994 state->connectors[index].ptr = connector;
995 connector_state->state = state;
997 DRM_DEBUG_ATOMIC("Added [CONNECTOR:%d:%s] %p state to %p\n",
999 connector_state, state);
1004 crtc_state = drm_atomic_get_crtc_state(state,
1015 const struct drm_connector_state *state)
1017 state->connector;
1020 drm_printf(p, "\tcrtc=%s\n", state->crtc ? state->crtc->name : "(null)");
1021 drm_printf(p, "\tself_refresh_aware=%d\n", state->self_refresh_aware);
1024 if (state->writeback_job && state->writeback_job->fb)
1025 drm_printf(p, "\tfb=%d\n", state->writeback_job->fb->base.id);
1028 connector->funcs->atomic_print_state(p, state);
1033 * @state: atomic state
1037 * currently using @crtc to the atomic configuration @state. Note that this
1049 drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
1052 struct drm_mode_config *config = &state->dev->mode_config;
1059 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1063 ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
1068 crtc->base.id, crtc->name, state);
1071 * Changed connectors are already in @state, so only need to look
1074 drm_connector_list_iter_begin(state->dev, &conn_iter);
1079 conn_state = drm_atomic_get_connector_state(state, connector);
1093 * @state: atomic state
1097 * currently used by @crtc to the atomic configuration @state. This is useful
1102 * Since acquiring a plane state will always also acquire the w/w mutex of the
1112 drm_atomic_add_affected_planes(struct drm_atomic_state *state,
1116 drm_atomic_get_old_crtc_state(state, crtc);
1119 WARN_ON(!drm_atomic_get_new_crtc_state(state, crtc));
1122 crtc->base.id, crtc->name, state);
1124 drm_for_each_plane_mask(plane, state->dev, old_crtc_state->plane_mask) {
1126 drm_atomic_get_plane_state(state, plane);
1137 * @state: atomic configuration to check
1146 int drm_atomic_check_only(struct drm_atomic_state *state)
1148 struct drm_device *dev = state->dev;
1160 DRM_DEBUG_ATOMIC("checking %p\n", state);
1162 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
1171 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
1180 for_each_new_connector_in_state(state, conn, conn_state, i) {
1190 ret = config->funcs->atomic_check(state->dev, state);
1194 state, ret);
1199 if (!state->allow_modeset) {
1200 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
1215 * @state: atomic configuration to check
1221 * This function will take its own reference on @state.
1227 int drm_atomic_commit(struct drm_atomic_state *state)
1229 struct drm_mode_config *config = &state->dev->mode_config;
1232 ret = drm_atomic_check_only(state);
1236 DRM_DEBUG_ATOMIC("committing %p\n", state);
1238 return config->funcs->atomic_commit(state->dev, state, false);
1244 * @state: atomic configuration to check
1250 * This function will take its own reference on @state.
1256 int drm_atomic_nonblocking_commit(struct drm_atomic_state *state)
1258 struct drm_mode_config *config = &state->dev->mode_config;
1261 ret = drm_atomic_check_only(state);
1265 DRM_DEBUG_ATOMIC("committing %p nonblocking\n", state);
1267 return config->funcs->atomic_commit(state->dev, state, true);
1295 static int update_output_state(struct drm_atomic_state *state,
1306 state->acquire_ctx);
1311 ret = drm_atomic_add_affected_connectors(state, set->crtc);
1315 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
1329 new_conn_state = drm_atomic_get_connector_state(state,
1340 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
1365 struct drm_atomic_state *state)
1373 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1377 primary_state = drm_atomic_get_plane_state(state, crtc->primary);
1431 ret = update_output_state(state, set);
1439 void drm_atomic_print_state(const struct drm_atomic_state *state)
1441 struct drm_printer p = drm_info_printer(state->dev->dev);
1450 DRM_DEBUG_ATOMIC("checking %p\n", state);
1452 for_each_new_plane_in_state(state, plane, plane_state, i)
1455 for_each_new_crtc_in_state(state, crtc, crtc_state, i)
1458 for_each_new_connector_in_state(state, connector, connector_state, i)
1477 drm_atomic_plane_print_state(p, plane->state);
1485 drm_atomic_crtc_print_state(p, crtc->state);
1494 drm_atomic_connector_print_state(p, connector->state);
1501 * drm_state_dump - dump entire device atomic state
1503 * @p: where to print the state to
1505 * Just for debugging. Drivers might want an option to dump state
1535 {"state", drm_state_info, 0},