From 345e705e33181c65c5885fef864e87b712e48bd3 Mon Sep 17 00:00:00 2001 From: Michael Tretter Date: Wed, 3 Nov 2021 12:56:53 +0100 Subject: [PATCH] backend-drm: move drm objects from backend to drm device The outputs, heads, crtcs, and connectors are specific to a drm device and not the backend in general. Link them to the device that they belong to to be able to retrieve the respective device. Signed-off-by: Michael Tretter --- libweston/backend-drm/drm-internal.h | 25 +++-- libweston/backend-drm/drm-virtual.c | 30 +++--- libweston/backend-drm/drm.c | 145 ++++++++++++-------------- libweston/backend-drm/fb.c | 3 +- libweston/backend-drm/kms-color.c | 2 +- libweston/backend-drm/kms.c | 29 +++--- libweston/backend-drm/modes.c | 34 +++--- libweston/backend-drm/state-helpers.c | 4 +- libweston/backend-drm/state-propose.c | 3 +- 9 files changed, 133 insertions(+), 142 deletions(-) diff --git a/libweston/backend-drm/drm-internal.h b/libweston/backend-drm/drm-internal.h index 030aa4aa..107f91e7 100644 --- a/libweston/backend-drm/drm-internal.h +++ b/libweston/backend-drm/drm-internal.h @@ -466,7 +466,7 @@ struct drm_plane_state { struct drm_plane { struct weston_plane base; - struct drm_backend *backend; + struct drm_device *device; enum wdrm_plane_type type; @@ -488,7 +488,7 @@ struct drm_plane { }; struct drm_connector { - struct drm_backend *backend; + struct drm_device *device; drmModeConnector *conn; uint32_t connector_id; @@ -500,16 +500,15 @@ struct drm_connector { }; struct drm_writeback { - /* drm_backend::writeback_connector_list */ + /* drm_device::writeback_connector_list */ struct wl_list link; - struct drm_backend *backend; + struct drm_device *device; struct drm_connector connector; }; struct drm_head { struct weston_head base; - struct drm_backend *backend; struct drm_connector connector; struct drm_edid edid; @@ -521,9 +520,9 @@ struct drm_head { }; struct drm_crtc { - /* drm_backend::crtc_list */ + /* drm_device::crtc_list */ struct wl_list link; - struct drm_backend *backend; + struct drm_device *device; /* The output driven by the CRTC */ struct drm_output *output; @@ -537,7 +536,7 @@ struct drm_crtc { struct drm_output { struct weston_output base; - struct drm_backend *backend; + struct drm_device *device; struct drm_crtc *crtc; bool page_flip_pending; @@ -625,7 +624,7 @@ drm_output_get_plane_type_name(struct drm_plane *p) } struct drm_crtc * -drm_crtc_find(struct drm_backend *b, uint32_t crtc_id); +drm_crtc_find(struct drm_device *device, uint32_t crtc_id); struct drm_head * drm_head_find_by_connector(struct drm_backend *backend, uint32_t connector_id); @@ -650,7 +649,7 @@ drm_view_transform_supported(struct weston_view *ev, struct weston_output *outpu } int -drm_mode_ensure_blob(struct drm_backend *backend, struct drm_mode *mode); +drm_mode_ensure_blob(struct drm_device *device, struct drm_mode *mode); struct drm_mode * drm_output_choose_mode(struct drm_output *output, @@ -659,7 +658,7 @@ void update_head_from_connector(struct drm_head *head); void -drm_mode_list_destroy(struct drm_backend *backend, struct wl_list *mode_list); +drm_mode_list_destroy(struct drm_device *device, struct wl_list *mode_list); void drm_output_print_modes(struct drm_output *output); @@ -670,7 +669,7 @@ drm_output_set_mode(struct weston_output *base, const char *modeline); void -drm_property_info_populate(struct drm_backend *b, +drm_property_info_populate(struct drm_device *device, const struct drm_property_info *src, struct drm_property_info *info, unsigned int num_infos, @@ -698,7 +697,7 @@ extern const struct drm_property_info connector_props[]; extern const struct drm_property_info crtc_props[]; int -init_kms_caps(struct drm_backend *b); +init_kms_caps(struct drm_device *device); int drm_pending_state_test(struct drm_pending_state *pending_state); diff --git a/libweston/backend-drm/drm-virtual.c b/libweston/backend-drm/drm-virtual.c index 24004e14..d2b4c8e3 100644 --- a/libweston/backend-drm/drm-virtual.c +++ b/libweston/backend-drm/drm-virtual.c @@ -47,7 +47,7 @@ * CRTC's. Also, as this is a fake CRTC, it will not try to populate props. */ static struct drm_crtc * -drm_virtual_crtc_create(struct drm_backend *b, struct drm_output *output) +drm_virtual_crtc_create(struct drm_device *device, struct drm_output *output) { struct drm_crtc *crtc; @@ -55,7 +55,7 @@ drm_virtual_crtc_create(struct drm_backend *b, struct drm_output *output) if (!crtc) return NULL; - crtc->backend = b; + crtc->device = device; crtc->output = output; crtc->crtc_id = 0; @@ -86,13 +86,13 @@ drm_virtual_crtc_destroy(struct drm_crtc *crtc) * * Call drm_virtual_plane_destroy to clean up the plane. * - * @param b DRM compositor backend + * @param device DRM device * @param output Output to create internal plane for */ static struct drm_plane * -drm_virtual_plane_create(struct drm_backend *b, struct drm_output *output) +drm_virtual_plane_create(struct drm_device *device, struct drm_output *output) { - struct drm_device *device = b->drm; + struct drm_backend *b = device->backend; struct drm_plane *plane; struct weston_drm_format *fmt; uint64_t mod; @@ -104,7 +104,7 @@ drm_virtual_plane_create(struct drm_backend *b, struct drm_output *output) } plane->type = WDRM_PLANE_TYPE_PRIMARY; - plane->backend = b; + plane->device = device; plane->state_cur = drm_plane_state_alloc(NULL, plane); plane->state_cur->complete = true; @@ -192,13 +192,11 @@ drm_virtual_output_repaint(struct weston_output *output_base, struct drm_plane *scanout_plane = output->scanout_plane; struct drm_plane_state *scanout_state; struct drm_pending_state *pending_state; - struct drm_backend *backend; struct drm_device *device; assert(output->virtual); - backend = output->backend; - device = backend->drm; + device = output->device; pending_state = device->repaint_data; if (output->disable_pending || output->destroy_pending) @@ -268,7 +266,8 @@ static int drm_virtual_output_enable(struct weston_output *output_base) { struct drm_output *output = to_drm_output(output_base); - struct drm_backend *b = to_drm_backend(output_base->compositor); + struct drm_device *device = output->device; + struct drm_backend *b = device->backend; assert(output->virtual); @@ -282,7 +281,7 @@ drm_virtual_output_enable(struct weston_output *output_base) goto err; } - output->scanout_plane = drm_virtual_plane_create(b, output); + output->scanout_plane = drm_virtual_plane_create(device, output); if (!output->scanout_plane) { weston_log("Failed to find primary plane for output %s\n", output->base.name); @@ -329,19 +328,21 @@ drm_virtual_output_create(struct weston_compositor *c, char *name) { struct drm_output *output; struct drm_backend *b = to_drm_backend(c); + /* Always use the main device for virtual outputs */ + struct drm_device *device = b->drm; output = zalloc(sizeof *output); if (!output) return NULL; - output->crtc = drm_virtual_crtc_create(b, output); + output->device = device; + output->crtc = drm_virtual_crtc_create(device, output); if (!output->crtc) { free(output); return NULL; } output->virtual = true; - output->backend = b; output->gbm_bo_flags = GBM_BO_USE_LINEAR | GBM_BO_USE_RENDERING; weston_output_init(&output->base, c, name); @@ -363,7 +364,8 @@ drm_virtual_output_set_gbm_format(struct weston_output *base, const char *gbm_format) { struct drm_output *output = to_drm_output(base); - struct drm_backend *b = to_drm_backend(base->compositor); + struct drm_device *device = output->device; + struct drm_backend *b = device->backend; if (parse_gbm_format(gbm_format, b->gbm_format, &output->gbm_format) == -1) output->gbm_format = b->gbm_format; diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c index a80406f8..b37705fb 100644 --- a/libweston/backend-drm/drm.c +++ b/libweston/backend-drm/drm.c @@ -193,9 +193,8 @@ drm_plane_is_available(struct drm_plane *plane, struct drm_output *output) } struct drm_crtc * -drm_crtc_find(struct drm_backend *b, uint32_t crtc_id) +drm_crtc_find(struct drm_device *device, uint32_t crtc_id) { - struct drm_device *device = b->drm; struct drm_crtc *crtc; wl_list_for_each(crtc, &device->crtc_list, link) { @@ -451,13 +450,11 @@ drm_output_repaint(struct weston_output *output_base, pixman_region32_t *damage) struct drm_output_state *state = NULL; struct drm_plane_state *scanout_state; struct drm_pending_state *pending_state; - struct drm_backend *backend; struct drm_device *device; assert(!output->virtual); - backend = output->backend; - device = backend->drm; + device = output->device; pending_state = device->repaint_data; if (output->disable_pending || output->destroy_pending) @@ -755,13 +752,14 @@ init_pixman(struct drm_backend *b) * Call drm_plane_destroy to clean up the plane. * * @sa drm_output_find_special_plane - * @param b DRM compositor backend + * @param device DRM device * @param kplane DRM plane to create */ static struct drm_plane * -drm_plane_create(struct drm_backend *b, const drmModePlane *kplane) +drm_plane_create(struct drm_device *device, const drmModePlane *kplane) { - struct drm_device *device = b->drm; + struct drm_backend *b = device->backend; + struct weston_compositor *compositor = b->compositor; struct drm_plane *plane, *tmp; drmModeObjectProperties *props; uint64_t *zpos_range_values; @@ -772,7 +770,7 @@ drm_plane_create(struct drm_backend *b, const drmModePlane *kplane) return NULL; } - plane->backend = b; + plane->device = device; plane->state_cur = drm_plane_state_alloc(NULL, plane); plane->state_cur->complete = true; plane->possible_crtcs = kplane->possible_crtcs; @@ -787,7 +785,7 @@ drm_plane_create(struct drm_backend *b, const drmModePlane *kplane) goto err; } - drm_property_info_populate(b, plane_props, plane->props, + drm_property_info_populate(device, plane_props, plane->props, WDRM_PLANE__COUNT, props); plane->type = drm_property_get_value(&plane->props[WDRM_PLANE_TYPE], @@ -817,7 +815,7 @@ drm_plane_create(struct drm_backend *b, const drmModePlane *kplane) if (plane->type == WDRM_PLANE_TYPE__COUNT) goto err_props; - weston_plane_init(&plane->base, b->compositor, 0, 0); + weston_plane_init(&plane->base, compositor, 0, 0); wl_list_for_each(tmp, &device->plane_list, link) { if (tmp->zpos_max > plane->zpos_max) { @@ -842,15 +840,16 @@ err: /** * Find, or create, a special-purpose plane * - * @param b DRM backend + * @param device DRM device * @param output Output to use for plane * @param type Type of plane */ static struct drm_plane * -drm_output_find_special_plane(struct drm_backend *b, struct drm_output *output, +drm_output_find_special_plane(struct drm_device *device, + struct drm_output *output, enum wdrm_plane_type type) { - struct drm_device *device = b->drm; + struct drm_backend *b = device->backend; struct drm_plane *plane; wl_list_for_each(plane, &device->plane_list, link) { @@ -894,8 +893,7 @@ drm_output_find_special_plane(struct drm_backend *b, struct drm_output *output, static void drm_plane_destroy(struct drm_plane *plane) { - struct drm_backend *backend = plane->backend; - struct drm_device *device = backend->drm; + struct drm_device *device = plane->device; if (plane->type == WDRM_PLANE_TYPE_OVERLAY) drmModeSetPlane(device->drm.fd, plane->plane_id, @@ -915,12 +913,12 @@ drm_plane_destroy(struct drm_plane *plane) * * Call destroy_sprites to free these planes. * - * @param b DRM compositor backend + * @param device DRM device */ static void -create_sprites(struct drm_backend *b) +create_sprites(struct drm_device *device) { - struct drm_device *device = b->drm; + struct drm_backend *b = device->backend; drmModePlaneRes *kplane_res; drmModePlane *kplane; struct drm_plane *drm_plane; @@ -939,7 +937,7 @@ create_sprites(struct drm_backend *b) if (!kplane) continue; - drm_plane = drm_plane_create(b, kplane); + drm_plane = drm_plane_create(device, kplane); drmModeFreePlane(kplane); if (!drm_plane) continue; @@ -961,12 +959,11 @@ create_sprites(struct drm_backend *b) * * The counterpart to create_sprites. * - * @param b DRM compositor backend + * @param device DRM device */ static void -destroy_sprites(struct drm_backend *b) +destroy_sprites(struct drm_device *device) { - struct drm_device *device = b->drm; struct drm_plane *plane, *next; wl_list_for_each_safe(plane, next, &device->plane_list, link) @@ -1342,9 +1339,8 @@ parse_gbm_format(const char *s, uint32_t default_value, uint32_t *gbm_format) } static int -drm_head_read_current_setup(struct drm_head *head, struct drm_backend *backend) +drm_head_read_current_setup(struct drm_head *head, struct drm_device *device) { - struct drm_device *device = backend->drm; int drm_fd = device->drm.fd; drmModeConnector *conn = head->connector.conn; drmModeEncoder *encoder; @@ -1414,8 +1410,7 @@ drm_output_init_gamma_size(struct drm_output *output) static uint32_t drm_connector_get_possible_crtcs_mask(struct drm_connector *connector) { - struct drm_backend *backend = connector->backend; - struct drm_device *device = backend->drm; + struct drm_device *device = connector->device; uint32_t possible_crtcs = 0; drmModeConnector *conn = connector->conn; drmModeEncoder *encoder; @@ -1471,7 +1466,7 @@ drm_output_pick_crtc(struct drm_output *output) crtc_id = head->inherited_crtc_id; if (crtc_id > 0 && n < ARRAY_LENGTH(existing_crtc)) - existing_crtc[n++] = drm_crtc_find(backend, crtc_id); + existing_crtc[n++] = drm_crtc_find(device, crtc_id); } /* Find a crtc that could drive each connector individually at least, @@ -1551,9 +1546,8 @@ drm_output_pick_crtc(struct drm_output *output) * all, it adds the object to the DRM-backend CRTC list. */ static struct drm_crtc * -drm_crtc_create(struct drm_backend *b, uint32_t crtc_id, uint32_t pipe) +drm_crtc_create(struct drm_device *device, uint32_t crtc_id, uint32_t pipe) { - struct drm_device *device = b->drm; struct drm_crtc *crtc; drmModeObjectPropertiesPtr props; @@ -1568,9 +1562,9 @@ drm_crtc_create(struct drm_backend *b, uint32_t crtc_id, uint32_t pipe) if (!crtc) goto ret; - drm_property_info_populate(b, crtc_props, crtc->props_crtc, + drm_property_info_populate(device, crtc_props, crtc->props_crtc, WDRM_CRTC__COUNT, props); - crtc->backend = b; + crtc->device = device; crtc->crtc_id = crtc_id; crtc->pipe = pipe; crtc->output = NULL; @@ -1607,14 +1601,13 @@ drm_crtc_destroy(struct drm_crtc *crtc) * The CRTCs are saved in a list of the drm_backend and will keep there until * the fd gets closed. * - * @param b The DRM-backend structure. + * @param device The DRM device structure. * @param resources The DRM resources, it is taken with drmModeGetResources * @return 0 on success (at least one CRTC in the list), -1 on failure. */ static int -drm_backend_create_crtc_list(struct drm_backend *b, drmModeRes *resources) +drm_backend_create_crtc_list(struct drm_device *device, drmModeRes *resources) { - struct drm_device *device = b->drm; struct drm_crtc *crtc, *crtc_tmp; int i; @@ -1622,7 +1615,7 @@ drm_backend_create_crtc_list(struct drm_backend *b, drmModeRes *resources) for (i = 0; i < resources->count_crtcs; i++) { /* Let's create an object for the CRTC and add it to the list */ - crtc = drm_crtc_create(b, resources->crtcs[i], i); + crtc = drm_crtc_create(device, resources->crtcs[i], i); if (!crtc) goto err; } @@ -1646,7 +1639,7 @@ drm_output_init_planes(struct drm_output *output) struct drm_device *device = b->drm; output->scanout_plane = - drm_output_find_special_plane(b, output, + drm_output_find_special_plane(device, output, WDRM_PLANE_TYPE_PRIMARY); if (!output->scanout_plane) { weston_log("Failed to find primary plane for output %s\n", @@ -1661,7 +1654,7 @@ drm_output_init_planes(struct drm_output *output) /* Failing to find a cursor plane is not fatal, as we'll fall back * to software cursor. */ output->cursor_plane = - drm_output_find_special_plane(b, output, + drm_output_find_special_plane(device, output, WDRM_PLANE_TYPE_CURSOR); if (output->cursor_plane) @@ -1803,8 +1796,7 @@ drm_output_attach_crtc(struct drm_output *output) static void drm_output_detach_crtc(struct drm_output *output) { - struct drm_backend *b = output->backend; - struct drm_device *device = b->drm; + struct drm_device *device = output->device; struct drm_crtc *crtc = output->crtc; crtc->output = NULL; @@ -1905,7 +1897,7 @@ static void drm_output_destroy(struct weston_output *base) { struct drm_output *output = to_drm_output(base); - struct drm_backend *b = to_drm_backend(base->compositor); + struct drm_device *device = output->device; assert(!output->virtual); @@ -1920,7 +1912,7 @@ drm_output_destroy(struct weston_output *base) if (output->base.enabled) drm_output_deinit(&output->base); - drm_mode_list_destroy(b, &output->base.mode_list); + drm_mode_list_destroy(device, &output->base.mode_list); if (output->pageflip_timer) wl_event_source_remove(output->pageflip_timer); @@ -2038,8 +2030,7 @@ drm_head_get_current_protection(struct drm_head *head) static int drm_connector_update_properties(struct drm_connector *connector) { - struct drm_backend *backend = connector->backend; - struct drm_device *device = backend->drm; + struct drm_device *device = connector->device; drmModeObjectProperties *props; props = drmModeObjectGetProperties(device->drm.fd, @@ -2070,6 +2061,8 @@ static int drm_connector_assign_connector_info(struct drm_connector *connector, drmModeConnector *conn) { + struct drm_device *device = connector->device; + assert(connector->conn != conn); assert(connector->connector_id == conn->connector_id); @@ -2081,17 +2074,16 @@ drm_connector_assign_connector_info(struct drm_connector *connector, connector->conn = conn; drm_property_info_free(connector->props, WDRM_CONNECTOR__COUNT); - drm_property_info_populate(connector->backend, connector_props, - connector->props, + drm_property_info_populate(device, connector_props, connector->props, WDRM_CONNECTOR__COUNT, connector->props_drm); return 0; } static void -drm_connector_init(struct drm_backend *b, struct drm_connector *connector, +drm_connector_init(struct drm_device *device, struct drm_connector *connector, uint32_t connector_id) { - connector->backend = b; + connector->device = device; connector->connector_id = connector_id; connector->conn = NULL; connector->props_drm = NULL; @@ -2181,7 +2173,7 @@ drm_writeback_update_info(struct drm_writeback *writeback, drmModeConnector *con * Given a DRM connector, create a matching drm_head structure and add it * to Weston's head list. * - * @param backend Weston backend structure + * @param device DRM device structure * @param conn DRM connector object * @param drm_device udev device pointer * @returns 0 on success, -1 on failure @@ -2189,9 +2181,10 @@ drm_writeback_update_info(struct drm_writeback *writeback, drmModeConnector *con * Takes ownership of @c connector on success, not on failure. */ static int -drm_head_create(struct drm_backend *backend, drmModeConnector *conn, +drm_head_create(struct drm_device *device, drmModeConnector *conn, struct udev_device *drm_device) { + struct drm_backend *backend = device->backend; struct drm_head *head; char *name; int ret; @@ -2200,9 +2193,7 @@ drm_head_create(struct drm_backend *backend, drmModeConnector *conn, if (!head) return -1; - head->backend = backend; - - drm_connector_init(backend, &head->connector, conn->connector_id); + drm_connector_init(device, &head->connector, conn->connector_id); name = make_connector_name(conn); if (!name) @@ -2221,7 +2212,7 @@ drm_head_create(struct drm_backend *backend, drmModeConnector *conn, conn->connector_type == DRM_MODE_CONNECTOR_eDP) weston_head_set_internal(&head->base); - if (drm_head_read_current_setup(head, backend) < 0) { + if (drm_head_read_current_setup(head, device) < 0) { weston_log("Failed to retrieve current mode from connector %d.\n", head->connector.connector_id); /* Not fatal. */ @@ -2270,13 +2261,14 @@ static struct weston_output * drm_output_create(struct weston_compositor *compositor, const char *name) { struct drm_backend *b = to_drm_backend(compositor); + struct drm_device *device = b->drm; struct drm_output *output; output = zalloc(sizeof *output); if (output == NULL) return NULL; - output->backend = b; + output->device = device; output->crtc = NULL; output->gbm_format = DRM_FORMAT_INVALID; @@ -2308,25 +2300,24 @@ drm_output_create(struct weston_compositor *compositor, const char *name) * Given a DRM connector of type writeback, create a matching drm_writeback * structure and add it to Weston's writeback list. * - * @param b Weston backend structure + * @param device DRM device structure * @param conn DRM connector object of type writeback * @returns 0 on success, -1 on failure * * Takes ownership of @c connector on success, not on failure. */ static int -drm_writeback_create(struct drm_backend *b, drmModeConnector *conn) +drm_writeback_create(struct drm_device *device, drmModeConnector *conn) { - struct drm_device *device = b->drm; struct drm_writeback *writeback; int ret; writeback = zalloc(sizeof *writeback); assert(writeback); - writeback->backend = b; + writeback->device = device; - drm_connector_init(b, &writeback->connector, conn->connector_id); + drm_connector_init(device, &writeback->connector, conn->connector_id); ret = drm_writeback_update_info(writeback, conn); if (ret < 0) @@ -2355,24 +2346,24 @@ drm_writeback_destroy(struct drm_writeback *writeback) * * The object is then added to the DRM-backend list of heads or writebacks. * - * @param b The DRM-backend structure + * @param device The DRM device structure * @param conn The DRM connector object * @param drm_device udev device pointer * @return 0 on success, -1 on failure */ static int -drm_backend_add_connector(struct drm_backend *b, drmModeConnector *conn, +drm_backend_add_connector(struct drm_device *device, drmModeConnector *conn, struct udev_device *drm_device) { int ret; if (conn->connector_type == DRM_MODE_CONNECTOR_WRITEBACK) { - ret = drm_writeback_create(b, conn); + ret = drm_writeback_create(device, conn); if (ret < 0) weston_log("DRM: failed to create writeback for connector %d.\n", conn->connector_id); } else { - ret = drm_head_create(b, conn, drm_device); + ret = drm_head_create(device, conn, drm_device); if (ret < 0) weston_log("DRM: failed to create head for connector %d.\n", conn->connector_id); @@ -2386,16 +2377,16 @@ drm_backend_add_connector(struct drm_backend *b, drmModeConnector *conn, * * These objects are added to the DRM-backend lists of heads and writebacks. * - * @param b The DRM-backend structure + * @param device The DRM device structure * @param drm_device udev device pointer * @param resources The DRM resources, it is taken with drmModeGetResources * @return 0 on success, -1 on failure */ static int -drm_backend_discover_connectors(struct drm_backend *b, struct udev_device *drm_device, +drm_backend_discover_connectors(struct drm_device *device, + struct udev_device *drm_device, drmModeRes *resources) { - struct drm_device *device = b->drm; drmModeConnector *conn; int i, ret; @@ -2411,7 +2402,7 @@ drm_backend_discover_connectors(struct drm_backend *b, struct udev_device *drm_d if (!conn) continue; - ret = drm_backend_add_connector(b, conn, drm_device); + ret = drm_backend_add_connector(device, conn, drm_device); if (ret < 0) drmModeFreeConnector(conn); } @@ -2468,7 +2459,7 @@ drm_backend_update_connectors(struct drm_backend *b, struct udev_device *drm_dev else if (writeback) ret = drm_writeback_update_info(writeback, conn); else - ret = drm_backend_add_connector(b, conn, drm_device); + ret = drm_backend_add_connector(b->drm, conn, drm_device); if (ret < 0) drmModeFreeConnector(conn); @@ -2632,7 +2623,7 @@ drm_destroy(struct weston_compositor *ec) b->shutting_down = true; - destroy_sprites(b); + destroy_sprites(b->drm); weston_log_scope_destroy(b->debug); b->debug = NULL; @@ -2951,13 +2942,11 @@ recorder_frame_notify(struct wl_listener *listener, void *data) { struct drm_output *output; struct drm_device *device; - struct drm_backend *b; int fd, ret; output = container_of(listener, struct drm_output, recorder_frame_listener); - b = to_drm_backend(output->base.compositor); - device = b->drm; + device = output->device; if (!output->recorder) return; @@ -3130,7 +3119,7 @@ drm_backend_create(struct weston_compositor *compositor, goto err_udev; } - if (init_kms_caps(b) < 0) { + if (init_kms_caps(device) < 0) { weston_log("failed to initialize kms\n"); goto err_udev_dev; } @@ -3164,13 +3153,13 @@ drm_backend_create(struct weston_compositor *compositor, } wl_list_init(&b->drm->crtc_list); - if (drm_backend_create_crtc_list(b, res) == -1) { + if (drm_backend_create_crtc_list(b->drm, res) == -1) { weston_log("Failed to create CRTC list for DRM-backend\n"); goto err_create_crtc_list; } wl_list_init(&device->plane_list); - create_sprites(b); + create_sprites(b->drm); if (udev_input_init(&b->input, compositor, b->udev, seat_id, @@ -3180,7 +3169,7 @@ drm_backend_create(struct weston_compositor *compositor, } wl_list_init(&b->drm->writeback_connector_list); - if (drm_backend_discover_connectors(b, drm_device, res) < 0) { + if (drm_backend_discover_connectors(b->drm, drm_device, res) < 0) { weston_log("Failed to create heads for %s\n", b->drm->drm.filename); goto err_udev_input; } @@ -3290,7 +3279,7 @@ err_drm_source: err_udev_input: udev_input_destroy(&b->input); err_sprite: - destroy_sprites(b); + destroy_sprites(b->drm); err_create_crtc_list: drmModeFreeResources(res); err_udev_dev: diff --git a/libweston/backend-drm/fb.c b/libweston/backend-drm/fb.c index d7df874a..e6881e8a 100644 --- a/libweston/backend-drm/fb.c +++ b/libweston/backend-drm/fb.c @@ -474,7 +474,8 @@ drm_can_scanout_dmabuf(struct weston_compositor *ec, static bool drm_fb_compatible_with_plane(struct drm_fb *fb, struct drm_plane *plane) { - struct drm_backend *b = plane->backend; + struct drm_device *device = plane->device; + struct drm_backend *b = device->backend; struct weston_drm_format *fmt; /* Check whether the format is supported */ diff --git a/libweston/backend-drm/kms-color.c b/libweston/backend-drm/kms-color.c index 55925665..2f9ad945 100644 --- a/libweston/backend-drm/kms-color.c +++ b/libweston/backend-drm/kms-color.c @@ -108,7 +108,7 @@ weston_hdr_metadata_type1_to_kms(struct hdr_metadata_infoframe *dst, int drm_output_ensure_hdr_output_metadata_blob(struct drm_output *output) { - struct drm_device *device = output->backend->drm; + struct drm_device *device = output->device; const struct weston_hdr_metadata_type1 *src; struct hdr_output_metadata meta; uint32_t blob_id = 0; diff --git a/libweston/backend-drm/kms.c b/libweston/backend-drm/kms.c index 858d9146..c7a067dc 100644 --- a/libweston/backend-drm/kms.c +++ b/libweston/backend-drm/kms.c @@ -275,20 +275,19 @@ drm_property_get_range_values(struct drm_property_info *info, * The values given in enum_names are searched for, and stored in the * same-indexed field of the map array. * - * @param b DRM backend object + * @param device DRM device object * @param src DRM property info array to source from * @param info DRM property info array to copy into * @param num_infos Number of entries in the source array * @param props DRM object properties for the object */ void -drm_property_info_populate(struct drm_backend *b, +drm_property_info_populate(struct drm_device *device, const struct drm_property_info *src, struct drm_property_info *info, unsigned int num_infos, drmModeObjectProperties *props) { - struct drm_device *device = b->drm; drmModePropertyRes *prop; unsigned i, j; @@ -437,8 +436,7 @@ drm_plane_populate_formats(struct drm_plane *plane, const drmModePlane *kplane, const drmModeObjectProperties *props, const bool use_modifiers) { - struct drm_backend *backend = plane->backend; - struct drm_device *device = backend->drm; + struct drm_device *device = plane->device; unsigned i, j; drmModePropertyBlobRes *blob = NULL; struct drm_format_modifier_blob *fmt_mod_blob; @@ -796,7 +794,8 @@ static int crtc_add_prop(drmModeAtomicReq *req, struct drm_crtc *crtc, enum wdrm_crtc_property prop, uint64_t val) { - struct drm_backend *b = crtc->backend; + struct drm_device *device = crtc->device; + struct drm_backend *b = device->backend; struct drm_property_info *info = &crtc->props_crtc[prop]; int ret; @@ -816,7 +815,8 @@ static int connector_add_prop(drmModeAtomicReq *req, struct drm_connector *connector, enum wdrm_connector_property prop, uint64_t val) { - struct drm_backend *b = connector->backend; + struct drm_device *device = connector->device; + struct drm_backend *b = device->backend; struct drm_property_info *info = &connector->props[prop]; uint32_t connector_id = connector->connector_id; int ret; @@ -836,7 +836,8 @@ static int plane_add_prop(drmModeAtomicReq *req, struct drm_plane *plane, enum wdrm_plane_property prop, uint64_t val) { - struct drm_backend *b = plane->backend; + struct drm_device *device = plane->device; + struct drm_backend *b = device->backend; struct drm_property_info *info = &plane->props[prop]; int ret; @@ -941,6 +942,7 @@ drm_output_apply_state_atomic(struct drm_output_state *state, { struct drm_output *output = state->output; struct drm_backend *b = to_drm_backend(output->base.compositor); + struct drm_device *device = b->drm; struct drm_crtc *crtc = output->crtc; struct drm_plane_state *plane_state; struct drm_mode *current_mode = to_drm_mode(output->base.current_mode); @@ -957,7 +959,7 @@ drm_output_apply_state_atomic(struct drm_output_state *state, } if (state->dpms == WESTON_DPMS_ON) { - ret = drm_mode_ensure_blob(b, current_mode); + ret = drm_mode_ensure_blob(device, current_mode); if (ret != 0) return ret; @@ -1410,7 +1412,7 @@ atomic_flip_handler(int fd, unsigned int frame, unsigned int sec, WP_PRESENTATION_FEEDBACK_KIND_HW_COMPLETION | WP_PRESENTATION_FEEDBACK_KIND_HW_CLOCK; - crtc = drm_crtc_find(b, crtc_id); + crtc = drm_crtc_find(device, crtc_id); assert(crtc); output = crtc->output; @@ -1450,9 +1452,10 @@ on_drm_input(int fd, uint32_t mask, void *data) } int -init_kms_caps(struct drm_backend *b) +init_kms_caps(struct drm_device *device) { - struct drm_device *device = b->drm; + struct drm_backend *b = device->backend; + struct weston_compositor *compositor = b->compositor; uint64_t cap; int ret; @@ -1464,7 +1467,7 @@ init_kms_caps(struct drm_backend *b) return -1; } - if (weston_compositor_set_presentation_clock(b->compositor, CLOCK_MONOTONIC) < 0) { + if (weston_compositor_set_presentation_clock(compositor, CLOCK_MONOTONIC) < 0) { weston_log("Error: failed to set presentation clock to CLOCK_MONOTONIC.\n"); return -1; } diff --git a/libweston/backend-drm/modes.c b/libweston/backend-drm/modes.c index a228572b..c904b1b2 100644 --- a/libweston/backend-drm/modes.c +++ b/libweston/backend-drm/modes.c @@ -98,9 +98,9 @@ drm_subpixel_to_wayland(int drm_value) } int -drm_mode_ensure_blob(struct drm_backend *backend, struct drm_mode *mode) +drm_mode_ensure_blob(struct drm_device *device, struct drm_mode *mode) { - struct drm_device *device = backend->drm; + struct drm_backend *backend = device->backend; int ret; if (mode->blob_id) @@ -321,8 +321,7 @@ find_and_parse_output_edid(struct drm_head *head, const char **serial_number, uint32_t *eotf_mask) { - struct drm_backend *backend = head->backend; - struct drm_device *device = backend->drm; + struct drm_device *device = head->connector.device; drmModePropertyBlobPtr edid_blob = NULL; uint32_t blob_id; int rc; @@ -363,7 +362,7 @@ prune_eotf_modes_by_kms_support(struct drm_head *head, uint32_t *eotf_mask) /* Without the KMS property, cannot do anything but SDR. */ info = &head->connector.props[WDRM_CONNECTOR_HDR_OUTPUT_METADATA]; - if (!head->backend->drm->atomic_modeset || info->prop_id == 0) + if (!head->connector.device->atomic_modeset || info->prop_id == 0) *eotf_mask = WESTON_EOTF_MODE_SDR; } @@ -427,10 +426,8 @@ drm_output_add_mode(struct drm_output *output, const drmModeModeInfo *info) * Destroys a mode, and removes it from the list. */ static void -drm_output_destroy_mode(struct drm_backend *backend, struct drm_mode *mode) +drm_output_destroy_mode(struct drm_device *device, struct drm_mode *mode) { - struct drm_device *device = backend->drm; - if (mode->blob_id) drmModeDestroyPropertyBlob(device->drm.fd, mode->blob_id); wl_list_remove(&mode->base.link); @@ -439,16 +436,16 @@ drm_output_destroy_mode(struct drm_backend *backend, struct drm_mode *mode) /** Destroy a list of drm_modes * - * @param backend The backend for releasing mode property blobs. + * @param device The device for releasing mode property blobs. * @param mode_list The list linked by drm_mode::base.link. */ void -drm_mode_list_destroy(struct drm_backend *backend, struct wl_list *mode_list) +drm_mode_list_destroy(struct drm_device *device, struct wl_list *mode_list) { struct drm_mode *mode, *next; wl_list_for_each_safe(mode, next, mode_list, base.link) - drm_output_destroy_mode(backend, mode); + drm_output_destroy_mode(device, mode); } void @@ -567,7 +564,7 @@ update_head_from_connector(struct drm_head *head) * Find the most suitable mode to use for initial setup (or reconfiguration on * hotplug etc) for a DRM output. * - * @param backend the DRM backend + * @param device the DRM device * @param output DRM output to choose mode for * @param mode Strategy and preference to use when choosing mode * @param modeline Manually-entered mode (may be NULL) @@ -575,13 +572,12 @@ update_head_from_connector(struct drm_head *head) * @returns A mode from the output's mode list, or NULL if none available */ static struct drm_mode * -drm_output_choose_initial_mode(struct drm_backend *backend, +drm_output_choose_initial_mode(struct drm_device *device, struct drm_output *output, enum weston_drm_backend_output_mode mode, const char *modeline, const drmModeModeInfo *current_mode) { - struct drm_device *device = backend->drm; struct drm_mode *preferred = NULL; struct drm_mode *current = NULL; struct drm_mode *configured = NULL; @@ -744,6 +740,7 @@ drm_output_try_add_mode(struct drm_output *output, const drmModeModeInfo *info) struct weston_mode *base; struct drm_mode *mode = NULL; struct drm_backend *backend; + struct drm_device *device; const drmModeModeInfo *chosen = NULL; assert(info); @@ -758,7 +755,8 @@ drm_output_try_add_mode(struct drm_output *output, const drmModeModeInfo *info) if (chosen == info) { assert(mode); backend = to_drm_backend(output->base.compositor); - drm_output_destroy_mode(backend, mode); + device = backend->drm; + drm_output_destroy_mode(device, mode); chosen = NULL; } @@ -786,6 +784,7 @@ static int drm_output_update_modelist_from_heads(struct drm_output *output) { struct drm_backend *backend = to_drm_backend(output->base.compositor); + struct drm_device *device = backend->drm; struct weston_head *head_base; struct drm_head *head; drmModeConnector *conn; @@ -794,7 +793,7 @@ drm_output_update_modelist_from_heads(struct drm_output *output) assert(!output->base.enabled); - drm_mode_list_destroy(backend, &output->base.mode_list); + drm_mode_list_destroy(device, &output->base.mode_list); wl_list_for_each(head_base, &output->base.head_list, output_link) { head = to_drm_head(head_base); @@ -816,6 +815,7 @@ drm_output_set_mode(struct weston_output *base, { struct drm_output *output = to_drm_output(base); struct drm_backend *b = to_drm_backend(base->compositor); + struct drm_device *device = b->drm; struct drm_head *head = to_drm_head(weston_output_get_first_head(base)); struct drm_mode *current; @@ -826,7 +826,7 @@ drm_output_set_mode(struct weston_output *base, if (drm_output_update_modelist_from_heads(output) < 0) return -1; - current = drm_output_choose_initial_mode(b, output, mode, modeline, + current = drm_output_choose_initial_mode(device, output, mode, modeline, &head->inherited_mode); if (!current) return -1; diff --git a/libweston/backend-drm/state-helpers.c b/libweston/backend-drm/state-helpers.c index 0e8e45e6..4077c8aa 100644 --- a/libweston/backend-drm/state-helpers.c +++ b/libweston/backend-drm/state-helpers.c @@ -73,7 +73,6 @@ drm_plane_state_alloc(struct drm_output_state *state_output, void drm_plane_state_free(struct drm_plane_state *state, bool force) { - struct drm_backend *backend; struct drm_device *device; if (!state) @@ -89,8 +88,7 @@ drm_plane_state_free(struct drm_plane_state *state, bool force) * by the kernel, which means we can safely discard it. */ if (state->damage_blob_id != 0) { - backend = state->plane->backend; - device = backend->drm; + device = state->plane->device; drmModeDestroyPropertyBlob(device->drm.fd, state->damage_blob_id); diff --git a/libweston/backend-drm/state-propose.c b/libweston/backend-drm/state-propose.c index 105c79e7..b2d0549f 100644 --- a/libweston/backend-drm/state-propose.c +++ b/libweston/backend-drm/state-propose.c @@ -162,8 +162,7 @@ out: static void cursor_bo_update(struct drm_plane_state *plane_state, struct weston_view *ev) { - struct drm_backend *b = plane_state->plane->backend; - struct drm_device *device = b->drm; + struct drm_device *device = plane_state->plane->device; struct gbm_bo *bo = plane_state->fb->bo; struct weston_buffer *buffer = ev->surface->buffer_ref.buffer; uint32_t buf[device->cursor_width * device->cursor_height];