123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- /* SPDX-License-Identifier: GPL-2.0-only */
- /*
- * Copyright (c) 2021, The Linux Foundation. All rights reserved.
- * Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
- */
- #ifndef _ADRENO_GEN8_HWSCHED_HFI_H_
- #define _ADRENO_GEN8_HWSCHED_HFI_H_
- /* Maximum number of IBs in a submission */
- #define HWSCHED_MAX_NUMIBS \
- ((HFI_MAX_MSG_SIZE - offsetof(struct hfi_issue_cmd_cmd, ibs)) \
- / sizeof(struct hfi_issue_ib))
- /*
- * This is used to put userspace threads to sleep when hardware fence unack count reaches a
- * threshold. This bit is cleared in two scenarios:
- * 1. If the hardware fence unack count drops to a desired threshold.
- * 2. If there is a GMU/GPU fault. Because we don't want the threads to keep sleeping through fault
- * recovery, which can easily take 100s of milliseconds to complete.
- */
- #define GEN8_HWSCHED_HW_FENCE_SLEEP_BIT 0x0
- /*
- * This is used to avoid creating any more hardware fences until the hardware fence unack count
- * drops to a desired threshold. This bit is required in cases where GEN8_HWSCHED_HW_FENCE_SLEEP_BIT
- * will be cleared, but we still want to avoid creating any more hardware fences. For example, if
- * hardware fence unack count reaches a maximum threshold, both GEN8_HWSCHED_HW_FENCE_SLEEP_BIT and
- * GEN8_HWSCHED_HW_FENCE_MAX_BIT will be set. Say, a GMU/GPU fault happens and
- * GEN8_HWSCHED_HW_FENCE_SLEEP_BIT will be cleared to wake up any sleeping threads. But,
- * GEN8_HWSCHED_HW_FENCE_MAX_BIT will remain set to avoid creating any new hardware fences until
- * recovery is complete and deferred drawctxt (if any) is handled.
- */
- #define GEN8_HWSCHED_HW_FENCE_MAX_BIT 0x1
- /*
- * This is used to avoid creating any more hardware fences until concurrent reset/recovery completes
- */
- #define GEN8_HWSCHED_HW_FENCE_ABORT_BIT 0x2
- struct gen8_hwsched_hfi {
- struct hfi_mem_alloc_entry mem_alloc_table[32];
- u32 mem_alloc_entries;
- /** @irq_mask: Store the hfi interrupt mask */
- u32 irq_mask;
- /** @msglock: To protect the list of un-ACKed hfi packets */
- rwlock_t msglock;
- /** @msglist: List of un-ACKed hfi packets */
- struct list_head msglist;
- /** @f2h_task: Task for processing gmu fw to host packets */
- struct task_struct *f2h_task;
- /** @f2h_wq: Waitqueue for the f2h_task */
- wait_queue_head_t f2h_wq;
- /** @big_ib: GMU buffer to hold big IBs */
- struct kgsl_memdesc *big_ib;
- /** @big_ib_recurring: GMU buffer to hold big recurring IBs */
- struct kgsl_memdesc *big_ib_recurring;
- /** @msg_mutex: Mutex for accessing the msgq */
- struct mutex msgq_mutex;
- struct {
- /** @lock: Spinlock for managing hardware fences */
- spinlock_t lock;
- /**
- * @unack_count: Number of hardware fences sent to GMU but haven't yet been ack'd
- * by GMU
- */
- u32 unack_count;
- /**
- * @unack_wq: Waitqueue to wait on till number of unacked hardware fences drops to
- * a desired threshold
- */
- wait_queue_head_t unack_wq;
- /**
- * @defer_drawctxt: Drawctxt to send hardware fences from as soon as unacked
- * hardware fences drops to a desired threshold
- */
- struct adreno_context *defer_drawctxt;
- /**
- * @defer_ts: The timestamp of the hardware fence which got deferred
- */
- u32 defer_ts;
- /**
- * @flags: Flags to control the creation of new hardware fences
- */
- unsigned long flags;
- /** @seqnum: Sequence number for hardware fence packet header */
- atomic_t seqnum;
- } hw_fence;
- /**
- * @hw_fence_timer: Timer to trigger fault if unack'd hardware fence count does'nt drop
- * to a desired threshold in given amount of time
- */
- struct timer_list hw_fence_timer;
- /**
- * @hw_fence_ws: Work struct that gets scheduled when hw_fence_timer expires
- */
- struct work_struct hw_fence_ws;
- /** @detached_hw_fences_list: List of hardware fences belonging to detached contexts */
- struct list_head detached_hw_fence_list;
- /** @defer_hw_fence_work: The work structure to send deferred hardware fences to GMU */
- struct kthread_work defer_hw_fence_work;
- };
- struct kgsl_drawobj_cmd;
- /**
- * gen8_hwsched_hfi_probe - Probe hwsched hfi resources
- * @adreno_dev: Pointer to adreno device structure
- *
- * Return: 0 on success and negative error on failure.
- */
- int gen8_hwsched_hfi_probe(struct adreno_device *adreno_dev);
- /**
- * gen8_hwsched_hfi_remove - Release hwsched hfi resources
- * @adreno_dev: Pointer to adreno device structure
- */
- void gen8_hwsched_hfi_remove(struct adreno_device *adreno_dev);
- /**
- * gen8_hwsched_hfi_init - Initialize hfi resources
- * @adreno_dev: Pointer to adreno device structure
- *
- * This function is used to initialize hfi resources
- * once before the very first gmu boot
- *
- * Return: 0 on success and negative error on failure.
- */
- int gen8_hwsched_hfi_init(struct adreno_device *adreno_dev);
- /**
- * gen8_hwsched_hfi_start - Start hfi resources
- * @adreno_dev: Pointer to adreno device structure
- *
- * Send the various hfi packets before booting the gpu
- *
- * Return: 0 on success and negative error on failure.
- */
- int gen8_hwsched_hfi_start(struct adreno_device *adreno_dev);
- /**
- * gen8_hwsched_hfi_stop - Stop the hfi resources
- * @adreno_dev: Pointer to the adreno device
- *
- * This function does the hfi cleanup when powering down the gmu
- */
- void gen8_hwsched_hfi_stop(struct adreno_device *adreno_dev);
- /**
- * gen8_hwched_cp_init - Send CP_INIT via HFI
- * @adreno_dev: Pointer to adreno device structure
- *
- * This function is used to send CP INIT packet and bring
- * GPU out of secure mode using hfi raw packets.
- *
- * Return: 0 on success and negative error on failure.
- */
- int gen8_hwsched_cp_init(struct adreno_device *adreno_dev);
- /**
- * gen8_hfi_send_cmd_async - Send an hfi packet
- * @adreno_dev: Pointer to adreno device structure
- * @data: Data to be sent in the hfi packet
- * @size_bytes: Size of the packet in bytes
- *
- * Send data in the form of an HFI packet to gmu and wait for
- * it's ack asynchronously
- *
- * Return: 0 on success and negative error on failure.
- */
- int gen8_hfi_send_cmd_async(struct adreno_device *adreno_dev, void *data, u32 size_bytes);
- /**
- * gen8_hwsched_submit_drawobj - Dispatch IBs to dispatch queues
- * @adreno_dev: Pointer to adreno device structure
- * @drawobj: The command draw object which needs to be submitted
- *
- * This function is used to register the context if needed and submit
- * IBs to the hfi dispatch queues.
- * Return: 0 on success and negative error on failure
- */
- int gen8_hwsched_submit_drawobj(struct adreno_device *adreno_dev,
- struct kgsl_drawobj *drawobj);
- /**
- * gen8_hwsched_context_detach - Unregister a context with GMU
- * @drawctxt: Pointer to the adreno context
- *
- * This function sends context unregister HFI and waits for the ack
- * to ensure all submissions from this context have retired
- */
- void gen8_hwsched_context_detach(struct adreno_context *drawctxt);
- /* Helper function to get to gen8 hwsched hfi device from adreno device */
- struct gen8_hwsched_hfi *to_gen8_hwsched_hfi(struct adreno_device *adreno_dev);
- /**
- * gen8_hwsched_preempt_count_get - Get preemption count from GMU
- * @adreno_dev: Pointer to adreno device
- *
- * This function sends a GET_VALUE HFI packet to get the number of
- * preemptions completed since last SLUMBER exit.
- *
- * Return: Preemption count
- */
- u32 gen8_hwsched_preempt_count_get(struct adreno_device *adreno_dev);
- /**
- * gen8_hwsched_parse_payload - Parse payload to look up a key
- * @payload: Pointer to a payload section
- * @key: The key who's value is to be looked up
- *
- * This function parses the payload data which is a sequence
- * of key-value pairs.
- *
- * Return: The value of the key or 0 if key is not found
- */
- u32 gen8_hwsched_parse_payload(struct payload_section *payload, u32 key);
- /**
- * gen8_hwsched_lpac_cp_init - Send CP_INIT to LPAC via HFI
- * @adreno_dev: Pointer to adreno device structure
- *
- * This function is used to send CP INIT packet to LPAC and
- * enable submission to LPAC queue.
- *
- * Return: 0 on success and negative error on failure.
- */
- int gen8_hwsched_lpac_cp_init(struct adreno_device *adreno_dev);
- /**
- * gen8_hfi_send_lpac_feature_ctrl - Send the lpac feature hfi packet
- * @adreno_dev: Pointer to the adreno device
- *
- * Return: 0 on success or negative error on failure
- */
- int gen8_hfi_send_lpac_feature_ctrl(struct adreno_device *adreno_dev);
- /**
- * gen8_hwsched_context_destroy - Destroy any hwsched related resources during context destruction
- * @adreno_dev: Pointer to adreno device
- * @drawctxt: Pointer to the adreno context
- *
- * This functions destroys any hwsched related resources when this context is destroyed
- */
- void gen8_hwsched_context_destroy(struct adreno_device *adreno_dev,
- struct adreno_context *drawctxt);
- /**
- * gen8_hwsched_hfi_get_value - Send GET_VALUE packet to GMU to get the value of a property
- * @adreno_dev: Pointer to adreno device
- * @prop: property to get from GMU
- *
- * This functions sends GET_VALUE HFI packet to query value of a property
- *
- * Return: On success, return the value in the GMU response. On failure, return 0
- */
- u32 gen8_hwsched_hfi_get_value(struct adreno_device *adreno_dev, u32 prop);
- /**
- * gen8_send_hw_fence_hfi_wait_ack - Send hardware fence info to GMU
- * @adreno_dev: Pointer to adreno device
- * @entry: Pointer to the adreno hardware fence entry
- * @flags: Flags for this hardware fence
- *
- * Send the hardware fence info to the GMU and wait for the ack
- *
- * Return: 0 on success or negative error on failure
- */
- int gen8_send_hw_fence_hfi_wait_ack(struct adreno_device *adreno_dev,
- struct adreno_hw_fence_entry *entry, u64 flags);
- /**
- * gen8_hwsched_create_hw_fence - Create a hardware fence
- * @adreno_dev: Pointer to adreno device
- * @kfence: Pointer to the kgsl fence
- *
- * Create a hardware fence, set up hardware fence info and send it to GMU if required
- */
- void gen8_hwsched_create_hw_fence(struct adreno_device *adreno_dev,
- struct kgsl_sync_fence *kfence);
- /**
- * gen8_hwsched_drain_context_hw_fences - Drain context's hardware fences via GMU
- * @adreno_dev: Pointer to adreno device
- * @drawctxt: Pointer to the adreno context which is to be flushed
- *
- * Trigger hardware fences that were never dispatched to GMU
- *
- * Return: Zero on success or negative error on failure
- */
- int gen8_hwsched_drain_context_hw_fences(struct adreno_device *adreno_dev,
- struct adreno_context *drawctxt);
- /**
- * gen8_hwsched_check_context_inflight_hw_fences - Check whether all hardware fences
- * from a context have been sent to the TxQueue or not
- * @adreno_dev: Pointer to adreno device
- * @drawctxt: Pointer to the adreno context which is to be flushed
- *
- * Check if all hardware fences from this context have been sent to the
- * TxQueue. If not, log an error and return error code.
- *
- * Return: Zero on success or negative error on failure
- */
- int gen8_hwsched_check_context_inflight_hw_fences(struct adreno_device *adreno_dev,
- struct adreno_context *drawctxt);
- /**
- * gen8_remove_hw_fence_entry - Remove hardware fence entry
- * @adreno_dev: pointer to the adreno device
- * @entry: Pointer to the hardware fence entry
- */
- void gen8_remove_hw_fence_entry(struct adreno_device *adreno_dev,
- struct adreno_hw_fence_entry *entry);
- /**
- * gen8_trigger_hw_fence_cpu - Trigger hardware fence from cpu
- * @adreno_dev: pointer to the adreno device
- * @fence: hardware fence entry to be triggered
- *
- * Trigger the hardware fence by sending it to GMU's TxQueue and raise the
- * interrupt from GMU to APPS
- */
- void gen8_trigger_hw_fence_cpu(struct adreno_device *adreno_dev,
- struct adreno_hw_fence_entry *fence);
- /**
- * gen8_hwsched_disable_hw_fence_throttle - Disable hardware fence throttling after reset
- * @adreno_dev: pointer to the adreno device
- *
- * After device reset, clear hardware fence related data structures and send any hardware fences
- * that got deferred (prior to reset) and re-open the gates for hardware fence creation
- *
- * Return: Zero on success or negative error on failure
- */
- int gen8_hwsched_disable_hw_fence_throttle(struct adreno_device *adreno_dev);
- /**
- * gen8_hwsched_process_msgq - Process msgq
- * @adreno_dev: pointer to the adreno device
- *
- * This function grabs the msgq mutex and processes msgq for any outstanding hfi packets
- */
- void gen8_hwsched_process_msgq(struct adreno_device *adreno_dev);
- /**
- * gen8_hwsched_boot_gpu - Send the command to boot GPU
- * @adreno_dev: Pointer to adreno device
- *
- * Send the hfi to boot GPU, and check the ack, incase of a failure
- * get a snapshot and capture registers of interest.
- *
- * Return: Zero on success or negative error on failure
- */
- int gen8_hwsched_boot_gpu(struct adreno_device *adreno_dev);
- #endif
|