/** * @CSF_FW_BINARY_ENTRY_TYPE_BUILD_INFO_METADATA: Metadata about how * the FW binary was built.
*/
CSF_FW_BINARY_ENTRY_TYPE_BUILD_INFO_METADATA = 6
};
/** @va: MCU virtual range to map this binary section to. */ struct { /** @start: Start address. */
u32 start;
/** @end: End address. */
u32 end;
} va;
/** @data: Data to initialize the FW section with. */ struct { /** @start: Start offset in the FW binary. */
u32 start;
/** @end: End offset in the FW binary. */
u32 end;
} data;
};
struct panthor_fw_build_info_hdr { /** @meta_start: Offset of the build info data in the FW binary */
u32 meta_start; /** @meta_size: Size of the build info data in the FW binary */
u32 meta_size;
};
/** * struct panthor_fw_binary_iter - Firmware binary iterator * * Used to parse a firmware binary.
*/ struct panthor_fw_binary_iter { /** @data: FW binary data. */ constvoid *data;
/** * @name: Name of the section, as specified in the binary. * * Can be NULL.
*/ constchar *name;
/** * @data: Initial data copied to the FW memory. * * We keep data around so we can reload sections after a reset.
*/ struct { /** @buf: Buffed used to store init data. */ constvoid *buf;
/** @size: Size of @buf in bytes. */
size_t size;
} data;
};
/** @watchdog: Collection of fields relating to the FW watchdog. */ struct { /** @ping_work: Delayed work used to ping the FW. */ struct delayed_work ping_work;
} watchdog;
/** * @req_waitqueue: FW request waitqueue. * * Everytime a request is sent to a command stream group or the global * interface, the caller will first busy wait for the request to be * acknowledged, and then fallback to a sleeping wait. * * This wait queue is here to support the sleeping wait flavor.
*/
wait_queue_head_t req_waitqueue;
/** @booted: True is the FW is booted */ bool booted;
/** * panthor_fw_get_glb_iface() - Get the global interface * @ptdev: Device. * * Return: The global interface.
*/ struct panthor_fw_global_iface *
panthor_fw_get_glb_iface(struct panthor_device *ptdev)
{ return &ptdev->fw->iface.global;
}
/** * panthor_fw_get_csg_iface() - Get a command stream group slot interface * @ptdev: Device. * @csg_slot: Index of the command stream group slot. * * Return: The command stream group slot interface.
*/ struct panthor_fw_csg_iface *
panthor_fw_get_csg_iface(struct panthor_device *ptdev, u32 csg_slot)
{ if (drm_WARN_ON(&ptdev->base, csg_slot >= MAX_CSGS)) return NULL;
return &ptdev->fw->iface.groups[csg_slot];
}
/** * panthor_fw_get_cs_iface() - Get a command stream slot interface * @ptdev: Device. * @csg_slot: Index of the command stream group slot. * @cs_slot: Index of the command stream slot. * * Return: The command stream slot interface.
*/ struct panthor_fw_cs_iface *
panthor_fw_get_cs_iface(struct panthor_device *ptdev, u32 csg_slot, u32 cs_slot)
{ if (drm_WARN_ON(&ptdev->base, csg_slot >= MAX_CSGS || cs_slot >= MAX_CS_PER_CSG)) return NULL;
/** * panthor_fw_conv_timeout() - Convert a timeout into a cycle-count * @ptdev: Device. * @timeout_us: Timeout expressed in micro-seconds. * * The FW has two timer sources: the GPU counter or arch-timer. We need * to express timeouts in term of number of cycles and specify which * timer source should be used. * * Return: A value suitable for timeout fields in the global interface.
*/ static u32 panthor_fw_conv_timeout(struct panthor_device *ptdev, u32 timeout_us)
{ bool use_cycle_counter = false;
u32 timer_rate = 0;
u64 mod_cycles;
if (!timer_rate) {
use_cycle_counter = true;
timer_rate = clk_get_rate(ptdev->clks.core);
}
if (drm_WARN_ON(&ptdev->base, !timer_rate)) { /* We couldn't get a valid clock rate, let's just pick the * maximum value so the FW still handles the core * power on/off requests.
*/ return GLB_TIMER_VAL(~0) |
GLB_TIMER_SOURCE_GPU_COUNTER;
}
if (!was_mapped)
panthor_kernel_bo_vunmap(section->mem);
}
/** * panthor_fw_alloc_queue_iface_mem() - Allocate a ring-buffer interfaces. * @ptdev: Device. * @input: Pointer holding the input interface on success. * Should be ignored on failure. * @output: Pointer holding the output interface on success. * Should be ignored on failure. * @input_fw_va: Pointer holding the input interface FW VA on success. * Should be ignored on failure. * @output_fw_va: Pointer holding the output interface FW VA on success. * Should be ignored on failure. * * Allocates panthor_fw_ringbuf_{input,out}_iface interfaces. The input * interface is at offset 0, and the output interface at offset 4096. * * Return: A valid pointer in case of success, an ERR_PTR() otherwise.
*/ struct panthor_kernel_bo *
panthor_fw_alloc_queue_iface_mem(struct panthor_device *ptdev, struct panthor_fw_ringbuf_input_iface **input, conststruct panthor_fw_ringbuf_output_iface **output,
u32 *input_fw_va, u32 *output_fw_va)
{ struct panthor_kernel_bo *mem; int ret;
mem = panthor_kernel_bo_create(ptdev, ptdev->fw->vm, SZ_8K,
DRM_PANTHOR_BO_NO_MMAP,
DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC |
DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED,
PANTHOR_VM_KERNEL_AUTO_VA, "Queue FW interface"); if (IS_ERR(mem)) return mem;
ret = panthor_kernel_bo_vmap(mem); if (ret) {
panthor_kernel_bo_destroy(mem); return ERR_PTR(ret);
}
if (hdr.flags & ~CSF_FW_BINARY_IFACE_ENTRY_SUPPORTED_FLAGS) {
drm_err(&ptdev->base, "Firmware contains interface with unsupported flags (0x%x)\n",
hdr.flags); return -EINVAL;
}
if (hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_PROT) {
drm_warn(&ptdev->base, "Firmware protected mode entry not be supported, ignoring"); return 0;
}
if (hdr.va.start == CSF_MCU_SHARED_REGION_START &&
!(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_SHARED)) {
drm_err(&ptdev->base, "Interface at 0x%llx must be shared", CSF_MCU_SHARED_REGION_START); return -EINVAL;
}
name_len = iter->size - iter->offset;
section = drmm_kzalloc(&ptdev->base, sizeof(*section), GFP_KERNEL); if (!section) return -ENOMEM;
if (!(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_WR))
vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_READONLY;
if (!(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_EX))
vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC;
/* TODO: CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_*_COHERENT are mapped to * non-cacheable for now. We might want to introduce a new * IOMMU_xxx flag (or abuse IOMMU_MMIO, which maps to device * memory and is currently not used by our driver) for * AS_MEMATTR_AARCH64_SHARED memory, so we can take benefit * of IO-coherent systems.
*/ if (cache_mode != CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_CACHED)
vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED;
section->mem = panthor_kernel_bo_create(ptdev, panthor_fw_vm(ptdev),
section_size,
DRM_PANTHOR_BO_NO_MMAP,
vm_map_flags, va, "FW section"); if (IS_ERR(section->mem)) return PTR_ERR(section->mem);
if (drm_WARN_ON(&ptdev->base, section->mem->va_node.start != hdr.va.start)) return -EINVAL;
if (section->flags & CSF_FW_BINARY_IFACE_ENTRY_SHARED) {
ret = panthor_kernel_bo_vmap(section->mem); if (ret) return ret;
}
panthor_fw_init_section_mem(ptdev, section);
bo = to_panthor_bo(section->mem->obj);
sgt = drm_gem_shmem_get_pages_sgt(&bo->base); if (IS_ERR(sgt)) return PTR_ERR(sgt);
ret = panthor_fw_binary_iter_read(ptdev, iter, &hdr, sizeof(hdr)); if (ret) return ret;
if (hdr.meta_start > fw->size ||
hdr.meta_start + hdr.meta_size > fw->size) {
drm_err(&ptdev->base, "Firmware build info corrupt\n"); /* We don't need the build info, so continue */ return 0;
}
if (memcmp(git_sha_header, fw->data + hdr.meta_start, header_len)) { /* Not the expected header, this isn't metadata we understand */ return 0;
}
/* Check that the git SHA is NULL terminated as expected */ if (fw->data[hdr.meta_start + hdr.meta_size - 1] != '\0') {
drm_warn(&ptdev->base, "Firmware's git sha is not NULL terminated\n"); /* Don't treat as fatal */ return 0;
}
if (panthor_fw_binary_sub_iter_init(ptdev, iter, &eiter,
CSF_FW_BINARY_ENTRY_SIZE(ehdr) - sizeof(ehdr))) return -EINVAL;
switch (CSF_FW_BINARY_ENTRY_TYPE(ehdr)) { case CSF_FW_BINARY_ENTRY_TYPE_IFACE: return panthor_fw_load_section_entry(ptdev, fw, &eiter, ehdr); case CSF_FW_BINARY_ENTRY_TYPE_BUILD_INFO_METADATA: return panthor_fw_read_build_info(ptdev, fw, &eiter, ehdr);
/* FIXME: handle those entry types? */ case CSF_FW_BINARY_ENTRY_TYPE_CONFIG: case CSF_FW_BINARY_ENTRY_TYPE_FUTF_TEST: case CSF_FW_BINARY_ENTRY_TYPE_TRACE_BUFFER: case CSF_FW_BINARY_ENTRY_TYPE_TIMELINE_METADATA: return 0; default: break;
}
if (ehdr & CSF_FW_BINARY_ENTRY_OPTIONAL) return 0;
drm_err(&ptdev->base, "Unsupported non-optional entry type %u in firmware\n",
CSF_FW_BINARY_ENTRY_TYPE(ehdr)); return -EINVAL;
}
if (!glb_iface->control->version) {
drm_err(&ptdev->base, "Firmware version is 0. Firmware may have failed to boot"); return -EINVAL;
}
glb_iface->input = iface_fw_to_cpu_addr(ptdev, glb_iface->control->input_va);
glb_iface->output = iface_fw_to_cpu_addr(ptdev, glb_iface->control->output_va); if (!glb_iface->input || !glb_iface->output) {
drm_err(&ptdev->base, "Invalid global control interface input/output VA"); return -EINVAL;
}
if (glb_iface->control->group_num > MAX_CSGS ||
glb_iface->control->group_num < MIN_CSGS) {
drm_err(&ptdev->base, "Invalid number of control groups"); return -EINVAL;
}
for (i = 0; i < glb_iface->control->group_num; i++) { int ret = panthor_init_csg_iface(ptdev, i);
if (ret) return ret;
}
drm_info(&ptdev->base, "CSF FW using interface v%d.%d.%d, Features %#x Instrumentation features %#x",
CSF_IFACE_VERSION_MAJOR(glb_iface->control->version),
CSF_IFACE_VERSION_MINOR(glb_iface->control->version),
CSF_IFACE_VERSION_PATCH(glb_iface->control->version),
glb_iface->control->features,
panthor_get_instr_features(ptdev)); return 0;
}
gpu_write(ptdev, MCU_CONTROL, MCU_CONTROL_DISABLE); if (gpu_read_poll_timeout(ptdev, MCU_STATUS, status,
status == MCU_STATUS_DISABLED, 10, 100000))
drm_err(&ptdev->base, "Failed to stop MCU");
}
/** * panthor_fw_pre_reset() - Call before a reset. * @ptdev: Device. * @on_hang: true if the reset was triggered on a GPU hang. * * If the reset is not triggered on a hang, we try to gracefully halt the * MCU, so we can do a fast-reset when panthor_fw_post_reset() is called.
*/ void panthor_fw_pre_reset(struct panthor_device *ptdev, bool on_hang)
{ /* Make sure we won't be woken up by a ping. */
cancel_delayed_work_sync(&ptdev->fw->watchdog.ping_work);
ptdev->reset.fast = false;
if (!on_hang) { struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev);
u32 status;
/** * panthor_fw_post_reset() - Call after a reset. * @ptdev: Device. * * Start the FW. If this is not a fast reset, all FW sections are reloaded to * make sure we can recover from a memory corruption.
*/ int panthor_fw_post_reset(struct panthor_device *ptdev)
{ int ret;
/* Make the MCU VM active. */
ret = panthor_vm_active(ptdev->fw->vm); if (ret) return ret;
if (!ptdev->reset.fast) { /* On a slow reset, reload all sections, including RO ones. * We're not supposed to end up here anyway, let's just assume * the overhead of reloading everything is acceptable.
*/
panthor_reload_fw_sections(ptdev, true);
} else { /* The FW detects 0 -> 1 transitions. Make sure we reset * the HALT bit before the FW is rebooted. * This is not needed on a slow reset because FW sections are * re-initialized.
*/ struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev);
ret = panthor_fw_start(ptdev); if (ret) {
drm_err(&ptdev->base, "FW %s reset failed",
ptdev->reset.fast ? "fast" : "slow"); return ret;
}
/* We must re-initialize the global interface even on fast-reset. */
panthor_fw_init_global_iface(ptdev); return 0;
}
/** * panthor_fw_unplug() - Called when the device is unplugged. * @ptdev: Device. * * This function must make sure all pending operations are flushed before * will release device resources, thus preventing any interaction with * the HW. * * If there is still FW-related work running after this function returns, * they must use drm_dev_{enter,exit}() and skip any HW access when * drm_dev_enter() returns false.
*/ void panthor_fw_unplug(struct panthor_device *ptdev)
{ struct panthor_fw_section *section;
if (!IS_ENABLED(CONFIG_PM) || pm_runtime_active(ptdev->base.dev)) { /* Make sure the IRQ handler cannot be called after that point. */ if (ptdev->fw->irq.irq)
panthor_job_irq_suspend(&ptdev->fw->irq);
/* We intentionally don't call panthor_vm_idle() and let * panthor_mmu_unplug() release the AS we acquired with * panthor_vm_active() so we don't have to track the VM active/idle * state to keep the active_refcnt balanced.
*/
panthor_vm_put(ptdev->fw->vm);
ptdev->fw->vm = NULL;
if (!IS_ENABLED(CONFIG_PM) || pm_runtime_active(ptdev->base.dev))
panthor_gpu_power_off(ptdev, L2, ptdev->gpu_info.l2_present, 20000);
}
/** * panthor_fw_wait_acks() - Wait for requests to be acknowledged by the FW. * @req_ptr: Pointer to the req register. * @ack_ptr: Pointer to the ack register. * @wq: Wait queue to use for the sleeping wait. * @req_mask: Mask of requests to wait for. * @acked: Pointer to field that's updated with the acked requests. * If the function returns 0, *acked == req_mask. * @timeout_ms: Timeout expressed in milliseconds. * * Return: 0 on success, -ETIMEDOUT otherwise.
*/ staticint panthor_fw_wait_acks(const u32 *req_ptr, const u32 *ack_ptr,
wait_queue_head_t *wq,
u32 req_mask, u32 *acked,
u32 timeout_ms)
{
u32 ack, req = READ_ONCE(*req_ptr) & req_mask; int ret;
/* Busy wait for a few µsecs before falling back to a sleeping wait. */
*acked = req_mask;
ret = read_poll_timeout_atomic(READ_ONCE, ack,
(ack & req_mask) == req,
0, 10, 0,
*ack_ptr); if (!ret) return 0;
if (wait_event_timeout(*wq, (READ_ONCE(*ack_ptr) & req_mask) == req,
msecs_to_jiffies(timeout_ms))) return 0;
/* Check one last time, in case we were not woken up for some reason. */
ack = READ_ONCE(*ack_ptr); if ((ack & req_mask) == req) return 0;
/** * panthor_fw_glb_wait_acks() - Wait for global requests to be acknowledged. * @ptdev: Device. * @req_mask: Mask of requests to wait for. * @acked: Pointer to field that's updated with the acked requests. * If the function returns 0, *acked == req_mask. * @timeout_ms: Timeout expressed in milliseconds. * * Return: 0 on success, -ETIMEDOUT otherwise.
*/ int panthor_fw_glb_wait_acks(struct panthor_device *ptdev,
u32 req_mask, u32 *acked,
u32 timeout_ms)
{ struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev);
/* GLB_HALT doesn't get acked through the FW interface. */ if (drm_WARN_ON(&ptdev->base, req_mask & (~GLB_REQ_MASK | GLB_HALT))) return -EINVAL;
/** * panthor_fw_csg_wait_acks() - Wait for command stream group requests to be acknowledged. * @ptdev: Device. * @csg_slot: CSG slot ID. * @req_mask: Mask of requests to wait for. * @acked: Pointer to field that's updated with the acked requests. * If the function returns 0, *acked == req_mask. * @timeout_ms: Timeout expressed in milliseconds. * * Return: 0 on success, -ETIMEDOUT otherwise.
*/ int panthor_fw_csg_wait_acks(struct panthor_device *ptdev, u32 csg_slot,
u32 req_mask, u32 *acked, u32 timeout_ms)
{ struct panthor_fw_csg_iface *csg_iface = panthor_fw_get_csg_iface(ptdev, csg_slot); int ret;
if (drm_WARN_ON(&ptdev->base, req_mask & ~CSG_REQ_MASK)) return -EINVAL;
ret = panthor_fw_wait_acks(&csg_iface->input->req,
&csg_iface->output->ack,
&ptdev->fw->req_waitqueue,
req_mask, acked, timeout_ms);
/* * Check that all bits in the state field were updated, if any mismatch * then clear all bits in the state field. This allows code to do * (acked & CSG_STATE_MASK) and get the right value.
*/
if ((*acked & CSG_STATE_MASK) != CSG_STATE_MASK)
*acked &= ~CSG_STATE_MASK;
return ret;
}
/** * panthor_fw_ring_csg_doorbells() - Ring command stream group doorbells. * @ptdev: Device. * @csg_mask: Bitmask encoding the command stream group doorbells to ring. * * This function is toggling bits in the doorbell_req and ringing the * global doorbell. It doesn't require a user doorbell to be attached to * the group.
*/ void panthor_fw_ring_csg_doorbells(struct panthor_device *ptdev, u32 csg_mask)
{ struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.