xref: /rk3399_ARM-atf/bl32/tsp/tsp_interrupt.c (revision 239b04fa31647100c537852b4a3fc8bd47e33aa6)
16cf89021SAchin Gupta /*
26cf89021SAchin Gupta  * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
36cf89021SAchin Gupta  *
46cf89021SAchin Gupta  * Redistribution and use in source and binary forms, with or without
56cf89021SAchin Gupta  * modification, are permitted provided that the following conditions are met:
66cf89021SAchin Gupta  *
76cf89021SAchin Gupta  * Redistributions of source code must retain the above copyright notice, this
86cf89021SAchin Gupta  * list of conditions and the following disclaimer.
96cf89021SAchin Gupta  *
106cf89021SAchin Gupta  * Redistributions in binary form must reproduce the above copyright notice,
116cf89021SAchin Gupta  * this list of conditions and the following disclaimer in the documentation
126cf89021SAchin Gupta  * and/or other materials provided with the distribution.
136cf89021SAchin Gupta  *
146cf89021SAchin Gupta  * Neither the name of ARM nor the names of its contributors may be used
156cf89021SAchin Gupta  * to endorse or promote products derived from this software without specific
166cf89021SAchin Gupta  * prior written permission.
176cf89021SAchin Gupta  *
186cf89021SAchin Gupta  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
196cf89021SAchin Gupta  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
206cf89021SAchin Gupta  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
216cf89021SAchin Gupta  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
226cf89021SAchin Gupta  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
236cf89021SAchin Gupta  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
246cf89021SAchin Gupta  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
256cf89021SAchin Gupta  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
266cf89021SAchin Gupta  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
276cf89021SAchin Gupta  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
286cf89021SAchin Gupta  * POSSIBILITY OF SUCH DAMAGE.
296cf89021SAchin Gupta  */
306cf89021SAchin Gupta 
316cf89021SAchin Gupta #include <arch_helpers.h>
326cf89021SAchin Gupta #include <assert.h>
336cf89021SAchin Gupta #include <debug.h>
346cf89021SAchin Gupta #include <gic_v2.h>
356cf89021SAchin Gupta #include <tsp.h>
366cf89021SAchin Gupta #include <platform.h>
376cf89021SAchin Gupta 
386cf89021SAchin Gupta /*******************************************************************************
396cf89021SAchin Gupta  * This function updates the TSP statistics for FIQs handled synchronously i.e
406cf89021SAchin Gupta  * the ones that have been handed over by the TSPD. It also keeps count of the
416cf89021SAchin Gupta  * number of times control was passed back to the TSPD after handling an FIQ.
426cf89021SAchin Gupta  * In the future it will be possible that the TSPD hands over an FIQ to the TSP
436cf89021SAchin Gupta  * but does not expect it to return execution. This statistic will be useful to
446cf89021SAchin Gupta  * distinguish between these two models of synchronous FIQ handling.
456cf89021SAchin Gupta  * The 'elr_el3' parameter contains the address of the instruction in normal
466cf89021SAchin Gupta  * world where this FIQ was generated.
476cf89021SAchin Gupta  ******************************************************************************/
486cf89021SAchin Gupta void tsp_update_sync_fiq_stats(uint32_t type, uint64_t elr_el3)
496cf89021SAchin Gupta {
506cf89021SAchin Gupta 	uint64_t mpidr = read_mpidr();
516cf89021SAchin Gupta 	uint32_t linear_id = platform_get_core_pos(mpidr);
526cf89021SAchin Gupta 
536cf89021SAchin Gupta 	tsp_stats[linear_id].sync_fiq_count++;
546cf89021SAchin Gupta 	if (type == TSP_HANDLE_FIQ_AND_RETURN)
556cf89021SAchin Gupta 		tsp_stats[linear_id].sync_fiq_ret_count++;
566cf89021SAchin Gupta 
576cf89021SAchin Gupta 	spin_lock(&console_lock);
586cf89021SAchin Gupta 	printf("TSP: cpu 0x%x sync fiq request from 0x%llx \n\r",
596cf89021SAchin Gupta 	       mpidr, elr_el3);
606cf89021SAchin Gupta 	INFO("cpu 0x%x: %d sync fiq requests, %d sync fiq returns\n",
616cf89021SAchin Gupta 	     mpidr,
626cf89021SAchin Gupta 	     tsp_stats[linear_id].sync_fiq_count,
636cf89021SAchin Gupta 	     tsp_stats[linear_id].sync_fiq_ret_count);
646cf89021SAchin Gupta 	spin_unlock(&console_lock);
656cf89021SAchin Gupta }
666cf89021SAchin Gupta 
676cf89021SAchin Gupta /*******************************************************************************
686cf89021SAchin Gupta  * TSP FIQ handler called as a part of both synchronous and asynchronous
696cf89021SAchin Gupta  * handling of FIQ interrupts. It returns 0 upon successfully handling a S-EL1
706cf89021SAchin Gupta  * FIQ and treats all other FIQs as EL3 interrupts. It assumes that the GIC
716cf89021SAchin Gupta  * architecture version in v2.0 and the secure physical timer interrupt is the
726cf89021SAchin Gupta  * only S-EL1 interrupt that it needs to handle.
736cf89021SAchin Gupta  ******************************************************************************/
746cf89021SAchin Gupta int32_t tsp_fiq_handler()
756cf89021SAchin Gupta {
766cf89021SAchin Gupta 	uint64_t mpidr = read_mpidr();
776cf89021SAchin Gupta 	uint32_t linear_id = platform_get_core_pos(mpidr), id;
786cf89021SAchin Gupta 
796cf89021SAchin Gupta 	/*
806cf89021SAchin Gupta 	 * Get the highest priority pending interrupt id and see if it is the
816cf89021SAchin Gupta 	 * secure physical generic timer interrupt in which case, handle it.
826cf89021SAchin Gupta 	 * Otherwise throw this interrupt at the EL3 firmware.
836cf89021SAchin Gupta 	 */
846cf89021SAchin Gupta 	id = ic_get_pending_interrupt_id();
856cf89021SAchin Gupta 
866cf89021SAchin Gupta 	/* TSP can only handle the secure physical timer interrupt */
876cf89021SAchin Gupta 	if (id != IRQ_SEC_PHY_TIMER)
886cf89021SAchin Gupta 		return TSP_EL3_FIQ;
896cf89021SAchin Gupta 
906cf89021SAchin Gupta 	/*
916cf89021SAchin Gupta 	 * Handle the interrupt. Also sanity check if it has been preempted by
926cf89021SAchin Gupta 	 * another secure interrupt through an assertion.
936cf89021SAchin Gupta 	 */
946cf89021SAchin Gupta 	id = ic_acknowledge_interrupt();
956cf89021SAchin Gupta 	assert(id == IRQ_SEC_PHY_TIMER);
966cf89021SAchin Gupta 	tsp_generic_timer_handler();
976cf89021SAchin Gupta 	ic_end_of_interrupt(id);
986cf89021SAchin Gupta 
996cf89021SAchin Gupta 	/* Update the statistics and print some messages */
1006cf89021SAchin Gupta 	tsp_stats[linear_id].fiq_count++;
1016cf89021SAchin Gupta 	spin_lock(&console_lock);
1026cf89021SAchin Gupta 	printf("TSP: cpu 0x%x handled fiq %d \n\r",
1036cf89021SAchin Gupta 	       mpidr, id);
1046cf89021SAchin Gupta 	INFO("cpu 0x%x: %d fiq requests \n",
1056cf89021SAchin Gupta 	     mpidr, tsp_stats[linear_id].fiq_count);
1066cf89021SAchin Gupta 	spin_unlock(&console_lock);
1076cf89021SAchin Gupta 
1086cf89021SAchin Gupta 	return 0;
1096cf89021SAchin Gupta }
110*239b04faSSoby Mathew 
111*239b04faSSoby Mathew int32_t tsp_irq_received()
112*239b04faSSoby Mathew {
113*239b04faSSoby Mathew 	uint64_t mpidr = read_mpidr();
114*239b04faSSoby Mathew 	uint32_t linear_id = platform_get_core_pos(mpidr);
115*239b04faSSoby Mathew 
116*239b04faSSoby Mathew 	tsp_stats[linear_id].irq_count++;
117*239b04faSSoby Mathew 	spin_lock(&console_lock);
118*239b04faSSoby Mathew 	printf("TSP: cpu 0x%x received irq\n\r", mpidr);
119*239b04faSSoby Mathew 	INFO("cpu 0x%x: %d irq requests \n",
120*239b04faSSoby Mathew 	     mpidr, tsp_stats[linear_id].irq_count);
121*239b04faSSoby Mathew 	spin_unlock(&console_lock);
122*239b04faSSoby Mathew 
123*239b04faSSoby Mathew 	return TSP_PREEMPTED;
124*239b04faSSoby Mathew }
125