diff --git a/drivers/gpu/drm/apple/Makefile b/drivers/gpu/drm/apple/Makefile index 8b2d7288b5639..1b3ff846bd0e6 100644 --- a/drivers/gpu/drm/apple/Makefile +++ b/drivers/gpu/drm/apple/Makefile @@ -9,8 +9,6 @@ appledrm-$(CONFIG_DRM_APPLE_AUDIO) += audio.o appledrm-$(CONFIG_DRM_APPLE_AUDIO) += av.o appledrm-y += connector.o dcp-panel-adt.o dcp-display-metadata.o dcp-180hz.o appledrm-y += ibootep.o -appledrm-y += dcpext_scanout.o -appledrm-y += dcpext_drm.o appledrm-y += iomfb_v12_3.o appledrm-y += iomfb_v13_3.o appledrm-y += iomfb_v14_7_tpl.o diff --git a/drivers/gpu/drm/apple/dcp-fabric.c b/drivers/gpu/drm/apple/dcp-fabric.c index 150cd163924f1..6a0e37934500b 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.c +++ b/drivers/gpu/drm/apple/dcp-fabric.c @@ -26,7 +26,6 @@ #include "dcp-fabric.h" #include "dcp-fabric-effects.h" #include "dcp-hdmi.h" -#include "dcpext_scanout.h" #include "ibootep.h" #include "dcp-internal.h" #include "dptx-service.h" @@ -1425,7 +1424,6 @@ static void dcp_fabric_snapshot_port(struct apple_dcp_typec_port *port, dcp_typec_safe_held(dcp); pipeline->tunnel_held = dcp_typec_tunnel_held(dcp); pipeline->presence = dcp_hdmi_presence(dcp); - pipeline->terminal = tunnel && dcpext_scanout_terminal(dcp); pipeline->services_ready = !tunnel || dcp_tb_services_ready(dcp); pipeline->external = dcp->external; diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index ea38c3fd64de7..5bdce8017dfd6 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -429,7 +429,6 @@ struct dcp_desktop_state { }; /* TODO: move IOMFB members to its own struct */ -struct dcpext_scanout; struct dcp_hdmi; bool dcp_desktop_present_complete(struct apple_dcp *dcp, u32 id); @@ -554,10 +553,9 @@ struct apple_dcp { /* * A T6030 external processor in the main DRM device: the kernel starts * its firmware on first use, its modes come from the attached display. - * Clear for the manual diagnostic path (separate scanout, explicit start). + * Clear for the manual diagnostic path (explicit start). */ bool external_native; - struct dcpext_scanout *dcpext_scanout; bool external_link_ready; /* Full connect/HPD handshake completed. */ bool external_suspended; /* hpd_mutex serializes PM against explicit start */ struct work_struct external_work; @@ -1305,8 +1303,8 @@ static inline bool dcp_is_ext26(const struct apple_dcp *dcp) * The T6030 external processor (the J514S/J516S built-in HDMI port and * USB-C displays) driven natively through Aurora's DCPLink session: DCP * firmware 14.7's external role, whose DP/HDMI audio service differs from - * the M1/M2 one (see av.c). The manual diagnostic pipe (dcpext_scanout) and - * the T8122 template path are not this. + * the M1/M2 one (see av.c). The manual explicit-start path and the T8122 + * template path are not this. */ static inline bool dcp_is_v14_7_external(const struct apple_dcp *dcp) { diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 7cde46e009096..d896b1b299bf7 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -68,7 +68,6 @@ #include "dcp-fabric.h" #include "dcp-hdmi.h" #include "dcp-syslog.h" -#include "dcpext_scanout.h" #include "dcp-internal.h" #include "j613-25g83.h" #include "dcp-external-bw.h" @@ -2356,10 +2355,6 @@ static int dcp_dptx_connect_raw(struct apple_dcp *dcp, u32 port, bool *retryable goto out_unlock; } generation = dcp->typec_generation; - if (dcp->external && dcpext_scanout_terminal(dcp)) { - mutex_unlock(&dcp->hpd_mutex); - return -ESHUTDOWN; - } if (!dptx_service_available(&dcp->dptxport[port])) { dev_warn(dcp->dev, "dcp_dptx_connect: dptx service for port %d not enabled\n", port); ret = -ENODEV; @@ -2517,12 +2512,11 @@ static int dcp_dptx_connect_raw(struct apple_dcp *dcp, u32 port, bool *retryable mutex_lock(&dcp->hpd_mutex); if (!dcp->dptxport[port].connected || !(READ_ONCE(dcp->typec_cable_connected) || dcp_hdmi_port_attached(dcp)) || - READ_ONCE(dcp->crashed) || dcpext_scanout_terminal(dcp)) { + READ_ONCE(dcp->crashed)) { mutex_unlock(&dcp->hpd_mutex); return -ENOLINK; } smp_store_release(&dcp->external_link_ready, true); - dcpext_scanout_link_restored(dcp); mutex_unlock(&dcp->hpd_mutex); } @@ -3485,8 +3479,7 @@ static void dcp_typec_reconnect_work(struct work_struct *work) } /* A route following its CRTC hands the link over itself. */ - if ((dcp->external && dcpext_scanout_terminal(dcp)) || - !READ_ONCE(dcp->typec_cable_connected) || + if (!READ_ONCE(dcp->typec_cable_connected) || READ_ONCE(dcp->typec_follow_retiring)) return; @@ -3785,10 +3778,8 @@ static int dcp_dptx_release_locked(struct apple_dcp *dcp, u32 port) int ret; lockdep_assert_held(&dcp->hpd_mutex); - if (dcp->external) { + if (dcp->external) smp_store_release(&dcp->external_link_ready, false); - dcpext_scanout_invalidate(dcp); - } if (dptx_service_available(&dcp->dptxport[port]) && dcp->dptxport[port].connected) { /* * A T8132 dcpext's DRM swaps stop with the route, before @@ -7875,8 +7866,7 @@ static const char *dcp_external_sleep_vetoed(struct apple_dcp *dcp) if (!dcp->external_native) return (atomic_read(&dcp->external_requested) || - (dcp->rtk && apple_rtkit_is_running(dcp->rtk)) || - dcpext_scanout_requested(dcp)) ? + (dcp->rtk && apple_rtkit_is_running(dcp->rtk))) ? "external firmware/scanout attempted" : NULL; why = iomfb_v14_7_external_busy(dcp); if (why) diff --git a/drivers/gpu/drm/apple/dcpext_drm.c b/drivers/gpu/drm/apple/dcpext_drm.c deleted file mode 100644 index 1d9981b5def3f..0000000000000 --- a/drivers/gpu/drm/apple/dcpext_drm.c +++ /dev/null @@ -1,486 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only OR MIT -/* Fixed iBoot mode, CPU shadow updates, optionally synchronized buffer swaps. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "dcp.h" -#include "dcpext_mode.h" -#include "dcpext_drm.h" -#include "dcpext_scanout.h" - -#define EXT_WIDTH DCPEXT_WIDTH -#define EXT_HEIGHT DCPEXT_HEIGHT -#define EXT_STRIDE DCPEXT_STRIDE -#define EXT_TILE_SIZE 32 -#define EXT_TILE_COLS DIV_ROUND_UP(EXT_WIDTH, EXT_TILE_SIZE) -#define EXT_TILE_ROWS DIV_ROUND_UP(EXT_HEIGHT, EXT_TILE_SIZE) -#define EXT_TILE_COUNT (EXT_TILE_COLS * EXT_TILE_ROWS) - -struct dcpext_drm { - struct drm_device drm; - struct drm_plane plane; - struct drm_crtc crtc; - struct drm_encoder encoder; - struct drm_connector connector; - void *pixels; - size_t size; - u32 stride; - struct apple_dcp *dcp; - bool pageflips; - u8 *row; - /* Damage from the last completed frame; the idle buffer is one older. */ - DECLARE_BITMAP(previous_damage, EXT_TILE_COUNT); - DECLARE_BITMAP(current_damage, EXT_TILE_COUNT); - DECLARE_BITMAP(copy_damage, EXT_TILE_COUNT); - bool damage_valid; - /* Owned by the retained scanout, never by the detachable parent device. */ - atomic_t *terminal_error; -}; - -/* The firmware selected this geometry/rate; timing changes are not supported. */ -static const struct drm_display_mode ext_mode = { - DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED, - 594000, 3840, 4016, 4104, 4400, 0, - 2160, 2168, 2178, 2250, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) -}; - -static bool ext_rect_valid(int x1, int y1, int x2, int y2, u32 pitch, size_t size) -{ - u64 end; - - if (x1 < 0 || y1 < 0 || x2 <= x1 || y2 <= y1 || - x2 > EXT_WIDTH || y2 > EXT_HEIGHT || pitch < EXT_STRIDE) - return false; - end = (u64)(y2 - 1) * pitch + (u64)x2 * 4; - return end <= size; -} - -static int ext_plane_check(struct drm_plane *plane, struct drm_atomic_commit *state) -{ - struct drm_plane_state *ps = drm_atomic_get_new_plane_state(state, plane); - struct drm_crtc_state *cs = NULL; - struct drm_gem_object *obj; - int ret; - - if (ps->crtc) - cs = drm_atomic_get_new_crtc_state(state, ps->crtc); - ret = drm_atomic_helper_check_plane_state(ps, cs, DRM_PLANE_NO_SCALING, - DRM_PLANE_NO_SCALING, false, false); - if (ret || !ps->visible) - return ret; - if (atomic_read(container_of(plane->dev, struct dcpext_drm, drm)->terminal_error)) - return -ENOLINK; - /* Keep source/destination coordinates identical for bounded damage copies. */ - if (ps->src_x || ps->src_y || ps->src_w != EXT_WIDTH << 16 || - ps->src_h != EXT_HEIGHT << 16 || ps->crtc_x || ps->crtc_y || - ps->crtc_w != EXT_WIDTH || ps->crtc_h != EXT_HEIGHT || - ps->fb->format->format != DRM_FORMAT_XRGB8888) - return -EINVAL; - obj = drm_gem_fb_get_obj(ps->fb, 0); - if (!obj || ps->fb->offsets[0] > obj->size || - !ext_rect_valid(0, 0, EXT_WIDTH, EXT_HEIGHT, ps->fb->pitches[0], - obj->size - ps->fb->offsets[0])) - return -EINVAL; - return 0; -} - -/* A failed copy/firmware transaction must not become a successful fake flip. */ -static void ext_cancel_flip(struct dcpext_drm *ext, struct drm_atomic_commit *state, int error) -{ - struct drm_crtc_state *cs = drm_atomic_get_new_crtc_state(state, &ext->crtc); - struct drm_pending_vblank_event *event; - unsigned long flags; - - if (!cs) - return; - spin_lock_irqsave(&ext->drm.event_lock, flags); - event = cs->event; - cs->event = NULL; - spin_unlock_irqrestore(&ext->drm.event_lock, flags); - if (!event) - return; - if (event->base.fence) { - dma_fence_set_error(event->base.fence, error); - dma_fence_signal(event->base.fence); - } - if (event->base.completion) { - complete_all(event->base.completion); - if (event->base.completion_release) - event->base.completion_release(event->base.completion); - event->base.completion = NULL; - } - drm_event_cancel_free(&ext->drm, &event->base); -} - -/* Bound history storage without merging distant clips into one large box. - * A tile conservatively includes unchanged edge pixels, never omits damage. - * Scratch maps are protected by the retained scanout's presentation lock. - */ -static void ext_damage_tiles(struct dcpext_drm *ext, struct drm_plane_state *old, - struct drm_plane_state *ps) -{ - struct drm_atomic_helper_damage_iter iter; - struct drm_rect bounds = DRM_RECT_INIT(0, 0, EXT_WIDTH, EXT_HEIGHT); - struct drm_rect damage; - unsigned int x1, x2, y, y2; - - if (!ext->damage_valid) { - bitmap_fill(ext->current_damage, EXT_TILE_COUNT); - return; - } - bitmap_zero(ext->current_damage, EXT_TILE_COUNT); - drm_atomic_helper_damage_iter_init(&iter, old, ps); - drm_atomic_for_each_plane_damage(&iter, &damage) { - if (!drm_rect_intersect(&damage, &bounds)) - continue; - x1 = damage.x1 / EXT_TILE_SIZE; - x2 = DIV_ROUND_UP(damage.x2, EXT_TILE_SIZE); - y2 = DIV_ROUND_UP(damage.y2, EXT_TILE_SIZE); - for (y = damage.y1 / EXT_TILE_SIZE; y < y2; y++) - bitmap_set(ext->current_damage, y * EXT_TILE_COLS + x1, x2 - x1); - } -} - -static void ext_copy_rect(struct dcpext_drm *ext, struct drm_plane_state *ps, - const struct dcpext_frame *frame, const struct drm_rect *copy) -{ - struct drm_shadow_plane_state *shadow = to_drm_shadow_plane_state(ps); - struct drm_framebuffer *fb = ps->fb; - int x, y; - - for (y = copy->y1; y < copy->y2; y++) { - size_t offset = (size_t)y * fb->pitches[0] + copy->x1 * 4; - size_t bytes = drm_rect_width(copy) * 4; - u8 *dst = frame->pixels + (size_t)y * ext->stride + copy->x1 * 4; - - iosys_map_memcpy_from(ext->row, &shadow->data[0], offset, bytes); - for (x = 0; x < drm_rect_width(copy); x++) - ext->row[x * 4 + 3] = 0xff; - /* Convert in cached memory, then stream to coherent scanout memory. - * Byte stores directly to that mapping make full 4K copies costly. - */ - memcpy(dst, ext->row, bytes); - } -} - -static int ext_copy_frame(struct dcpext_drm *ext, struct drm_plane_state *old, - struct drm_plane_state *ps) -{ - struct dcpext_frame frame; - unsigned int row, first, end, bit, next; - int ret; - - ret = dcpext_scanout_begin_frame(ext->dcp, &frame); - if (ret) - return ret; - if (!ext_rect_valid(0, 0, EXT_WIDTH, EXT_HEIGHT, ext->stride, frame.size)) { - dcpext_scanout_end_frame(ext->dcp, false); - return -EINVAL; - } - /* The idle buffer contains frame N-2. Repair both N-1's damage and the - * current damage from the current framebuffer, without touching scanout. - * Invalid history forces two complete copies, initializing both buffers. - */ - ext_damage_tiles(ext, old, ps); - if (ext->damage_valid) - bitmap_or(ext->copy_damage, ext->current_damage, - ext->previous_damage, EXT_TILE_COUNT); - else - bitmap_copy(ext->copy_damage, ext->current_damage, EXT_TILE_COUNT); - for (row = 0; row < EXT_TILE_ROWS; row++) { - first = row * EXT_TILE_COLS; - end = first + EXT_TILE_COLS; - bit = find_next_bit(ext->copy_damage, end, first); - while (bit < end) { - struct drm_rect copy; - - next = find_next_zero_bit(ext->copy_damage, end, bit); - copy.x1 = (bit - first) * EXT_TILE_SIZE; - copy.x2 = min((next - first) * EXT_TILE_SIZE, EXT_WIDTH); - copy.y1 = row * EXT_TILE_SIZE; - copy.y2 = min((row + 1) * EXT_TILE_SIZE, EXT_HEIGHT); - ext_copy_rect(ext, ps, &frame, ©); - bit = find_next_bit(ext->copy_damage, end, next); - } - } - ret = dcpext_scanout_end_frame(ext->dcp, true); - /* Ordered atomic commits advance history only after a completed swap. */ - if (!ret) { - bitmap_copy(ext->previous_damage, ext->current_damage, EXT_TILE_COUNT); - ext->damage_valid = true; - } - return ret; -} - -static void ext_plane_update(struct drm_plane *plane, struct drm_atomic_commit *state) -{ - struct dcpext_drm *ext = container_of(plane->dev, struct dcpext_drm, drm); - struct drm_plane_state *ps = drm_atomic_get_new_plane_state(state, plane); - struct drm_plane_state *old = drm_atomic_get_old_plane_state(state, plane); - struct drm_shadow_plane_state *shadow = to_drm_shadow_plane_state(ps); - struct drm_framebuffer *fb = ps->fb; - struct drm_gem_object *obj; - struct drm_atomic_helper_damage_iter iter; - struct drm_rect damage, bounds = DRM_RECT_INIT(0, 0, EXT_WIDTH, EXT_HEIGHT); - int idx, x, y, ret; - - if (!ps->visible || !fb) - return; - ret = atomic_read(ext->terminal_error); - if (ret) - goto cancel; - obj = drm_gem_fb_get_obj(fb, 0); - ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); - if (ret) - goto cancel; - if (!drm_dev_enter(plane->dev, &idx)) { - ret = -ENODEV; - goto end_access; - } - if (ext->pageflips) { - ret = ext_copy_frame(ext, old, ps); - goto exit_device; - } - drm_atomic_helper_damage_iter_init(&iter, old, ps); - drm_atomic_for_each_plane_damage(&iter, &damage) { - if (!drm_rect_intersect(&damage, &bounds)) - continue; - if (WARN_ON_ONCE(!obj || fb->offsets[0] > obj->size || - !ext_rect_valid(damage.x1, damage.y1, damage.x2, damage.y2, - fb->pitches[0], obj->size - fb->offsets[0]) || - !ext_rect_valid(damage.x1, damage.y1, damage.x2, damage.y2, - ext->stride, ext->size))) - continue; - for (y = damage.y1; y < damage.y2; ++y) { - u8 *dst = ext->pixels + (size_t)y * ext->stride + damage.x1 * 4; - - iosys_map_memcpy_from(dst, &shadow->data[0], - (size_t)y * fb->pitches[0] + damage.x1 * 4, - (damage.x2 - damage.x1) * 4); - /* Firmware BGRA requires opaque alpha; XRGB's X is undefined. */ - for (x = 0; x < damage.x2 - damage.x1; ++x) - dst[x * 4 + 3] = 0xff; - } - } - dma_wmb(); -exit_device: - drm_dev_exit(idx); -end_access: - drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); -cancel: - if (ext->pageflips && ret) - ext_cancel_flip(ext, state, ret); -} - -static void ext_plane_disable(struct drm_plane *plane, struct drm_atomic_commit *state) -{ - struct dcpext_drm *ext = container_of(plane->dev, struct dcpext_drm, drm); - u32 *dst = ext->pixels; - struct dcpext_frame frame; - int idx, i, ret; - - ret = atomic_read(ext->terminal_error); - if (ret || !drm_dev_enter(plane->dev, &idx)) { - if (ext->pageflips) - ext_cancel_flip(ext, state, ret ? ret : -ENODEV); - return; - } - if (ext->pageflips) { - ext->damage_valid = false; - ret = dcpext_scanout_begin_frame(ext->dcp, &frame); - if (ret) { - ext_cancel_flip(ext, state, ret); - goto exit_device; - } - dst = frame.pixels; - } - for (i = 0; i < EXT_WIDTH * EXT_HEIGHT; ++i) - dst[i] = cpu_to_le32(0xff000000); - dma_wmb(); - if (ext->pageflips) { - ret = dcpext_scanout_end_frame(ext->dcp, true); - if (ret) - ext_cancel_flip(ext, state, ret); - } -exit_device: - drm_dev_exit(idx); -} - -static const struct drm_plane_funcs ext_plane_funcs = { - DRM_GEM_SHADOW_PLANE_FUNCS, - .update_plane = drm_atomic_helper_update_plane, - .disable_plane = drm_atomic_helper_disable_plane, - .destroy = drm_plane_cleanup, -}; -static const struct drm_plane_helper_funcs ext_plane_helpers = { - DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, - .atomic_check = ext_plane_check, - .atomic_update = ext_plane_update, - .atomic_disable = ext_plane_disable, -}; -static enum drm_mode_status ext_mode_valid(struct drm_crtc *crtc, - const struct drm_display_mode *mode) -{ - return drm_mode_equal(mode, &ext_mode) ? MODE_OK : MODE_BAD; -} -static int ext_crtc_check(struct drm_crtc *crtc, struct drm_atomic_commit *state) -{ - struct drm_crtc_state *cs = drm_atomic_get_new_crtc_state(state, crtc); - - return cs->enable ? drm_atomic_helper_check_crtc_primary_plane(cs) : 0; -} -static const struct drm_crtc_funcs ext_crtc_funcs = { - .reset = drm_atomic_helper_crtc_reset, - .set_config = drm_atomic_helper_set_config, - .page_flip = drm_atomic_helper_page_flip, - .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, - .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, - .destroy = drm_crtc_cleanup, -}; -static const struct drm_crtc_helper_funcs ext_crtc_helpers = { - .mode_valid = ext_mode_valid, - .atomic_check = ext_crtc_check, -}; -static int ext_get_modes(struct drm_connector *connector) -{ - return drm_connector_helper_get_modes_fixed(connector, &ext_mode); -} -static enum drm_connector_status ext_detect(struct drm_connector *connector, bool force) -{ - struct dcpext_drm *ext = container_of(connector->dev, struct dcpext_drm, drm); - - return atomic_read(ext->terminal_error) ? connector_status_disconnected : - connector_status_connected; -} -static const struct drm_connector_funcs ext_connector_funcs = { - .reset = drm_atomic_helper_connector_reset, - .fill_modes = drm_helper_probe_single_connector_modes, - .detect = ext_detect, - .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, - .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, - .destroy = drm_connector_cleanup, -}; -static const struct drm_connector_helper_funcs ext_connector_helpers = { - .get_modes = ext_get_modes, -}; -static const struct drm_encoder_funcs ext_encoder_funcs = { - .destroy = drm_encoder_cleanup, -}; -static const struct drm_mode_config_funcs ext_mode_funcs = { - .fb_create = drm_gem_fb_create_with_dirty, - .atomic_check = drm_atomic_helper_check, - .atomic_commit = drm_atomic_helper_commit, -}; -DEFINE_DRM_GEM_FOPS(ext_fops); -static const struct drm_driver ext_driver = { - DRM_GEM_SHMEM_DRIVER_OPS, - .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC, - .fops = &ext_fops, - .name = "apple-dcpext-shadow", - .desc = "Apple external fixed iBoot shadow scanout", - .major = 1, - .minor = 0, -}; - -static void ext_unregister(void *data) -{ - struct drm_device *drm = data; - - drm_dev_unplug(drm); - drm_atomic_helper_shutdown(drm); -} - -int dcpext_drm_register(struct apple_dcp *dcp, void *pixels, size_t size, u32 stride, - atomic_t *terminal_error, struct drm_device **retained_drm) -{ - static const u32 formats[] = { DRM_FORMAT_XRGB8888 }; - static const u64 modifiers[] = { DRM_FORMAT_MOD_LINEAR, DRM_FORMAT_MOD_INVALID }; - struct dcpext_drm *ext; - struct drm_device *drm; - int ret; - - if (!terminal_error || !retained_drm || atomic_read(terminal_error) || !pixels || !IS_ALIGNED((unsigned long)pixels, 4) || stride != EXT_STRIDE || - !ext_rect_valid(0, 0, EXT_WIDTH, EXT_HEIGHT, stride, size)) - return -EINVAL; - ext = devm_drm_dev_alloc(dcp->dev, &ext_driver, struct dcpext_drm, drm); - if (IS_ERR(ext)) - return PTR_ERR(ext); - drm = &ext->drm; - ext->pixels = pixels; - ext->size = size; - ext->stride = stride; - ext->terminal_error = terminal_error; - ext->dcp = dcp; - ext->pageflips = dcpext_scanout_pageflips(dcp); - if (ext->pageflips) { - ext->row = drmm_kmalloc(drm, EXT_STRIDE, GFP_KERNEL); - if (!ext->row) - return -ENOMEM; - } - ret = drmm_mode_config_init(drm); - if (ret) - return ret; - drm->mode_config.min_width = EXT_WIDTH; - drm->mode_config.max_width = EXT_WIDTH; - drm->mode_config.min_height = EXT_HEIGHT; - drm->mode_config.max_height = EXT_HEIGHT; - drm->mode_config.preferred_depth = 24; - drm->mode_config.funcs = &ext_mode_funcs; - ret = drm_universal_plane_init(drm, &ext->plane, 0, &ext_plane_funcs, - formats, ARRAY_SIZE(formats), modifiers, DRM_PLANE_TYPE_PRIMARY, NULL); - if (ret) - return ret; - drm_plane_helper_add(&ext->plane, &ext_plane_helpers); - drm_plane_enable_fb_damage_clips(&ext->plane); - ret = drm_crtc_init_with_planes(drm, &ext->crtc, &ext->plane, NULL, - &ext_crtc_funcs, NULL); - if (ret) - return ret; - drm_crtc_helper_add(&ext->crtc, &ext_crtc_helpers); - ret = drm_encoder_init(drm, &ext->encoder, &ext_encoder_funcs, - DRM_MODE_ENCODER_TMDS, NULL); - if (ret) - return ret; - ext->encoder.possible_crtcs = drm_crtc_mask(&ext->crtc); - ret = drm_connector_init(drm, &ext->connector, &ext_connector_funcs, - DRM_MODE_CONNECTOR_DisplayPort); - if (ret) - return ret; - drm_connector_helper_add(&ext->connector, &ext_connector_helpers); - ret = drm_connector_attach_encoder(&ext->connector, &ext->encoder); - if (ret) - return ret; - drm_mode_config_reset(drm); - /* No vblank IRQ: the helper timestamps completion in software. In pageflip - * mode the copy/commit also waits for firmware completion before this event; - * the legacy single-buffer mode remains unsynchronized and may tear. - * Deliberately no fbdev/client setup, console takeover, or render node. - */ - ret = drm_dev_register(drm, 0); - if (ret) - return ret; - ret = devm_add_action_or_reset(dcp->dev, ext_unregister, drm); - if (ret) - return ret; - /* Keep notification work safe even after parent devres teardown. */ - drm_dev_get(drm); - WRITE_ONCE(*retained_drm, drm); - dev_info(dcp->dev, "external shadow DRM registered: fixed 3840x2160, CPU copies, %s\n", - ext->pageflips ? "firmware-completed double-buffer swaps" : "no hardware vblank"); - return 0; -} diff --git a/drivers/gpu/drm/apple/dcpext_drm.h b/drivers/gpu/drm/apple/dcpext_drm.h deleted file mode 100644 index e9ef1db3d96af..0000000000000 --- a/drivers/gpu/drm/apple/dcpext_drm.h +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ -#ifndef __APPLE_DCPEXT_DRM_H__ -#define __APPLE_DCPEXT_DRM_H__ -#include -#include -struct apple_dcp; -struct drm_device; -/* Caller retains the already-scanning buffer and serializes one registration. */ -int dcpext_drm_register(struct apple_dcp *dcp, void *pixels, size_t size, u32 stride, - atomic_t *terminal_error, struct drm_device **retained_drm); -#endif diff --git a/drivers/gpu/drm/apple/dcpext_scanout.c b/drivers/gpu/drm/apple/dcpext_scanout.c deleted file mode 100644 index e652b8ac207a0..0000000000000 --- a/drivers/gpu/drm/apple/dcpext_scanout.c +++ /dev/null @@ -1,829 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only OR MIT -/* Local T6030 external first-pixel diagnostic. No automatic scanout startup. */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dcp.h" -#include "dcpext_mode.h" -#include "dcpext_scanout.h" -#include "dcpext_drm.h" -#include "ibootep.h" - -#define SCANOUT_WIDTH DCPEXT_WIDTH -#define SCANOUT_HEIGHT DCPEXT_HEIGHT -#define SCANOUT_STRIDE DCPEXT_STRIDE -#define SCANOUT_IOVA_BASE (1ULL << 40) -#define SCANOUT_IOVA_SIZE (1ULL << 36) - -static bool dcpext_pageflip; -module_param(dcpext_pageflip, bool, 0444); -MODULE_PARM_DESC(dcpext_pageflip, "Use two retained external buffers and wait for firmware swap completion"); - -/* - * Some docks and monitors drop HPD once shortly after the first mode is set and - * bring it back within a second or two. Tolerate exactly one such bounce after - * the first pattern: hold the retained buffer, wait for the link to return, and - * send the pattern commands again. - * - * A link loss that outlasts the bounce (the dock was unplugged) parks the - * scanout: it latches -ENOLINK, so the desktop sees a disconnect, but the - * retained buffer and the firmware session stay as they were. When a dock - * brings the link back, the pattern commands are sent again exactly as after a - * bounce, and the new link gets its own bounce allowance. Any other error, or a - * link loss before the first pattern was accepted, is terminal until reboot. - */ -#define SCANOUT_BOUNCE_GRACE_MS 10000 -#define SCANOUT_REPATTERN_DELAY_MS 1500 -enum { SCANOUT_BOUNCE_NONE, SCANOUT_BOUNCE_PENDING, SCANOUT_BOUNCE_USED }; - -struct dcpext_scanout { - struct apple_dcp *dcp; - struct device *firmware_dev; - struct device_node *node; - struct platform_device *pdev; - struct iommu_group *group; - struct iommu_domain *firmware_domain; - struct iommu_domain *scanout_domain; - void *pixels; - dma_addr_t iova; - size_t size; - size_t frame_size; - bool pageflips; - unsigned int front; - struct mutex present_lock; - u64 frames_completed; - u64 present_ns_max; - size_t mapped; - struct sg_table sgt; - struct work_struct work; - struct work_struct desktop_work; - atomic_t desktop_requested; - atomic_t terminal_error; - bool desktop_registered; - struct drm_device *retained_drm; - struct work_struct invalidate_work; - bool pattern_ready; - atomic_t requested; - atomic_t bounce; /* SCANOUT_BOUNCE_* */ - struct delayed_work bounce_work; - struct delayed_work repattern_work; - bool reattached; /* the desktop saw a disconnect before this restore */ - bool stopping; - bool published; /* Firmware callbacks may retain this object until reboot. */ - struct device_attribute attr; - struct device_attribute desktop_attr; - struct device_attribute status_attr; - struct device_attribute present_attr; - struct attribute *attrs[5]; - struct attribute_group attr_group; -}; - -static void dcpext_invalidate_work(struct work_struct *work) -{ - struct dcpext_scanout *scanout = container_of(work, struct dcpext_scanout, invalidate_work); - struct drm_device *drm = READ_ONCE(scanout->retained_drm); - - /* Never notify while holding the Type-C fabric or HPD locks. */ - if (drm && !READ_ONCE(scanout->stopping)) - drm_kms_helper_hotplug_event(drm); -} - -static void scanout_fail(struct dcpext_scanout *scanout, int error) -{ - if (READ_ONCE(scanout->stopping)) - return; - if (error >= 0 || (scanout->pageflips && error == -ENOLINK)) - error = -EIO; - if (!atomic_cmpxchg(&scanout->terminal_error, 0, error)) - schedule_work(&scanout->invalidate_work); -} - -bool dcpext_scanout_requested(struct apple_dcp *dcp) -{ - struct dcpext_scanout *scanout = smp_load_acquire(&dcp->dcpext_scanout); - - return scanout && atomic_read(&scanout->requested); -} - -/* Unplugged after the first pattern: the link is gone, nothing else is lost. */ -static bool scanout_parked(struct dcpext_scanout *scanout) -{ - return atomic_read(&scanout->terminal_error) == -ENOLINK && - smp_load_acquire(&scanout->pattern_ready); -} - -/* True when the scanout can never be used again. A parked scanout is not: the - * next dock may route a tunnel and bring its link up to restore it. */ -bool dcpext_scanout_terminal(struct apple_dcp *dcp) -{ - struct dcpext_scanout *scanout = smp_load_acquire(&dcp->dcpext_scanout); - - return scanout && atomic_read(&scanout->terminal_error) && !scanout_parked(scanout); -} - -void dcpext_scanout_fault(struct apple_dcp *dcp, int error) -{ - struct dcpext_scanout *scanout = smp_load_acquire(&dcp->dcpext_scanout); - - if (scanout) - scanout_fail(scanout, error); -} - -void dcpext_scanout_invalidate(struct apple_dcp *dcp) -{ - struct dcpext_scanout *scanout = smp_load_acquire(&dcp->dcpext_scanout); - - /* Initial unplug remains allowed; only a started scanout owns DMA. */ - if (!scanout || !atomic_read(&scanout->requested)) - return; - /* Link loss can race a submitted swap. Until recovery also accounts for - * its completion, keep both buffers and require a fresh boot in this mode. - */ - if (scanout->pageflips) { - scanout_fail(scanout, -EIO); - return; - } - /* The desktop reuses the pattern's retained buffer, so the same restore - * covers a bounce before or after desktop registration. */ - if (smp_load_acquire(&scanout->pattern_ready)) { - int prev = atomic_cmpxchg(&scanout->bounce, SCANOUT_BOUNCE_NONE, SCANOUT_BOUNCE_PENDING); - - if (prev == SCANOUT_BOUNCE_NONE) { - dev_info(scanout->firmware_dev, "external link lost after the first pattern; waiting up to %u ms for it to return\n", - SCANOUT_BOUNCE_GRACE_MS); - schedule_delayed_work(&scanout->bounce_work, msecs_to_jiffies(SCANOUT_BOUNCE_GRACE_MS)); - return; - } - /* Re-routing the returning tunnel disconnects the port once more - * before reconnecting it; that is still the same bounce. */ - if (prev == SCANOUT_BOUNCE_PENDING) - return; - if (!atomic_read(&scanout->terminal_error)) - dev_info(scanout->firmware_dev, "external link lost again; scanout parked until a dock brings it back\n"); - } - scanout_fail(scanout, -ENOLINK); -} - -static void dcpext_bounce_timeout(struct work_struct *work) -{ - struct dcpext_scanout *scanout = - container_of(to_delayed_work(work), struct dcpext_scanout, bounce_work); - - if (atomic_cmpxchg(&scanout->bounce, SCANOUT_BOUNCE_PENDING, SCANOUT_BOUNCE_USED) != - SCANOUT_BOUNCE_PENDING) - return; - dev_info(scanout->firmware_dev, "external link did not return within %u ms; scanout parked until a dock brings it back\n", - SCANOUT_BOUNCE_GRACE_MS); - scanout_fail(scanout, -ENOLINK); -} - -static void dcpext_repattern_work(struct work_struct *work) -{ - struct dcpext_scanout *scanout = - container_of(to_delayed_work(work), struct dcpext_scanout, repattern_work); - int ret; - - if (READ_ONCE(scanout->stopping) || atomic_read(&scanout->terminal_error)) - return; - ret = ibootep_rearm_pattern(scanout->dcp); - if (!ret) - ret = ibootep_present_pattern(scanout->dcp, scanout->iova, scanout->size, SCANOUT_STRIDE); - if (ret) { - scanout_fail(scanout, ret); - dev_err(scanout->firmware_dev, "external pattern not restored after the link returned: %d; resources retained until reboot\n", - ret); - return; - } - if (xchg(&scanout->reattached, false)) { - dev_info(scanout->firmware_dev, "external pattern restored after an unplug\n"); - schedule_work(&scanout->invalidate_work); - return; - } - dev_info(scanout->firmware_dev, "external pattern restored after one hotplug bounce\n"); -} - -/* Caller holds hpd_mutex; the external link has just become ready again. */ -void dcpext_scanout_link_restored(struct apple_dcp *dcp) -{ - struct dcpext_scanout *scanout = smp_load_acquire(&dcp->dcpext_scanout); - - if (!scanout || scanout->pageflips || READ_ONCE(scanout->stopping)) - return; - if (atomic_cmpxchg(&scanout->bounce, SCANOUT_BOUNCE_PENDING, SCANOUT_BOUNCE_USED) == - SCANOUT_BOUNCE_PENDING) { - cancel_delayed_work(&scanout->bounce_work); - dev_info(scanout->firmware_dev, "external link returned; sending the pattern commands again\n"); - } else if (scanout_parked(scanout) && - atomic_cmpxchg(&scanout->terminal_error, -ENOLINK, 0) == -ENOLINK) { - /* The desktop only copies into the retained buffer, so it may see - * the connector again before the pattern commands go out. */ - atomic_set(&scanout->bounce, SCANOUT_BOUNCE_NONE); - WRITE_ONCE(scanout->reattached, true); - dev_info(scanout->firmware_dev, "external link up again after an unplug; sending the pattern commands again\n"); - } else { - return; - } - queue_delayed_work(system_dfl_wq, &scanout->repattern_work, - msecs_to_jiffies(SCANOUT_REPATTERN_DELAY_MS)); -} - -static bool scanout_link_ready(struct dcpext_scanout *scanout) -{ - struct apple_dcp *dcp = scanout->dcp; - - return !READ_ONCE(dcp->crashed) && !atomic_read(&scanout->terminal_error) && - smp_load_acquire(&dcp->external_link_ready) && - (!READ_ONCE(dcp->dptx_tunnel) || READ_ONCE(dcp->tb_clock_ok)) && - READ_ONCE(dcp->typec_cable_connected) && - READ_ONCE(dcp->dptxport[0].connected) && - READ_ONCE(dcp->dptxport[0].enabled); -} - -bool dcpext_scanout_pageflips(struct apple_dcp *dcp) -{ - /* Pair with publication of the initialized scanout in register(). */ - struct dcpext_scanout *scanout = smp_load_acquire(&dcp->dcpext_scanout); - - return scanout && scanout->pageflips; -} - -int dcpext_scanout_begin_frame(struct apple_dcp *dcp, struct dcpext_frame *frame) -{ - /* Pair with register(); drm_dev_enter() protects the parent lifetime. */ - struct dcpext_scanout *scanout = smp_load_acquire(&dcp->dcpext_scanout); - - if (!scanout || !scanout->pageflips) - return -EOPNOTSUPP; - mutex_lock(&scanout->present_lock); - /* Observe the buffers/mappings published before pattern_ready. */ - if (READ_ONCE(scanout->stopping) || !scanout_link_ready(scanout) || - !smp_load_acquire(&scanout->pattern_ready)) { - mutex_unlock(&scanout->present_lock); - return -ENOLINK; - } - frame->pixels = scanout->pixels + (scanout->front ^ 1) * scanout->frame_size; - frame->size = scanout->frame_size; - return 0; -} - -int dcpext_scanout_end_frame(struct apple_dcp *dcp, bool present) -{ - /* Same publication/lifetime protection as begin_frame(). */ - struct dcpext_scanout *scanout = smp_load_acquire(&dcp->dcpext_scanout); - unsigned int next = scanout->front ^ 1; - u64 start; - int ret = 0; - - lockdep_assert_held(&scanout->present_lock); - if (!present) - goto out; - if (READ_ONCE(scanout->stopping) || !scanout_link_ready(scanout)) { - ret = -ENOLINK; - goto out; - } - dma_wmb(); - start = ktime_get_ns(); - ret = ibootep_present_frame(dcp, scanout->iova + next * scanout->frame_size, - scanout->frame_size, SCANOUT_STRIDE); - if (ret) { - /* Even -ENOLINK from a presentation command is uncertain DMA state; - * use a terminal error that the hotplug restore path cannot clear. - */ - scanout_fail(scanout, -EIO); - goto out; - } - scanout->front = next; - scanout->frames_completed++; - scanout->present_ns_max = max(scanout->present_ns_max, ktime_get_ns() - start); -out: - mutex_unlock(&scanout->present_lock); - return ret; -} - -static ssize_t dcpext_present_show(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct dcpext_scanout *scanout = container_of(attr, struct dcpext_scanout, present_attr); - - return sysfs_emit(buf, "pageflips=%u buffers=%u completed=%llu front=%u wait_max_us=%llu\n", - scanout->pageflips, scanout->pageflips ? 2 : 1, - READ_ONCE(scanout->frames_completed), READ_ONCE(scanout->front), - READ_ONCE(scanout->present_ns_max) / NSEC_PER_USEC); -} - -static ssize_t dcpext_status_show(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct dcpext_scanout *scanout = container_of(attr, struct dcpext_scanout, status_attr); - bool requested = atomic_read(&scanout->requested); - bool ready = smp_load_acquire(&scanout->pattern_ready); - bool desktop_requested = atomic_read(&scanout->desktop_requested); - bool registered = smp_load_acquire(&scanout->desktop_registered); - int error = atomic_read(&scanout->terminal_error); - bool fw_ready = !READ_ONCE(scanout->dcp->crashed) && scanout->dcp->rtk && apple_rtkit_is_running(scanout->dcp->rtk) && - ibootep_is_ready(scanout->dcp) && - smp_load_acquire(&scanout->dcp->dptxport[0].enabled); - const char *phase = error == -ENOLINK && ready ? "parked" : error ? "terminal" : - registered ? "desktop_registered" : - desktop_requested ? "desktop_pending" : ready ? "pattern_ready" : - requested ? "pattern_pending" : "ready"; - - return sysfs_emit(buf, "schema=1 phase=%s fw_ready=%u pattern_requested=%u pattern_ready=%u desktop_requested=%u desktop_registered=%u terminal_error=%d link_ready=%u width=%u height=%u stride=%u\n", - phase, fw_ready, requested, ready, desktop_requested, registered, error, - scanout_link_ready(scanout), SCANOUT_WIDTH, SCANOUT_HEIGHT, SCANOUT_STRIDE); -} - -static bool scanout_iova_valid(u64 iova, size_t size) -{ - return size && IS_ALIGNED(iova, SZ_16K) && IS_ALIGNED(size, SZ_16K) && - iova >= SCANOUT_IOVA_BASE && size <= SCANOUT_IOVA_SIZE && - iova - SCANOUT_IOVA_BASE <= SCANOUT_IOVA_SIZE - size; -} - -static void scanout_fill_pattern(void *pixels, size_t size) -{ - static const u32 bars[] = { - 0xffffffff, 0xffffff00, 0xff00ffff, 0xff00ff00, - 0xffff00ff, 0xffff0000, 0xff0000ff, 0xff000000, - }; - __le32 *pixel = pixels; - u32 x, y; - - memset(pixels, 0, size); - for (y = 0; y < SCANOUT_HEIGHT; y++) - for (x = 0; x < SCANOUT_WIDTH; x++) - pixel[y * SCANOUT_WIDTH + x] = - cpu_to_le32(bars[x / (SCANOUT_WIDTH / ARRAY_SIZE(bars))]); -} - -/* Before mapping, require a hole in scanout and the expected firmware mapping. - * Afterwards, require both DART domains to resolve every 16K page identically. - * SG addresses describe physical backing, never DMA addresses from another map. - */ -static int scanout_verify_buffer(struct dcpext_scanout *scanout, bool mapped) -{ - struct scatterlist *sg; - size_t total = 0, off; - unsigned int i; - - if (!scanout_iova_valid(scanout->iova, scanout->size)) - return -ERANGE; - for_each_sg(scanout->sgt.sgl, sg, scanout->sgt.orig_nents, i) { - phys_addr_t phys = sg_phys(sg); - size_t length = sg->length; - - if (!phys || !length || !IS_ALIGNED(phys, SZ_16K) || - !IS_ALIGNED(length, SZ_16K) || length > scanout->size - total) - return -EINVAL; - for (off = 0; off < length; off += SZ_16K) { - u64 iova = scanout->iova + total + off; - phys_addr_t firmware = iommu_iova_to_phys(scanout->firmware_domain, iova); - phys_addr_t display = iommu_iova_to_phys(scanout->scanout_domain, iova); - - if (firmware != phys + off) - return -EFAULT; - if (mapped ? display != firmware : display != 0) - return mapped ? -EFAULT : -EBUSY; - } - total += length; - } - return total == scanout->size ? 0 : -EINVAL; -} - -static int scanout_map_buffer(struct dcpext_scanout *scanout) -{ - struct scatterlist *sg; - unsigned int i; - int ret; - - ret = scanout_verify_buffer(scanout, false); - if (ret) - return ret; - for_each_sg(scanout->sgt.sgl, sg, scanout->sgt.orig_nents, i) { - ret = iommu_map(scanout->scanout_domain, scanout->iova + scanout->mapped, - sg_phys(sg), sg->length, IOMMU_READ | IOMMU_WRITE, GFP_KERNEL); - if (ret) - return ret; - scanout->mapped += sg->length; - } - return scanout_verify_buffer(scanout, true); -} - -static bool scanout_node_verified(struct device_node *node) -{ - u32 marker; - - return node && of_device_is_available(node) && - of_device_is_compatible(node, "apple,t6030-dispext-scanout") && - !of_property_read_u32(node, "apple,t6030-dispext-handoff", &marker) && marker == 1 && - !of_property_read_u32(node, "apple,t6030-scanout-verified", &marker) && marker == 1; -} - -struct scanout_group_check { - struct device *expected; - unsigned int count; -}; - -static int scanout_group_member(struct device *dev, void *data) -{ - struct scanout_group_check *check = data; - - check->count++; - return dev == check->expected ? 0 : -EBUSY; -} - -static int scanout_check_domains(struct dcpext_scanout *scanout) -{ - struct device *dev = &scanout->pdev->dev; - struct scanout_group_check check = { .expected = dev }; - struct iommu_group *firmware_group; - int ret; - - /* These raw display mappings have no IOMMU_CACHE attribute. The tested - * firmware allocation is uncached coherent memory on a noncoherent device. - */ - if (dev_is_dma_coherent(scanout->firmware_dev) || dev_is_dma_coherent(dev)) - return -EOPNOTSUPP; - /* No driver or second DMA client may allocate addresses in this domain. */ - if (device_is_bound(dev)) - return -EBUSY; - scanout->firmware_domain = iommu_get_domain_for_dev(scanout->firmware_dev); - scanout->scanout_domain = iommu_get_domain_for_dev(dev); - if (IS_ERR_OR_NULL(scanout->firmware_domain) || IS_ERR_OR_NULL(scanout->scanout_domain) || - scanout->firmware_domain == scanout->scanout_domain || - !iommu_is_dma_domain(scanout->firmware_domain) || - !iommu_is_dma_domain(scanout->scanout_domain) || - !(scanout->scanout_domain->pgsize_bitmap & SZ_16K)) - return -EINVAL; - scanout->group = iommu_group_get(dev); - if (!scanout->group) - return -ENODEV; - firmware_group = iommu_group_get(scanout->firmware_dev); - ret = firmware_group && firmware_group != scanout->group ? 0 : -EBUSY; - if (firmware_group) - iommu_group_put(firmware_group); - if (ret) - return ret; - ret = iommu_group_for_each_dev(scanout->group, &check, scanout_group_member); - if (ret) - return ret; - return check.count == 1 ? 0 : -EBUSY; -} - -/* - * The early gate predates external firmware startup. Recheck immediately - * before attaching: neither firmware nor another client may have populated - * the inherited roots in the meantime. This function performs no MMIO writes. - */ -static int scanout_recheck_dart(struct device_node *dart, struct device_node *dcp) -{ - struct device_node *dart_pd, *dcp_pd; - struct resource regs, table, first = {}; - struct device_node *region = NULL; - struct reserved_mem *rmem; - void __iomem *mmio; - u32 state[6], marker; - u64 phys, size; - void *root; - int i, ret = -EINVAL; - - if (of_property_read_u32(dart, "apple,t6030-dispext-handoff", &marker) || marker != 1 || - of_property_count_u32_elems(dart, "apple,inherited-dart-state") != 6 || - of_property_read_u32_array(dart, "apple,inherited-dart-state", state, 6) || - state[0] != 0 || state[3] != 4 || - of_count_phandle_with_args(dart, "memory-region", NULL) != 2 || - of_address_to_resource(dart, 0, ®s) || resource_size(®s) != SZ_16K) - return -EINVAL; - /* The display DART of this processor's own pipe shares its CPU domain. */ - dart_pd = of_parse_phandle(dart, "power-domains", 0); - dcp_pd = of_parse_phandle(dcp, "power-domains", 0); - of_node_put(dart_pd); - of_node_put(dcp_pd); - if (!dart_pd || dart_pd != dcp_pd) - return -EINVAL; - mmio = ioremap(regs.start, resource_size(®s)); - if (!mmio) - return -ENOMEM; - if (!(readl(mmio + 0x200) & BIT(0))) - goto out; - for (i = 0; i < 2; i++) { - u32 sid = state[3 * i], tcr = state[3 * i + 1], ttbr = state[3 * i + 2]; - - ret = -EINVAL; - if ((tcr & (BIT(0) | BIT(1) | BIT(3))) != BIT(0) || !(ttbr & BIT(0)) || - (ttbr & ~(GENMASK(29, 2) | BIT(0))) || - readl(mmio + 0x1000 + 4 * sid) != tcr || - readl(mmio + 0x1400 + 4 * sid) != ttbr) - goto out; - phys = (u64)(ttbr & GENMASK(29, 2)) << 12; - region = of_parse_phandle(dart, "memory-region", i); - if (!region || !of_property_read_bool(region, "no-map") || - of_property_read_bool(region, "reusable") || - of_address_to_resource(region, 0, &table) || table.end < table.start) - goto out; - size = resource_size(&table); - rmem = of_reserved_mem_lookup(region); - if (!rmem || size < SZ_16K || size > SZ_1M || - !IS_ALIGNED(table.start, SZ_16K) || !IS_ALIGNED(size, SZ_16K) || - rmem->base != table.start || rmem->size != size || - phys < table.start || phys > table.end - SZ_16K + 1 || - (i && table.start <= first.end && first.start <= table.end)) - goto out; - if (!i) - first = table; - root = memremap(phys, SZ_16K, MEMREMAP_WB); - if (!root) { - ret = -ENOMEM; - goto out; - } - ret = memchr_inv(root, 0, SZ_16K) ? -EBUSY : 0; - memunmap(root); - if (ret) - goto out; - of_node_put(region); - region = NULL; - } -out: - of_node_put(region); - iounmap(mmio); - return ret; -} - -static int scanout_create_device(struct dcpext_scanout *scanout) -{ - struct of_phandle_args spec; - struct platform_device *existing; - int ret; - - if (PAGE_SIZE != SZ_16K || !scanout_node_verified(scanout->node)) - return -EINVAL; - if (of_count_phandle_with_args(scanout->node, "iommus", "#iommu-cells") != 1) - return -EINVAL; - ret = of_parse_phandle_with_args(scanout->node, "iommus", "#iommu-cells", 0, &spec); - if (ret) - return ret; - ret = spec.args_count == 1 && spec.args[0] == 0 && - of_device_is_compatible(spec.np, "apple,t8110-dart") && - of_device_is_available(spec.np) ? 0 : -EINVAL; - if (!ret) - ret = scanout_recheck_dart(spec.np, scanout->firmware_dev->of_node); - of_node_put(spec.np); - if (ret) - return ret; - existing = of_find_device_by_node(scanout->node); - if (existing) { - put_device(&existing->dev); - return -EBUSY; - } - scanout->pdev = of_platform_device_create(scanout->node, NULL, scanout->firmware_dev); - if (!scanout->pdev) - return -ENODEV; - /* Once attached, never destroy this consumer of the locked inherited DART. */ - ret = dma_set_mask_and_coherent(&scanout->pdev->dev, DMA_BIT_MASK(42)); - if (!ret) - ret = of_dma_configure(&scanout->pdev->dev, scanout->node, true); - if (ret) - return ret; - return scanout_check_domains(scanout); -} - -static void dcpext_pattern_work(struct work_struct *work) -{ - struct dcpext_scanout *scanout = container_of(work, struct dcpext_scanout, work); - struct device *dev = scanout->firmware_dev; - const char *step = "scanout DMA consumer"; - int ret; - - if (READ_ONCE(scanout->stopping) || atomic_read(&scanout->terminal_error)) - return; - ret = scanout_create_device(scanout); - if (ret) - goto fail; - scanout->frame_size = ALIGN((size_t)SCANOUT_STRIDE * SCANOUT_HEIGHT, SZ_16K); - scanout->size = scanout->frame_size * (scanout->pageflips ? 2 : 1); - step = "coherent framebuffer allocation"; - scanout->pixels = dma_alloc_coherent(dev, scanout->size, &scanout->iova, GFP_KERNEL); - if (!scanout->pixels) { - ret = -ENOMEM; - goto fail; - } - if (!scanout_iova_valid(scanout->iova, scanout->size)) { - ret = -ERANGE; - goto fail; - } - step = "coherent backing scatterlist"; - ret = dma_get_sgtable(dev, &scanout->sgt, scanout->pixels, scanout->iova, scanout->size); - if (ret) - goto fail; - step = "scanout IOVA mapping and page verification"; - ret = scanout_map_buffer(scanout); - if (ret) - goto fail; - scanout_fill_pattern(scanout->pixels, scanout->size); - dma_wmb(); - dev_info(dev, "external pattern: verified %zu bytes at %pad in separate firmware/scanout domains; BGRA 3840x2160 stride %u\n", - scanout->size, &scanout->iova, SCANOUT_STRIDE); - step = "iBoot first-pattern commands"; - if (atomic_read(&scanout->terminal_error)) { - ret = -ENOLINK; - goto fail; - } - ret = ibootep_present_pattern(scanout->dcp, scanout->iova, - scanout->frame_size, SCANOUT_STRIDE); - if (!ret && scanout->pageflips) { - step = "initial firmware swap completion"; - ret = ibootep_present_frame(scanout->dcp, scanout->iova, - scanout->frame_size, SCANOUT_STRIDE); - } - if (ret) - goto fail; - if (atomic_read(&scanout->terminal_error)) { - ret = -ENOLINK; - goto fail; - } - smp_store_release(&scanout->pattern_ready, true); - dev_info(dev, "external pattern commands accepted; all scanout resources retained until reboot\n"); - return; -fail: - scanout_fail(scanout, ret); - dev_err(dev, "external pattern stopped at %s: %d (%zu bytes mapped); no retry, resources retained until reboot\n", - step, ret, scanout->mapped); -} - -static ssize_t dcpext_pattern_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct dcpext_scanout *scanout = container_of(attr, struct dcpext_scanout, attr); - struct apple_dcp *dcp = scanout->dcp; - - if (!sysfs_streq(buf, "1")) - return -EINVAL; - if (READ_ONCE(scanout->stopping) || !dcp->external || !dcp->rtk || - !apple_rtkit_is_running(dcp->rtk) || READ_ONCE(dcp->crashed) || !scanout_node_verified(scanout->node)) - return -ENODEV; - /* Serialize the first request against the disconnect invalidation hook. */ - mutex_lock(&dcp->hpd_mutex); - if (atomic_read(&scanout->terminal_error) || !scanout_link_ready(scanout)) { - mutex_unlock(&dcp->hpd_mutex); - return -ENOLINK; - } - if (atomic_cmpxchg(&scanout->requested, 0, 1)) { - mutex_unlock(&dcp->hpd_mutex); - return -EALREADY; - } - mutex_unlock(&dcp->hpd_mutex); - /* Firmware DMA and callbacks may outlive any error returned by this worker. */ - if (!try_module_get(THIS_MODULE)) { - atomic_set(&scanout->requested, 0); - return -ENODEV; - } - queue_work(system_dfl_wq, &scanout->work); - return count; -} - -/* Separate explicit step: keep a successful pattern visible until requested. */ -static void dcpext_desktop_work(struct work_struct *work) -{ - struct dcpext_scanout *scanout = container_of(work, struct dcpext_scanout, desktop_work); - int ret; - - if (READ_ONCE(scanout->stopping) || atomic_read(&scanout->terminal_error) || - !smp_load_acquire(&scanout->pattern_ready)) - return; - ret = dcpext_drm_register(scanout->dcp, scanout->pixels, scanout->frame_size, - SCANOUT_STRIDE, &scanout->terminal_error, &scanout->retained_drm); - if (ret) { - scanout_fail(scanout, ret); - dev_err(scanout->firmware_dev, "external desktop registration failed: %d; scanout retained\n", ret); - } else { - smp_store_release(&scanout->desktop_registered, true); - if (atomic_read(&scanout->terminal_error)) - schedule_work(&scanout->invalidate_work); - } -} - -static ssize_t dcpext_desktop_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct dcpext_scanout *scanout = container_of(attr, struct dcpext_scanout, desktop_attr); - - if (!sysfs_streq(buf, "1")) - return -EINVAL; - if (READ_ONCE(scanout->stopping)) - return -ENODEV; - if (atomic_read(&scanout->terminal_error)) - return -ENOLINK; - if (!smp_load_acquire(&scanout->pattern_ready)) - return -EAGAIN; - if (atomic_cmpxchg(&scanout->desktop_requested, 0, 1)) - return -EALREADY; - queue_work(system_dfl_wq, &scanout->desktop_work); - return count; -} - -static void dcpext_scanout_cleanup(void *data) -{ - struct dcpext_scanout *scanout = data; - - WRITE_ONCE(scanout->stopping, true); - cancel_work_sync(&scanout->desktop_work); - cancel_work_sync(&scanout->work); - cancel_delayed_work_sync(&scanout->bounce_work); - cancel_delayed_work_sync(&scanout->repattern_work); - cancel_work_sync(&scanout->invalidate_work); - if (atomic_read(&scanout->requested) || READ_ONCE(scanout->published)) - return; /* Firmware callbacks and possible DMA survive parent cleanup. */ - WRITE_ONCE(scanout->dcp->dcpext_scanout, NULL); - of_node_put(scanout->node); - put_device(scanout->firmware_dev); - kfree(scanout); -} - -int dcpext_scanout_register(struct apple_dcp *dcp) -{ - struct device_node *node; - struct dcpext_scanout *scanout; - const char *uuid; - int ret; - - if (!dcp->external || dcp->fw_compat != DCP_FIRMWARE_V_14_7) - return -ENODEV; - if (dcpext_pageflip && - (of_property_read_string(dcp->dev->of_node, "apple,firmware-uuid", &uuid) || - strcmp(uuid, "DDF38191-93B3-324A-BC8F-643006F5AC82"))) - return -EOPNOTSUPP; - node = of_get_child_by_name(dcp->dev->of_node, "scanout"); - if (!scanout_node_verified(node)) { - of_node_put(node); - return -ENODEV; - } - scanout = kzalloc(sizeof(*scanout), GFP_KERNEL); - if (!scanout) { - of_node_put(node); - return -ENOMEM; - } - scanout->dcp = dcp; - scanout->firmware_dev = get_device(dcp->dev); - scanout->node = node; - scanout->pageflips = dcpext_pageflip; - mutex_init(&scanout->present_lock); - atomic_set(&scanout->requested, 0); - atomic_set(&scanout->terminal_error, 0); - INIT_WORK(&scanout->invalidate_work, dcpext_invalidate_work); - INIT_WORK(&scanout->work, dcpext_pattern_work); - atomic_set(&scanout->bounce, SCANOUT_BOUNCE_NONE); - INIT_DELAYED_WORK(&scanout->bounce_work, dcpext_bounce_timeout); - INIT_DELAYED_WORK(&scanout->repattern_work, dcpext_repattern_work); - atomic_set(&scanout->desktop_requested, 0); - INIT_WORK(&scanout->desktop_work, dcpext_desktop_work); - sysfs_attr_init(&scanout->attr.attr); - scanout->attr.attr.name = "dcpext_pattern"; - scanout->attr.attr.mode = 0200; - scanout->attr.store = dcpext_pattern_store; - scanout->attrs[0] = &scanout->attr.attr; - sysfs_attr_init(&scanout->desktop_attr.attr); - scanout->desktop_attr.attr.name = "dcpext_desktop"; - scanout->desktop_attr.attr.mode = 0200; - scanout->desktop_attr.store = dcpext_desktop_store; - scanout->attrs[1] = &scanout->desktop_attr.attr; - sysfs_attr_init(&scanout->status_attr.attr); - scanout->status_attr.attr.name = "dcpext_status"; - scanout->status_attr.attr.mode = 0444; - scanout->status_attr.show = dcpext_status_show; - scanout->attrs[2] = &scanout->status_attr.attr; - sysfs_attr_init(&scanout->present_attr.attr); - scanout->present_attr.attr.name = "dcpext_present"; - scanout->present_attr.attr.mode = 0444; - scanout->present_attr.show = dcpext_present_show; - scanout->attrs[3] = &scanout->present_attr.attr; - scanout->attr_group.attrs = scanout->attrs; - ret = devm_add_action_or_reset(dcp->dev, dcpext_scanout_cleanup, scanout); - if (ret) - return ret; - WRITE_ONCE(scanout->published, true); - smp_store_release(&dcp->dcpext_scanout, scanout); - ret = devm_device_add_group(dcp->dev, &scanout->attr_group); - if (!ret) - dev_info(dcp->dev, "external scanout handoff verified; explicit dcpext_pattern=1 is available\n"); - return ret; -} diff --git a/drivers/gpu/drm/apple/dcpext_scanout.h b/drivers/gpu/drm/apple/dcpext_scanout.h deleted file mode 100644 index aa195170f8e28..0000000000000 --- a/drivers/gpu/drm/apple/dcpext_scanout.h +++ /dev/null @@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ -#ifndef _APPLE_DCPEXT_SCANOUT_H -#define _APPLE_DCPEXT_SCANOUT_H - -#include -struct apple_dcp; - -struct dcpext_frame { - void *pixels; - size_t size; -}; - -bool dcpext_scanout_pageflips(struct apple_dcp *dcp); -/* begin holds the presentation mutex until end, including on discard. - * Callers must hold drm_dev_enter() across the pair to exclude removal. - */ -int dcpext_scanout_begin_frame(struct apple_dcp *dcp, struct dcpext_frame *frame); -int dcpext_scanout_end_frame(struct apple_dcp *dcp, bool present); - -/* Register the explicit one-shot diagnostic only after the iBoot service exists. */ -int dcpext_scanout_register(struct apple_dcp *dcp); - -/* Caller holds hpd_mutex when invalidating a physical link. */ -void dcpext_scanout_fault(struct apple_dcp *dcp, int error); -void dcpext_scanout_invalidate(struct apple_dcp *dcp); -void dcpext_scanout_link_restored(struct apple_dcp *dcp); -bool dcpext_scanout_terminal(struct apple_dcp *dcp); -bool dcpext_scanout_requested(struct apple_dcp *dcp); - -#endif diff --git a/drivers/gpu/drm/apple/ibootep.c b/drivers/gpu/drm/apple/ibootep.c index 7f90f68bf26f6..0e03d658aee32 100644 --- a/drivers/gpu/drm/apple/ibootep.c +++ b/drivers/gpu/drm/apple/ibootep.c @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -11,7 +10,6 @@ #include "afk.h" #include "dcp.h" #include "dcpext_mode.h" -#include "dcpext_scanout.h" #include "ibootep.h" /* m1n1 src/dcp_iboot.c: iBoot commands have their own wrapper inside EPIC. */ @@ -19,7 +17,6 @@ #define IBOOT_MODE_SIZE 24 #define IBOOT_PATTERN_WIDTH DCPEXT_WIDTH #define IBOOT_PATTERN_HEIGHT DCPEXT_HEIGHT -#define IBOOT_PATTERN_STRIDE DCPEXT_STRIDE enum iboot_query_op { IBOOT_GET_HPD = 3, @@ -27,53 +24,11 @@ enum iboot_query_op { IBOOT_GET_COLOR_MODES = 5, }; -/* Packed layouts from m1n1 src/dcp_iboot.h and swap_set_layer_cmd_v13_3. */ -struct iboot_plane { - __le32 unk1; - __le64 addr; - __le32 tile_size; - __le32 stride; - __le32 unk2[4]; - __le32 addr_format; - __le32 unk3; -} __packed; - -struct iboot_layer { - struct iboot_plane planes[3]; - __le32 unk; - __le32 plane_count; - __le32 width; - __le32 height; - __le32 surface_format; - __le32 colorspace; - __le32 eotf; - u8 transform; - u8 padding[3]; -} __packed; - -struct iboot_swap_layer_v13_3 { - __le32 unk; - __le32 layer_id; - struct iboot_layer layer; - __le32 unk3; - __le32 unk4; - __le32 src[4]; - __le32 dst[4]; - __le32 unk2; -} __packed; - -static_assert(sizeof(struct iboot_plane) == 44); -static_assert(sizeof(struct iboot_layer) == 164); -static_assert(sizeof(struct iboot_swap_layer_v13_3) == 216); - struct iboot_query { struct apple_epic_service *service; struct work_struct work; atomic_t busy; bool stopping; - bool pattern_requested; - bool presentation_failed; - u32 last_frame_swap; bool timing_valid; bool color_valid; /* Preserve the exact queried records, including firmware-owned padding. */ @@ -123,31 +78,6 @@ static int iboot_parse_hpd(const u8 *payload, size_t size, bool *hpd, return 0; } -static int iboot_parse_swap_begin(const u8 *reply, size_t received, u32 *id) -{ - const u8 *payload; - size_t size; - int ret; - - /* The gated 14.7 firmware writes 284 in this wrapper but returns only - * the 28-byte Begin record through EPIC. Accept that exact mismatch, - * bounded by the actual transport length; never read the absent tail. - */ - if (received == 28 && get_unaligned_le32(reply) == 15 && - get_unaligned_le32(reply + 4) == 284) { - payload = reply + 8; - size = 20; - } else { - ret = iboot_reply_payload(reply, received, 15, &payload, &size); - if (ret) - return ret; - } - if (size < 20) - return -EPROTO; - *id = get_unaligned_le32(payload + 12); - return 0; -} - static int iboot_parse_modes(const u8 *payload, size_t size, u32 *count) { u32 i; @@ -164,7 +94,7 @@ static int iboot_parse_modes(const u8 *payload, size_t size, u32 *count) } /* - * 3840x2160 timings the first pattern may use, best first: the reduced-blanking + * 3840x2160 timings the mode query selects, best first: the reduced-blanking * 59.9966 Hz timing seen through TB3 docks, then the standard 59.94 Hz and 60 Hz * timings that monitors report over faster USB4 links. 59.94 Hz comes before * 60 Hz because firmware can resolve "60 Hz" to a DSC timing on 4K120 monitors, @@ -199,63 +129,6 @@ static bool iboot_pattern_mode(u32 op, const u8 *mode) return false; } -static int iboot_pattern_params(u64 iova, size_t size, u32 stride) -{ - /* The caller owns address allocation and both DART mappings. */ - if (!iova || (iova & 0x3fff) || stride != IBOOT_PATTERN_STRIDE || - size < (size_t)IBOOT_PATTERN_STRIDE * IBOOT_PATTERN_HEIGHT || - size > DCPEXT_MAX_BUFFER_SIZE || iova >= (1ULL << 42) || - size > (1ULL << 42) - iova) - return -EINVAL; - return 0; -} - -static void iboot_build_pattern_layer(struct iboot_swap_layer_v13_3 *cmd, - u64 iova, u32 stride) -{ - memset(cmd, 0, sizeof(*cmd)); - /* Layer zero, one linear BGRA plane with opaque alpha in the supplied pixels. */ - cmd->layer.planes[0].addr = cpu_to_le64(iova); - cmd->layer.planes[0].stride = cpu_to_le32(stride); - cmd->layer.planes[0].addr_format = cpu_to_le32(1); - cmd->layer.plane_count = cpu_to_le32(1); - cmd->layer.width = cpu_to_le32(IBOOT_PATTERN_WIDTH); - cmd->layer.height = cpu_to_le32(IBOOT_PATTERN_HEIGHT); - cmd->layer.surface_format = cpu_to_le32(1); /* BGRA */ - cmd->layer.colorspace = cpu_to_le32(1); /* sRGB */ - cmd->layer.eotf = cpu_to_le32(1); /* SDR */ - cmd->src[0] = cmd->dst[0] = cpu_to_le32(IBOOT_PATTERN_WIDTH); - cmd->src[1] = cmd->dst[1] = cpu_to_le32(IBOOT_PATTERN_HEIGHT); -} - -static int iboot_build_pattern_request(u32 op, const void *data, size_t data_size, - u8 *request, size_t capacity, size_t *size) -{ - size_t expected; - - switch (op) { - case 2: expected = 1; break; /* SetPower */ - case 6: expected = 2 * IBOOT_MODE_SIZE; break; /* SetMode */ - case 15: expected = 0; break; /* SwapBegin */ - case 16: expected = sizeof(struct iboot_swap_layer_v13_3); break; - case 18: expected = 12; break; /* SwapEnd */ - case 19: /* SwapWait */ - expected = 16; - break; - default: return -EINVAL; - } - if (data_size != expected || capacity < 16 + expected || - (expected && !data)) - return -EINVAL; - memset(request, 0, 16 + expected); - put_unaligned_le32(op, request); - put_unaligned_le32(16 + expected, request + 4); - if (expected) - memcpy(request + 16, data, expected); - *size = 16 + expected; - return 0; -} - static int iboot_read_query(struct iboot_query *query, u32 op, u8 *reply, const u8 **payload, size_t *size) { @@ -433,241 +306,6 @@ int ibootep_query_modes(struct apple_dcp *dcp) return 0; } -/* Observational only: inner status fields for mutation ops are not decoded. - * AFK currently exposes capacity rather than the actual DMA reply length. - * Never trust the firmware length to enlarge this fixed diagnostic snapshot. - */ -static void iboot_log_pattern_reply(struct device *dev, u32 op, const u8 *reply) -{ - const u8 *payload; - size_t size; - int header = iboot_reply_payload(reply, IBOOT_QUERY_RX_SIZE, op, &payload, &size); - - dev_info(dev, "iBoot command %u EPIC success: inner-op=%u declared-len=%u header-check=%d raw64=%*phN (capacity snapshot, inner status unknown)\n", - op, get_unaligned_le32(reply), get_unaligned_le32(reply + 4), - header, 64, reply); -} - -static int iboot_pattern_command(struct iboot_query *query, u32 op, - const void *data, size_t data_size, u8 *reply) -{ - u8 request[16 + sizeof(struct iboot_swap_layer_v13_3)]; - size_t size; - u32 retcode = 0; - int ret; - - if (READ_ONCE(query->stopping) || READ_ONCE(query->service->torndown)) - return -ENODEV; - ret = iboot_build_pattern_request(op, data, data_size, request, sizeof(request), &size); - if (ret) - return ret; - memset(reply, 0, IBOOT_QUERY_RX_SIZE); - ret = afk_send_command(query->service, EPIC_SUBTYPE_STD_SERVICE, - request, size, reply, IBOOT_QUERY_RX_SIZE, &retcode); - if (retcode) { - dev_warn(query->service->ep->dcp->dev, - "iBoot pattern command %u returned %#x\n", op, retcode); - return -EIO; - } - if (!ret) - iboot_log_pattern_reply(query->service->ep->dcp->dev, op, reply); - return ret; -} - -/* Unlike startup diagnostics, presentation needs the actual received length - * before trusting the swap id. Mutation operations may have no DMA body; - * their outer EPIC return code carries the operation's success or failure. - */ -static int iboot_frame_command(struct iboot_query *query, u32 op, - const void *data, size_t data_size, u8 *reply, - size_t *received) -{ - u8 request[16 + sizeof(struct iboot_swap_layer_v13_3)]; - size_t size; - u32 retcode = 0; - int ret; - - if (READ_ONCE(query->stopping) || READ_ONCE(query->service->torndown)) - return -ENODEV; - ret = iboot_build_pattern_request(op, data, data_size, request, - sizeof(request), &size); - if (ret) - return ret; - ret = afk_send_command_with_reply_len(query->service, EPIC_SUBTYPE_STD_SERVICE, - request, size, reply, IBOOT_QUERY_RX_SIZE, &retcode, received); - if (ret) - return ret; - return retcode ? -EIO : 0; -} - -int ibootep_present_frame(struct apple_dcp *dcp, u64 iova, size_t size, u32 stride) -{ - struct iboot_swap_layer_v13_3 layer; - struct iboot_query *query; - __le32 end[3] = {}, wait[4] = {}; - size_t received; - u32 id = 0, step = 15; - u8 *reply; - int ret; - - ret = iboot_pattern_params(iova, size, stride); - if (ret) - return ret; - if (dcp->fw_compat != DCP_FIRMWARE_V_14_7) - return -EOPNOTSUPP; - query = iboot_find_query(dcp); - if (IS_ERR(query)) - return PTR_ERR(query); - might_sleep(); - if (atomic_cmpxchg(&query->busy, 0, 1)) - return -EBUSY; - if (!query->pattern_requested || query->presentation_failed) { - ret = -EIO; - goto done; - } - reply = kzalloc(IBOOT_QUERY_RX_SIZE, GFP_KERNEL); - if (!reply) { - ret = -ENOMEM; - goto done; - } - ret = iboot_frame_command(query, step, NULL, 0, reply, &received); - if (ret) - goto failed; - ret = iboot_parse_swap_begin(reply, received, &id); - if (ret) - goto failed; - if (!id || id == query->last_frame_swap) { - ret = -EPROTO; - goto failed; - } - iboot_build_pattern_layer(&layer, iova, stride); - step = 16; - ret = iboot_frame_command(query, step, &layer, sizeof(layer), reply, &received); - if (ret) - goto failed; - step = 18; - ret = iboot_frame_command(query, step, end, sizeof(end), reply, &received); - if (ret) - goto failed; - /* Display zero, exact swap id, wait for completion, no extra delay. - * Mode 1 waits while this id remains in the pending/current transaction - * queue. It does not wait for the newly displayed frame to be replaced. - * AFK bounds the host wait; on timeout neither buffer may be reused. - */ - wait[1] = cpu_to_le32(id); - wait[2] = cpu_to_le32(1); - step = 19; - ret = iboot_frame_command(query, step, wait, sizeof(wait), reply, &received); - if (ret) - goto failed; - query->last_frame_swap = id; - kfree(reply); - goto done; -failed: - query->presentation_failed = true; - dev_err(dcp->dev, "external frame swap %u failed at step %u: %d; buffers retained, no retry\n", - id, step, ret); - kfree(reply); -done: - atomic_set_release(&query->busy, 0); - return ret; -} - -int ibootep_rearm_pattern(struct apple_dcp *dcp) -{ - struct iboot_query *query = iboot_find_query(dcp); - - if (IS_ERR(query)) - return PTR_ERR(query); - if (atomic_read(&query->busy)) - return -EBUSY; - WRITE_ONCE(query->pattern_requested, false); - return 0; -} - -int ibootep_present_pattern(struct apple_dcp *dcp, u64 iova, size_t size, u32 stride) -{ - struct iboot_query *query; - struct iboot_swap_layer_v13_3 layer; - u8 modes[2 * IBOOT_MODE_SIZE], power = 1, end[12] = {}; - const u8 *payload; - u8 *reply; - size_t payload_size; - u32 step = IBOOT_GET_HPD, swap_id = 0; - int ret; - - ret = iboot_pattern_params(iova, size, stride); - if (ret) - return ret; - query = iboot_find_query(dcp); - if (IS_ERR(query)) - return PTR_ERR(query); - if (dcp->fw_compat != DCP_FIRMWARE_V_14_7) - return -EOPNOTSUPP; - /* The caller uses its own sleepable worker, not the ordered AFK RX queue. */ - might_sleep(); - if (atomic_cmpxchg(&query->busy, 0, 1)) - return -EBUSY; - if (query->pattern_requested) { - ret = -EALREADY; - goto done; - } - /* Even failure is one-shot; a timeout leaves the firmware state uncertain. */ - query->pattern_requested = true; - reply = kzalloc(IBOOT_QUERY_RX_SIZE, GFP_KERNEL); - if (!reply) { - ret = -ENOMEM; - goto done; - } - ret = iboot_refresh_modes(query, reply); - if (ret) - goto free; - if (!query->timing_valid || !query->color_valid) { - ret = -ENODATA; - goto free; - } - memcpy(modes, query->timing, IBOOT_MODE_SIZE); - memcpy(modes + IBOOT_MODE_SIZE, query->color, IBOOT_MODE_SIZE); - iboot_build_pattern_layer(&layer, iova, stride); - step = 2; - ret = iboot_pattern_command(query, step, &power, sizeof(power), reply); - if (ret) - goto free; - /* Match m1n1's Sonoma power-on settling interval before changing timing. */ - msleep(100); - step = 6; - ret = iboot_pattern_command(query, step, modes, sizeof(modes), reply); - if (ret) - goto free; - step = 15; - ret = iboot_pattern_command(query, step, NULL, 0, reply); - if (ret) - goto free; - ret = iboot_reply_payload(reply, IBOOT_QUERY_RX_SIZE, step, &payload, &payload_size); - if (ret || payload_size < 20) { - ret = -EPROTO; - goto free; - } - swap_id = get_unaligned_le32(payload + 12); - step = 16; - ret = iboot_pattern_command(query, step, &layer, sizeof(layer), reply); - if (ret) - goto free; - step = 18; - ret = iboot_pattern_command(query, step, end, sizeof(end), reply); - if (!ret) - dev_info(dcp->dev, "iBoot EPIC sequence completed for 3840x2160 BGRA pattern; physical scanout unverified, stride %u IOVA %#llx swap %u; buffer retained\n", - stride, iova, swap_id); -free: - if (ret) - dev_warn(dcp->dev, "iBoot first-pattern step %u failed: %d; no retry, buffer must remain mapped\n", - step, ret); - kfree(reply); -done: - atomic_set_release(&query->busy, 0); - return ret; -} - static ssize_t dcpext_modes_query_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -717,9 +355,6 @@ static void disp_service_init(struct apple_epic_service *service, const char *na return; } smp_store_release(&service->cookie, query); - ret = dcpext_scanout_register(dcp); - if (ret && ret != -ENODEV) - dev_warn(dcp->dev, "external pattern interface unavailable: %d\n", ret); dev_info(dcp->dev, "external iBoot disp0 service ready on channel %u; mode queries are manual\n", service->channel); } diff --git a/drivers/gpu/drm/apple/ibootep.h b/drivers/gpu/drm/apple/ibootep.h index aa44c2f8754e4..3e134b4215432 100644 --- a/drivers/gpu/drm/apple/ibootep.h +++ b/drivers/gpu/drm/apple/ibootep.h @@ -12,19 +12,4 @@ bool ibootep_is_ready(struct apple_dcp *dcp); /* Queue external HPD/timing/color queries; never call synchronously from AFK RX. */ int ibootep_query_modes(struct apple_dcp *dcp); -/* Explicit, one-shot external presentation, called from sleepable work outside - * the AFK receive queue. Buffer: 3840x2160, stride 15360, bytes B,G,R,0xff. - * Caller verifies both DART mappings and retains the buffer until reboot, - * including after an error: commands may already have reached firmware. - */ -int ibootep_present_pattern(struct apple_dcp *dcp, u64 iova, size_t size, u32 stride); -/* Allow one more pattern request, for the retained buffer after a hotplug bounce. */ -int ibootep_rearm_pattern(struct apple_dcp *dcp); - -/* Submit a retained buffer without changing power/timing. Success follows - * SwapWait for this swap, not merely the SetSwapEnd command acknowledgment. - * Failure leaves DMA ownership uncertain: retain every submitted buffer. - */ -int ibootep_present_frame(struct apple_dcp *dcp, u64 iova, size_t size, u32 stride); - #endif diff --git a/drivers/gpu/drm/apple/iomfb_v14_7.c b/drivers/gpu/drm/apple/iomfb_v14_7.c index a99bfed67183f..f5f90e1feb29c 100644 --- a/drivers/gpu/drm/apple/iomfb_v14_7.c +++ b/drivers/gpu/drm/apple/iomfb_v14_7.c @@ -36,7 +36,6 @@ #include "afk.h" #include "dcp.h" #include "dcp-internal.h" -#include "dcpext_scanout.h" #include "dcp-lifecycle.h" #include "iomfb_internal.h" #include "iomfb_v14_7.h" @@ -1470,8 +1469,6 @@ static void dcp_v14_crashed(void *cookie, const void *crashlog, size_t crashlog_ struct apple_connector *connector = READ_ONCE(dcp->connector); WRITE_ONCE(dcp->crashed, true); - if (dcp->external) - dcpext_scanout_fault(dcp, -EIO); /* The display it drove is gone until reboot. */ if (v14->external && connector && !READ_ONCE(dcp->external_detached)) { WRITE_ONCE(connector->connected, false); diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index 03db5ed73e343..d9fd10df679da 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -1102,19 +1102,17 @@ static int __init gate_pmp_apply(struct device_node *dcp, struct device_node **p * (apple,t6030-dispext-handoff). Nothing here touches a processor's CPU: the * display driver starts the firmware when a display is first attached. * - * Each processor ends in one of three states: - * - native (the default): the processor, its DART, mailbox, PMP request and - * Type-C routes are enabled; its display DART is added to the display + * Each processor ends in one of two states: + * - native: the processor, its DART, mailbox, PMP request and Type-C + * routes are enabled; its display DART is added to the display * subsystem's iommus, so every framebuffer is mapped for this pipe as on * M1/M2, and a piodma child is added for the DART's PIODMA stream 4. The * processor then joins the main DRM device. - * - manual (apple_t6030_display.dcpext_manual=1): the earlier diagnostic - * path, with explicit start and a separately mapped scanout buffer. * - refused: everything stays disabled, and so do its Type-C routes, so the * USB-C ports never wait for a display mode switch nobody registers. * apple_t6030_display.dcpext=0 refuses every processor; - * apple_t6030_display.scanout=0 refuses the display DART, which the native - * path needs. + * apple_t6030_display.scanout=0 refuses the display DART, which every + * processor needs, and so refuses them all. */ static bool gate_dcpext_requested __initdata = true; @@ -1132,14 +1130,6 @@ static int __init gate_scanout_setup(char *arg) } early_param("apple_t6030_display.scanout", gate_scanout_setup); -static bool gate_dcpext_manual __initdata; - -static int __init gate_dcpext_manual_setup(char *arg) -{ - return kstrtobool(arg, &gate_dcpext_manual); -} -early_param("apple_t6030_display.dcpext_manual", gate_dcpext_manual_setup); - #define GATE_DCPEXT_MAX 4 /* One external display processor and what the gate found for it. */ @@ -1528,8 +1518,8 @@ static int __init gate_ext_piodma(struct of_changeset *cs, struct gate_ext *ext) return ret; } -/* Enables @ext's processor, in the native or the manual configuration. */ -static int __init gate_ext_apply(struct gate_ext *ext, bool native) +/* Enables @ext's processor. */ +static int __init gate_ext_apply(struct gate_ext *ext) { struct of_changeset *cs = gate_cs_alloc(); int ret; @@ -1557,15 +1547,10 @@ static int __init gate_ext_apply(struct gate_ext *ext, bool native) ret = gate_ext_routes(cs, ext->dcp, "okay"); if (!ret && ext->scanout_ok) ret = of_changeset_update_prop_string(cs, ext->disp_dart, "status", "okay"); - if (!ret && native) { + if (!ret) ret = gate_ext_piodma(cs, ext); - if (!ret) - ret = gate_display_add_dart(cs, ext->disp_dart); - } else if (!ret && ext->scanout_ok) { - ret = gate_set_u32(cs, ext->scanout, "apple,t6030-scanout-verified", 1); - if (!ret) - ret = of_changeset_update_prop_string(cs, ext->scanout, "status", "okay"); - } + if (!ret) + ret = gate_display_add_dart(cs, ext->disp_dart); if (!ret) ret = of_changeset_apply(cs); if (ret) @@ -1604,7 +1589,6 @@ static bool __init gate_ext_firmware_ok(struct device_node *np) static void __init gate_dcpext_one(struct device_node *np, const char *refuse) { struct gate_ext ext = { .dcp = of_node_get(np) }; - bool native = !gate_dcpext_manual; int ret; if (!gate_disabled(np)) { @@ -1638,22 +1622,18 @@ static void __init gate_dcpext_one(struct device_node *np, const char *refuse) if (ret && ret != -ENODEV) gate_warn("%pOF: display DART handoff failed validation (%d)\n", np, ret); } - if (native && !ext.scanout_ok) { + if (!ext.scanout_ok) { gate_ext_refuse(np, "no usable display DART handoff"); goto put; } - ret = gate_ext_apply(&ext, native); + ret = gate_ext_apply(&ext); if (ret) { gate_warn("%pOF: changeset failed: %d\n", np, ret); gate_ext_refuse(np, "the gate could not enable it"); goto put; } - if (native) - gate_info("enabled dcpext%u (%pOF) with PMP DISPEXT%u request, CPU power floor, display DART %pOF and its Type-C routes; started by the display driver on first use\n", - ext.index, np, ext.index, ext.disp_dart); - else - gate_info("enabled dcpext%u (%pOF) for manual start%s\n", ext.index, np, - ext.scanout_ok ? " with the verified scanout DART" : ""); + gate_info("enabled dcpext%u (%pOF) with PMP DISPEXT%u request, CPU power floor, display DART %pOF and its Type-C routes; started by the display driver on first use\n", + ext.index, np, ext.index, ext.disp_dart); put: gate_ext_put(&ext); } diff --git a/tools/asahi/tunnel-route/fixture.c b/tools/asahi/tunnel-route/fixture.c index 2bcb8e713e5be..f02c2a4405fbe 100644 --- a/tools/asahi/tunnel-route/fixture.c +++ b/tools/asahi/tunnel-route/fixture.c @@ -89,10 +89,6 @@ static enum dcp_fabric_presence_state dcp_hdmi_presence(struct apple_dcp *d) { return DCP_FABRIC_ABSENT; } -static bool dcpext_scanout_terminal(struct apple_dcp *d) -{ - return false; -} static bool dcp_tb_services_ready(struct apple_dcp *d) { return true; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py index 9aa4f2041961b..35ef9df0fb62e 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py @@ -607,10 +607,8 @@ def swap(old, new): static int dptxport_set_hpd_timeout(void *s, bool on, int t) { (void)t; return dptxport_set_hpd(s, on); } /* The pre-split condition: neither a USB4 output nor a T602X tunnel machine here. */ static bool dcp_uses_t6020_tunnel_flow(struct apple_dcp *d) { return dcp_is_usb4_output(d) && apple_dp_tunnel_t602x(); } -/* An H17P display is not a T6030 dcpext (dcp->external): no scanout to fault or restore. */ +/* An H17P display is not a T6030 dcpext (dcp->external). */ #define smp_store_release(p, v) (*(p) = (v)) -static bool dcpext_scanout_terminal(struct apple_dcp *d) { (void)d; return false; } -static void dcpext_scanout_link_restored(struct apple_dcp *d) { (void)d; assert(!"T6030 dcpext path in an H17P scenario"); } static bool iomfb_v14_7_external_ready(struct apple_dcp *d) { (void)d; assert(!"T6030 external processor in an H17P scenario"); return false; } static int iomfb_v14_7_external_open(struct apple_dcp *d) { (void)d; assert(!"T6030 external processor in an H17P scenario"); return -ENODEV; } '''