Lines Matching refs:state
58 * @state: atomic state
64 void drm_atomic_state_default_release(struct drm_atomic_state *state)
66 kfree(state->connectors);
67 kfree(state->crtcs);
68 kfree(state->planes);
69 kfree(state->private_objs);
74 * drm_atomic_state_init - init new atomic state
76 * @state: atomic state
78 * Default implementation for filling in a new atomic state.
83 drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state)
85 kref_init(&state->ref);
90 state->allow_modeset = true;
92 state->crtcs = kcalloc(dev->mode_config.num_crtc,
93 sizeof(*state->crtcs), GFP_KERNEL);
94 if (!state->crtcs)
96 state->planes = kcalloc(dev->mode_config.num_total_plane,
97 sizeof(*state->planes), GFP_KERNEL);
98 if (!state->planes)
107 state->dev = dev;
109 DRM_DEBUG_ATOMIC("Allocated atomic state %p\n", state);
113 drm_atomic_state_default_release(state);
119 * drm_atomic_state_alloc - allocate atomic state
122 * This allocates an empty atomic state to track updates.
130 struct drm_atomic_state *state;
132 state = kzalloc(sizeof(*state), GFP_KERNEL);
133 if (!state)
135 if (drm_atomic_state_init(dev, state) < 0) {
136 kfree(state);
139 return state;
147 * drm_atomic_state_default_clear - clear base atomic state
148 * @state: atomic state
150 * Default implementation for clearing atomic state.
154 void drm_atomic_state_default_clear(struct drm_atomic_state *state)
156 struct drm_device *dev = state->dev;
160 DRM_DEBUG_ATOMIC("Clearing atomic state %p\n", state);
162 for (i = 0; i < state->num_connector; i++) {
163 struct drm_connector *connector = state->connectors[i].ptr;
169 state->connectors[i].state);
170 state->connectors[i].ptr = NULL;
171 state->connectors[i].state = NULL;
172 state->connectors[i].old_state = NULL;
173 state->connectors[i].new_state = NULL;
178 struct drm_crtc *crtc = state->crtcs[i].ptr;
184 state->crtcs[i].state);
186 state->crtcs[i].ptr = NULL;
187 state->crtcs[i].state = NULL;
188 state->crtcs[i].old_state = NULL;
189 state->crtcs[i].new_state = NULL;
191 if (state->crtcs[i].commit) {
192 drm_crtc_commit_put(state->crtcs[i].commit);
193 state->crtcs[i].commit = NULL;
198 struct drm_plane *plane = state->planes[i].ptr;
204 state->planes[i].state);
205 state->planes[i].ptr = NULL;
206 state->planes[i].state = NULL;
207 state->planes[i].old_state = NULL;
208 state->planes[i].new_state = NULL;
211 for (i = 0; i < state->num_private_objs; i++) {
212 struct drm_private_obj *obj = state->private_objs[i].ptr;
215 state->private_objs[i].state);
216 state->private_objs[i].ptr = NULL;
217 state->private_objs[i].state = NULL;
218 state->private_objs[i].old_state = NULL;
219 state->private_objs[i].new_state = NULL;
221 state->num_private_objs = 0;
223 if (state->fake_commit) {
224 drm_crtc_commit_put(state->fake_commit);
225 state->fake_commit = NULL;
231 * drm_atomic_state_clear - clear state object
232 * @state: atomic state
236 * configuration. Which means that all the state assembled in @state is no
237 * longer an atomic update to the current state, but to some arbitrary earlier
238 * state. Which could break assumptions the driver's
241 * Hence we must clear all cached state and completely start over, using this
244 void drm_atomic_state_clear(struct drm_atomic_state *state)
246 struct drm_device *dev = state->dev;
250 config->funcs->atomic_state_clear(state);
252 drm_atomic_state_default_clear(state);
257 * __drm_atomic_state_free - free all memory for an atomic state
258 * @ref: This atomic state to deallocate
260 * This frees all memory associated with an atomic state, including all the
261 * per-object state for planes, CRTCs and connectors.
265 struct drm_atomic_state *state = container_of(ref, typeof(*state), ref);
266 struct drm_device *dev = state->dev;
269 drm_atomic_state_clear(state);
271 DRM_DEBUG_ATOMIC("Freeing atomic state %p\n", state);
274 config->funcs->atomic_state_free(state);
276 drm_atomic_state_default_release(state);
277 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;
419 state->max_bpc = info->bpc ? info->bpc : 8;
421 state->max_bpc = min(state->max_bpc, state->max_requested_bpc);
426 if (writeback_job->fb && !state->crtc) {
432 if (state->crtc)
433 crtc_state = drm_atomic_get_existing_crtc_state(state->state,
434 state->crtc);
439 state->crtc->base.id);
451 state->writeback_job = NULL;
458 * drm_atomic_get_plane_state - get plane state
459 * @state: global atomic state object
460 * @plane: plane to get state object for
462 * This function returns the plane state for the given plane, allocating it if
463 * needed. It will also grab the relevant plane lock to make sure that the state
468 * Either the allocated state or the error code encoded into the pointer. When
473 drm_atomic_get_plane_state(struct drm_atomic_state *state,
479 WARN_ON(!state->acquire_ctx);
486 plane_state = drm_atomic_get_existing_plane_state(state, plane);
490 ret = drm_modeset_lock(&plane->mutex, state->acquire_ctx);
498 state->planes[index].state = plane_state;
499 state->planes[index].ptr = plane;
500 state->planes[index].old_state = plane->state;
501 state->planes[index].new_state = plane_state;
502 plane_state->state = state;
504 DRM_DEBUG_ATOMIC("Added [PLANE:%d:%s] %p state to %p\n",
505 plane->base.id, plane->name, plane_state, state);
510 crtc_state = drm_atomic_get_crtc_state(state,
533 * full OFF state.
539 * drm_atomic_plane_check - check plane state
540 * @old_plane_state: old plane state to check
541 * @new_plane_state: new plane state to check
543 * Provides core sanity checks for plane state.
570 /* 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 struct drm_connector *connector = 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);
1022 drm_printf(p, "\tmax_requested_bpc=%d\n", state->max_requested_bpc);
1025 if (state->writeback_job && state->writeback_job->fb)
1026 drm_printf(p, "\tfb=%d\n", state->writeback_job->fb->base.id);
1029 connector->funcs->atomic_print_state(p, state);
1033 * drm_atomic_get_bridge_state - get bridge state
1034 * @state: global atomic state object
1035 * @bridge: bridge to get state object for
1037 * This function returns the bridge state for the given bridge, allocating it
1039 * state is consistent.
1043 * Either the allocated state or the error code encoded into the pointer. When
1048 drm_atomic_get_bridge_state(struct drm_atomic_state *state,
1053 obj_state = drm_atomic_get_private_obj_state(state, &bridge->base);
1062 * drm_atomic_get_old_bridge_state - get old bridge state, if it exists
1063 * @state: global atomic state object
1066 * This function returns the old bridge state for the given bridge, or NULL if
1067 * the bridge is not part of the global atomic state.
1070 drm_atomic_get_old_bridge_state(struct drm_atomic_state *state,
1075 obj_state = drm_atomic_get_old_private_obj_state(state, &bridge->base);
1084 * drm_atomic_get_new_bridge_state - get new bridge state, if it exists
1085 * @state: global atomic state object
1088 * This function returns the new bridge state for the given bridge, or NULL if
1089 * the bridge is not part of the global atomic state.
1092 drm_atomic_get_new_bridge_state(struct drm_atomic_state *state,
1097 obj_state = drm_atomic_get_new_private_obj_state(state, &bridge->base);
1107 * @state: atomic state
1111 * bridge states to @state and make them available when
1122 drm_atomic_add_encoder_bridges(struct drm_atomic_state *state,
1132 encoder->base.id, encoder->name, state);
1135 /* Skip bridges that don't implement the atomic state hooks. */
1139 bridge_state = drm_atomic_get_bridge_state(state, bridge);
1150 * @state: atomic state
1154 * currently using @crtc to the atomic configuration @state. Note that this
1166 drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
1169 struct drm_mode_config *config = &state->dev->mode_config;
1176 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1180 ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
1185 crtc->base.id, crtc->name, state);
1188 * Changed connectors are already in @state, so only need to look
1191 drm_connector_list_iter_begin(state->dev, &conn_iter);
1196 conn_state = drm_atomic_get_connector_state(state, connector);
1210 * @state: atomic state
1214 * currently used by @crtc to the atomic configuration @state. This is useful
1219 * Since acquiring a plane state will always also acquire the w/w mutex of the
1229 drm_atomic_add_affected_planes(struct drm_atomic_state *state,
1233 drm_atomic_get_old_crtc_state(state, crtc);
1236 WARN_ON(!drm_atomic_get_new_crtc_state(state, crtc));
1239 crtc->base.id, crtc->name, state);
1241 drm_for_each_plane_mask(plane, state->dev, old_crtc_state->plane_mask) {
1243 drm_atomic_get_plane_state(state, plane);
1254 * @state: atomic configuration to check
1263 int drm_atomic_check_only(struct drm_atomic_state *state)
1265 struct drm_device *dev = state->dev;
1277 DRM_DEBUG_ATOMIC("checking %p\n", state);
1279 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
1288 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
1297 for_each_new_connector_in_state(state, conn, conn_state, i) {
1307 ret = config->funcs->atomic_check(state->dev, state);
1311 state, ret);
1316 if (!state->allow_modeset) {
1317 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
1332 * @state: atomic configuration to check
1338 * This function will take its own reference on @state.
1344 int drm_atomic_commit(struct drm_atomic_state *state)
1346 struct drm_mode_config *config = &state->dev->mode_config;
1349 ret = drm_atomic_check_only(state);
1353 DRM_DEBUG_ATOMIC("committing %p\n", state);
1355 return config->funcs->atomic_commit(state->dev, state, false);
1361 * @state: atomic configuration to check
1367 * This function will take its own reference on @state.
1373 int drm_atomic_nonblocking_commit(struct drm_atomic_state *state)
1375 struct drm_mode_config *config = &state->dev->mode_config;
1378 ret = drm_atomic_check_only(state);
1382 DRM_DEBUG_ATOMIC("committing %p nonblocking\n", state);
1384 return config->funcs->atomic_commit(state->dev, state, true);
1412 static int update_output_state(struct drm_atomic_state *state,
1423 state->acquire_ctx);
1428 ret = drm_atomic_add_affected_connectors(state, set->crtc);
1432 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
1446 new_conn_state = drm_atomic_get_connector_state(state,
1457 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
1482 struct drm_atomic_state *state)
1490 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1494 primary_state = drm_atomic_get_plane_state(state, crtc->primary);
1548 ret = update_output_state(state, set);
1556 void drm_atomic_print_state(const struct drm_atomic_state *state)
1558 struct drm_printer p = drm_info_printer(state->dev->dev);
1567 DRM_DEBUG_ATOMIC("checking %p\n", state);
1569 for_each_new_plane_in_state(state, plane, plane_state, i)
1572 for_each_new_crtc_in_state(state, crtc, crtc_state, i)
1575 for_each_new_connector_in_state(state, connector, connector_state, i)
1594 drm_atomic_plane_print_state(p, plane->state);
1602 drm_atomic_crtc_print_state(p, crtc->state);
1611 drm_atomic_connector_print_state(p, connector->state);
1618 * drm_state_dump - dump entire device atomic state
1620 * @p: where to print the state to
1622 * Just for debugging. Drivers might want an option to dump state
1652 {"state", drm_state_info, 0},