From 1543e317f1da31b75942316931e8f491a8920811 Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Thu, 04 Jan 2024 10:08:02 +0000
Subject: [PATCH] disable FB
---
kernel/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware.h | 337 ++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 221 insertions(+), 116 deletions(-)
diff --git a/kernel/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware.h b/kernel/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware.h
index 6a78ff2..714a140 100644
--- a/kernel/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware.h
+++ b/kernel/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware.h
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
*
- * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved.
+ * (C) COPYRIGHT 2018-2022 ARM Limited. All rights reserved.
*
* This program is free software and is provided to you under the terms of the
* GNU General Public License version 2 as published by the Free Software
@@ -23,7 +23,7 @@
#define _KBASE_CSF_FIRMWARE_H_
#include "device/mali_kbase_device.h"
-#include <uapi/gpu/arm/bifrost/csf/mali_gpu_csf_registers.h>
+#include <csf/mali_kbase_csf_registers.h>
/*
* PAGE_KERNEL_RO was only defined on 32bit ARM in 4.19 in:
@@ -75,11 +75,8 @@
#define MAX_SUPPORTED_CSGS 31
/* GROUP_STREAM_NUM: At least 8 CSs per CSG, but no more than 32 */
#define MIN_SUPPORTED_STREAMS_PER_GROUP 8
-/* Maximum CSs per csg. */
+/* MAX_SUPPORTED_STREAMS_PER_GROUP: Maximum CSs per csg. */
#define MAX_SUPPORTED_STREAMS_PER_GROUP 32
-
-/* Waiting timeout for status change acknowledgment, in milliseconds */
-#define CSF_FIRMWARE_TIMEOUT_MS (3000) /* Relaxed to 3000ms from 800ms due to Android */
struct kbase_device;
@@ -327,36 +324,25 @@
u32 kbase_csf_firmware_global_output(
const struct kbase_csf_global_iface *iface, u32 offset);
-/* Calculate the offset to the Hw doorbell page corresponding to the
- * doorbell number.
+/**
+ * kbase_csf_ring_doorbell() - Ring the doorbell
+ *
+ * @kbdev: An instance of the GPU platform device
+ * @doorbell_nr: Index of the HW doorbell page
*/
-static u32 csf_doorbell_offset(int doorbell_nr)
-{
- WARN_ON(doorbell_nr >= CSF_NUM_DOORBELL);
-
- return CSF_HW_DOORBELL_PAGE_OFFSET +
- (doorbell_nr * CSF_HW_DOORBELL_PAGE_SIZE);
-}
-
-static inline void kbase_csf_ring_doorbell(struct kbase_device *kbdev,
- int doorbell_nr)
-{
- WARN_ON(doorbell_nr >= CSF_NUM_DOORBELL);
-
- kbase_reg_write(kbdev, csf_doorbell_offset(doorbell_nr), (u32)1);
-}
+void kbase_csf_ring_doorbell(struct kbase_device *kbdev, int doorbell_nr);
/**
* kbase_csf_read_firmware_memory - Read a value in a GPU address
+ *
+ * @kbdev: Device pointer
+ * @gpu_addr: GPU address to read
+ * @value: output pointer to which the read value will be written.
*
* This function read a value in a GPU address that belongs to
* a private firmware memory region. The function assumes that the location
* is not permanently mapped on the CPU address space, therefore it maps it
* and then unmaps it to access it independently.
- *
- * @kbdev: Device pointer
- * @gpu_addr: GPU address to read
- * @value: output pointer to which the read value will be written.
*/
void kbase_csf_read_firmware_memory(struct kbase_device *kbdev,
u32 gpu_addr, u32 *value);
@@ -364,20 +350,58 @@
/**
* kbase_csf_update_firmware_memory - Write a value in a GPU address
*
+ * @kbdev: Device pointer
+ * @gpu_addr: GPU address to write
+ * @value: Value to write
+ *
* This function writes a given value in a GPU address that belongs to
* a private firmware memory region. The function assumes that the destination
* is not permanently mapped on the CPU address space, therefore it maps it
* and then unmaps it to access it independently.
- *
- * @kbdev: Device pointer
- * @gpu_addr: GPU address to write
- * @value: Value to write
*/
void kbase_csf_update_firmware_memory(struct kbase_device *kbdev,
u32 gpu_addr, u32 value);
/**
- * kbase_csf_firmware_early_init() - Early initializatin for the firmware.
+ * kbase_csf_read_firmware_memory_exe - Read a value in a GPU address in the
+ * region of its final execution location.
+ *
+ * @kbdev: Device pointer
+ * @gpu_addr: GPU address to read
+ * @value: Output pointer to which the read value will be written
+ *
+ * This function read a value in a GPU address that belongs to a private loaded
+ * firmware memory region based on its final execution location. The function
+ * assumes that the location is not permanently mapped on the CPU address space,
+ * therefore it maps it and then unmaps it to access it independently. This function
+ * needs to be used when accessing firmware memory regions which will be moved to
+ * their final execution location during firmware boot using an address based on the
+ * final execution location.
+ */
+void kbase_csf_read_firmware_memory_exe(struct kbase_device *kbdev,
+ u32 gpu_addr, u32 *value);
+
+/**
+ * kbase_csf_update_firmware_memory_exe - Write a value in a GPU address in the
+ * region of its final execution location.
+ *
+ * @kbdev: Device pointer
+ * @gpu_addr: GPU address to write
+ * @value: Value to write
+ *
+ * This function writes a value in a GPU address that belongs to a private loaded
+ * firmware memory region based on its final execution location. The function
+ * assumes that the location is not permanently mapped on the CPU address space,
+ * therefore it maps it and then unmaps it to access it independently. This function
+ * needs to be used when accessing firmware memory regions which will be moved to
+ * their final execution location during firmware boot using an address based on the
+ * final execution location.
+ */
+void kbase_csf_update_firmware_memory_exe(struct kbase_device *kbdev,
+ u32 gpu_addr, u32 value);
+
+/**
+ * kbase_csf_firmware_early_init() - Early initialization for the firmware.
* @kbdev: Kbase device
*
* Initialize resources related to the firmware. Must be called at kbase probe.
@@ -387,43 +411,109 @@
int kbase_csf_firmware_early_init(struct kbase_device *kbdev);
/**
- * kbase_csf_firmware_init() - Load the firmware for the CSF MCU
+ * kbase_csf_firmware_early_term() - Terminate resources related to the firmware
+ * after the firmware unload has been done.
+ *
+ * @kbdev: Device pointer
+ *
+ * This should be called only when kbase probe fails or gets rmmoded.
+ */
+void kbase_csf_firmware_early_term(struct kbase_device *kbdev);
+
+/**
+ * kbase_csf_firmware_late_init() - Late initialization for the firmware.
+ * @kbdev: Kbase device
+ *
+ * Initialize resources related to the firmware. But must be called after
+ * backend late init is done. Must be used at probe time only.
+ *
+ * Return: 0 if successful, negative error code on failure
+ */
+int kbase_csf_firmware_late_init(struct kbase_device *kbdev);
+
+/**
+ * kbase_csf_firmware_load_init() - Load the firmware for the CSF MCU
* @kbdev: Kbase device
*
* Request the firmware from user space and load it into memory.
*
* Return: 0 if successful, negative error code on failure
*/
-int kbase_csf_firmware_init(struct kbase_device *kbdev);
+int kbase_csf_firmware_load_init(struct kbase_device *kbdev);
/**
- * kbase_csf_firmware_term() - Unload the firmware
+ * kbase_csf_firmware_unload_term() - Unload the firmware
* @kbdev: Kbase device
*
- * Frees the memory allocated by kbase_csf_firmware_init()
+ * Frees the memory allocated by kbase_csf_firmware_load_init()
*/
-void kbase_csf_firmware_term(struct kbase_device *kbdev);
+void kbase_csf_firmware_unload_term(struct kbase_device *kbdev);
+
+#if IS_ENABLED(CONFIG_MALI_CORESIGHT)
+/**
+ * kbase_csf_firmware_mcu_register_write - Write to MCU register
+ *
+ * @kbdev: Instance of a gpu platform device that implements a csf interface.
+ * @reg_addr: Register address to write into
+ * @reg_val: Value to be written
+ *
+ * Write a desired value to a register in MCU address space.
+ *
+ * return: 0 on success, or negative on failure.
+ */
+int kbase_csf_firmware_mcu_register_write(struct kbase_device *const kbdev, u32 const reg_addr,
+ u32 const reg_val);
+/**
+ * kbase_csf_firmware_mcu_register_read - Read from MCU register
+ *
+ * @kbdev: Instance of a gpu platform device that implements a csf interface.
+ * @reg_addr: Register address to read from
+ * @reg_val: Value as present in reg_addr register
+ *
+ * Read a value from MCU address space.
+ *
+ * return: 0 on success, or negative on failure.
+ */
+int kbase_csf_firmware_mcu_register_read(struct kbase_device *const kbdev, u32 const reg_addr,
+ u32 *reg_val);
+
+/**
+ * kbase_csf_firmware_mcu_register_poll - Poll MCU register
+ *
+ * @kbdev: Instance of a gpu platform device that implements a csf interface.
+ * @reg_addr: Register address to read from
+ * @val_mask: Value to mask the read value for comparison
+ * @reg_val: Value to be compared against
+ *
+ * Continue to read a value from MCU address space until it matches given mask and value.
+ *
+ * return: 0 on success, or negative on failure.
+ */
+int kbase_csf_firmware_mcu_register_poll(struct kbase_device *const kbdev, u32 const reg_addr,
+ u32 const val_mask, u32 const reg_val);
+#endif /* IS_ENABLED(CONFIG_MALI_CORESIGHT) */
/**
* kbase_csf_firmware_ping - Send the ping request to firmware.
*
- * The function sends the ping request to firmware.
- *
* @kbdev: Instance of a GPU platform device that implements a CSF interface.
+ *
+ * The function sends the ping request to firmware.
*/
void kbase_csf_firmware_ping(struct kbase_device *kbdev);
/**
* kbase_csf_firmware_ping_wait - Send the ping request to firmware and waits.
*
+ * @kbdev: Instance of a GPU platform device that implements a CSF interface.
+ * @wait_timeout_ms: Timeout to get the acknowledgment for PING request from FW.
+ *
* The function sends the ping request to firmware and waits to confirm it is
* alive.
*
- * @kbdev: Instance of a GPU platform device that implements a CSF interface.
- *
* Return: 0 on success, or negative on failure.
*/
-int kbase_csf_firmware_ping_wait(struct kbase_device *kbdev);
+int kbase_csf_firmware_ping_wait(struct kbase_device *kbdev, unsigned int wait_timeout_ms);
/**
* kbase_csf_firmware_set_timeout - Set a hardware endpoint progress timeout.
@@ -442,17 +532,37 @@
/**
* kbase_csf_enter_protected_mode - Send the Global request to firmware to
- * enter protected mode and wait for its
- * completion.
+ * enter protected mode.
*
* @kbdev: Instance of a GPU platform device that implements a CSF interface.
+ *
+ * The function must be called with kbdev->csf.scheduler.interrupt_lock held
+ * and it does not wait for the protected mode entry to complete.
*/
void kbase_csf_enter_protected_mode(struct kbase_device *kbdev);
+/**
+ * kbase_csf_wait_protected_mode_enter - Wait for the completion of PROTM_ENTER
+ * Global request sent to firmware.
+ *
+ * @kbdev: Instance of a GPU platform device that implements a CSF interface.
+ *
+ * This function needs to be called after kbase_csf_enter_protected_mode() to
+ * wait for the GPU to actually enter protected mode. GPU reset is triggered if
+ * the wait is unsuccessful.
+ *
+ * Return: 0 on success, or negative on failure.
+ */
+int kbase_csf_wait_protected_mode_enter(struct kbase_device *kbdev);
+
static inline bool kbase_csf_firmware_mcu_halted(struct kbase_device *kbdev)
{
+#if IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI)
+ return true;
+#else
return (kbase_reg_read(kbdev, GPU_CONTROL_REG(MCU_STATUS)) ==
MCU_STATUS_HALTED);
+#endif /* CONFIG_MALI_BIFROST_NO_MALI */
}
/**
@@ -470,24 +580,14 @@
*
* @kbdev: Instance of a GPU platform device that implements a CSF interface.
*/
-static inline void kbase_csf_firmware_enable_mcu(struct kbase_device *kbdev)
-{
- /* Trigger the boot of MCU firmware, Use the AUTO mode as
- * otherwise on fast reset, to exit protected mode, MCU will
- * not reboot by itself to enter normal mode.
- */
- kbase_reg_write(kbdev, GPU_CONTROL_REG(MCU_CONTROL), MCU_CNTRL_AUTO);
-}
+void kbase_csf_firmware_enable_mcu(struct kbase_device *kbdev);
/**
* kbase_csf_firmware_disable_mcu - Send the command to disable MCU
*
* @kbdev: Instance of a GPU platform device that implements a CSF interface.
*/
-static inline void kbase_csf_firmware_disable_mcu(struct kbase_device *kbdev)
-{
- kbase_reg_write(kbdev, GPU_CONTROL_REG(MCU_CONTROL), MCU_CNTRL_DISABLE);
-}
+void kbase_csf_firmware_disable_mcu(struct kbase_device *kbdev);
/**
* kbase_csf_firmware_disable_mcu_wait - Wait for the MCU to reach disabled
@@ -497,10 +597,30 @@
*/
void kbase_csf_firmware_disable_mcu_wait(struct kbase_device *kbdev);
+#ifdef KBASE_PM_RUNTIME
/**
- * kbase_trigger_firmware_reload - Trigger the reboot of MCU firmware, for the
- * cold boot case firmware image would be
- * reloaded from filesystem into memory.
+ * kbase_csf_firmware_trigger_mcu_sleep - Send the command to put MCU in sleep
+ * state.
+ *
+ * @kbdev: Instance of a GPU platform device that implements a CSF interface.
+ */
+void kbase_csf_firmware_trigger_mcu_sleep(struct kbase_device *kbdev);
+
+/**
+ * kbase_csf_firmware_is_mcu_in_sleep - Check if sleep request has completed
+ * and MCU has halted.
+ *
+ * @kbdev: Instance of a GPU platform device that implements a CSF interface.
+ *
+ * Return: true if sleep request has completed, otherwise false.
+ */
+bool kbase_csf_firmware_is_mcu_in_sleep(struct kbase_device *kbdev);
+#endif
+
+/**
+ * kbase_csf_firmware_trigger_reload() - Trigger the reboot of MCU firmware, for
+ * the cold boot case firmware image would
+ * be reloaded from filesystem into memory.
*
* @kbdev: Instance of a GPU platform device that implements a CSF interface.
*/
@@ -529,9 +649,9 @@
* requests, sent after the reboot of MCU firmware, have
* completed or not.
*
- * Return: true if the Global configuration requests completed otherwise false.
- *
* @kbdev: Instance of a GPU platform device that implements a CSF interface.
+ *
+ * Return: true if the Global configuration requests completed otherwise false.
*/
bool kbase_csf_firmware_global_reinit_complete(struct kbase_device *kbdev);
@@ -556,17 +676,16 @@
* request has completed or not, that was sent to update
* the core attributes.
*
+ * @kbdev: Instance of a GPU platform device that implements a CSF interface.
+ *
* Return: true if the Global configuration request to update the core
* attributes has completed, otherwise false.
- *
- * @kbdev: Instance of a GPU platform device that implements a CSF interface.
*/
bool kbase_csf_firmware_core_attr_updated(struct kbase_device *kbdev);
/**
- * Request the global control block of CSF interface capabilities
- *
- * Return: Total number of CSs, summed across all groups.
+ * kbase_csf_firmware_get_glb_iface - Request the global control block of CSF
+ * interface capabilities
*
* @kbdev: Kbase device.
* @group_data: Pointer where to store all the group data
@@ -589,6 +708,8 @@
* @instr_features: Instrumentation features. Bits 7:4 hold the max size
* of events. Bits 3:0 hold the offset update rate.
* (csf >= 1,1,0)
+ *
+ * Return: Total number of CSs, summed across all groups.
*/
u32 kbase_csf_firmware_get_glb_iface(
struct kbase_device *kbdev, struct basep_cs_group_control *group_data,
@@ -597,20 +718,26 @@
u32 *group_num, u32 *prfcnt_size, u32 *instr_features);
/**
- * Get CSF firmware header timeline metadata content
- *
- * Return: The firmware timeline metadata content which match @p name.
+ * kbase_csf_firmware_get_timeline_metadata - Get CSF firmware header timeline
+ * metadata content
*
* @kbdev: Kbase device.
* @name: Name of the metadata which metadata content to be returned.
* @size: Metadata size if specified metadata found.
+ *
+ * Return: The firmware timeline metadata content which match @p name.
*/
const char *kbase_csf_firmware_get_timeline_metadata(struct kbase_device *kbdev,
const char *name, size_t *size);
/**
- * kbase_csf_firmware_mcu_shared_mapping_init -
- * Allocate and map MCU shared memory.
+ * kbase_csf_firmware_mcu_shared_mapping_init - Allocate and map MCU shared memory.
+ *
+ * @kbdev: Kbase device the memory mapping shall belong to.
+ * @num_pages: Number of memory pages to map.
+ * @cpu_map_properties: Either PROT_READ or PROT_WRITE.
+ * @gpu_map_properties: Either KBASE_REG_GPU_RD or KBASE_REG_GPU_WR.
+ * @csf_mapping: Object where to write metadata for the memory mapping.
*
* This helper function allocates memory and maps it on both the CPU
* and the GPU address spaces. Most of the properties of the mapping
@@ -622,12 +749,6 @@
* will be ignored by the function.
*
* Return: 0 if success, or an error code on failure.
- *
- * @kbdev: Kbase device the memory mapping shall belong to.
- * @num_pages: Number of memory pages to map.
- * @cpu_map_properties: Either PROT_READ or PROT_WRITE.
- * @gpu_map_properties: Either KBASE_REG_GPU_RD or KBASE_REG_GPU_WR.
- * @csf_mapping: Object where to write metadata for the memory mapping.
*/
int kbase_csf_firmware_mcu_shared_mapping_init(
struct kbase_device *kbdev,
@@ -645,36 +766,7 @@
void kbase_csf_firmware_mcu_shared_mapping_term(
struct kbase_device *kbdev, struct kbase_csf_mapping *csf_mapping);
-#ifndef MALI_KBASE_BUILD
-/**
- * mali_kutf_process_fw_utf_entry() - Process the "Firmware UTF tests" section
- *
- * Read "Firmware UTF tests" section from the firmware image and create
- * necessary kutf app+suite+tests.
- *
- * Return: 0 if successful, negative error code on failure. In both cases
- * caller will have to invoke mali_kutf_fw_utf_entry_cleanup for the cleanup
- *
- * @kbdev: Kbase device structure
- * @fw_data: Pointer to the start of firmware binary image loaded from disk
- * @fw_size: Size (in bytes) of the firmware image
- * @entry: Pointer to the start of the section
- */
-int mali_kutf_process_fw_utf_entry(struct kbase_device *kbdev,
- const void *fw_data, size_t fw_size, const u32 *entry);
-
-/**
- * mali_kutf_fw_utf_entry_cleanup() - Remove the Fw UTF tests debugfs entries
- *
- * Destroy the kutf apps+suites+tests created on parsing "Firmware UTF tests"
- * section from the firmware image.
- *
- * @kbdev: Kbase device structure
- */
-void mali_kutf_fw_utf_entry_cleanup(struct kbase_device *kbdev);
-#endif
-
-#ifdef CONFIG_MALI_BIFROST_DEBUG
+#ifdef CONFIG_MALI_BIFROST_DEBUG
extern bool fw_debug;
#endif
@@ -691,11 +783,11 @@
* kbase_csf_firmware_enable_gpu_idle_timer() - Activate the idle hysteresis
* monitoring operation
*
+ * @kbdev: Kbase device structure
+ *
* Program the firmware interface with its configured hysteresis count value
* and enable the firmware to act on it. The Caller is
* assumed to hold the kbdev->csf.scheduler.interrupt_lock.
- *
- * @kbdev: Kbase device structure
*/
void kbase_csf_firmware_enable_gpu_idle_timer(struct kbase_device *kbdev);
@@ -703,10 +795,10 @@
* kbase_csf_firmware_disable_gpu_idle_timer() - Disable the idle time
* hysteresis monitoring operation
*
+ * @kbdev: Kbase device structure
+ *
* Program the firmware interface to disable the idle hysteresis timer. The
* Caller is assumed to hold the kbdev->csf.scheduler.interrupt_lock.
- *
- * @kbdev: Kbase device structure
*/
void kbase_csf_firmware_disable_gpu_idle_timer(struct kbase_device *kbdev);
@@ -741,18 +833,18 @@
u32 kbase_csf_firmware_set_gpu_idle_hysteresis_time(struct kbase_device *kbdev, u32 dur);
/**
- * kbase_csf_firmware_get_mcu_core_pwroff_time - Get the MCU core power-off
+ * kbase_csf_firmware_get_mcu_core_pwroff_time - Get the MCU shader Core power-off
* time value
*
* @kbdev: Instance of a GPU platform device that implements a CSF interface.
*
- * Return: the internally recorded MCU core power-off (nominal) value. The unit
+ * Return: the internally recorded MCU shader Core power-off (nominal) timeout value. The unit
* of the value is in micro-seconds.
*/
u32 kbase_csf_firmware_get_mcu_core_pwroff_time(struct kbase_device *kbdev);
/**
- * kbase_csf_firmware_set_mcu_core_pwroff_time - Set the MCU core power-off
+ * kbase_csf_firmware_set_mcu_core_pwroff_time - Set the MCU shader Core power-off
* time value
*
* @kbdev: Instance of a GPU platform device that implements a CSF interface.
@@ -769,7 +861,7 @@
* returned value is the source configuration flag, and it is set to '1'
* when CYCLE_COUNTER alternative source is used.
*
- * The configured MCU core power-off timer will only have effect when the host
+ * The configured MCU shader Core power-off timer will only have effect when the host
* driver has delegated the shader cores' power management to MCU.
*
* Return: the actual internal core power-off timer value in register defined
@@ -780,7 +872,7 @@
/**
* kbase_csf_interface_version - Helper function to build the full firmware
* interface version in a format compatible with
- * with GLB_VERSION register
+ * GLB_VERSION register
*
* @major: major version of csf interface
* @minor: minor version of csf interface
@@ -808,4 +900,17 @@
* Return: 0 if success, or negative error code on failure.
*/
int kbase_csf_trigger_firmware_config_update(struct kbase_device *kbdev);
+
+/**
+ * kbase_csf_firmware_req_core_dump - Request a firmware core dump
+ *
+ * @kbdev: Instance of a GPU platform device that implements a CSF interface.
+ *
+ * Request a firmware core dump and wait for for firmware to acknowledge.
+ * Firmware will enter infinite loop after the firmware core dump is created.
+ *
+ * Return: 0 if success, or negative error code on failure.
+ */
+int kbase_csf_firmware_req_core_dump(struct kbase_device *const kbdev);
+
#endif
--
Gitblit v1.6.2