forked from Mirrors/opensbi
		
	lib: irqchip/plic: Add context save/restore helpers
These can be used by platform code to save the PLIC context state, if it would otherwise be lost during non-retentive suspend. The platform is responsible for allocating all necessary storage. Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
		
				
					committed by
					
						
						Anup Patel
					
				
			
			
				
	
			
			
			
						parent
						
							8c362e7d06
						
					
				
				
					commit
					415ecf28f7
				
			@@ -17,6 +17,12 @@ struct plic_data {
 | 
			
		||||
	unsigned long num_src;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void plic_context_save(const struct plic_data *plic, int context_id,
 | 
			
		||||
		       u32 *enable, u32 *threshold);
 | 
			
		||||
 | 
			
		||||
void plic_context_restore(const struct plic_data *plic, int context_id,
 | 
			
		||||
			  const u32 *enable, u32 threshold);
 | 
			
		||||
 | 
			
		||||
int plic_context_init(const struct plic_data *plic, int context_id,
 | 
			
		||||
		      bool enable, u32 threshold);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -29,6 +29,16 @@ static void plic_set_priority(const struct plic_data *plic, u32 source, u32 val)
 | 
			
		||||
	writel(val, plic_priority);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static u32 plic_get_thresh(const struct plic_data *plic, u32 cntxid)
 | 
			
		||||
{
 | 
			
		||||
	volatile void *plic_thresh;
 | 
			
		||||
 | 
			
		||||
	plic_thresh = (char *)plic->addr +
 | 
			
		||||
		      PLIC_CONTEXT_BASE + PLIC_CONTEXT_STRIDE * cntxid;
 | 
			
		||||
 | 
			
		||||
	return readl(plic_thresh);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void plic_set_thresh(const struct plic_data *plic, u32 cntxid, u32 val)
 | 
			
		||||
{
 | 
			
		||||
	volatile void *plic_thresh;
 | 
			
		||||
@@ -38,14 +48,49 @@ static void plic_set_thresh(const struct plic_data *plic, u32 cntxid, u32 val)
 | 
			
		||||
	writel(val, plic_thresh);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static u32 plic_get_ie(const struct plic_data *plic, u32 cntxid,
 | 
			
		||||
		       u32 word_index)
 | 
			
		||||
{
 | 
			
		||||
	volatile void *plic_ie;
 | 
			
		||||
 | 
			
		||||
	plic_ie = (char *)plic->addr +
 | 
			
		||||
		   PLIC_ENABLE_BASE + PLIC_ENABLE_STRIDE * cntxid +
 | 
			
		||||
		   4 * word_index;
 | 
			
		||||
 | 
			
		||||
	return readl(plic_ie);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void plic_set_ie(const struct plic_data *plic, u32 cntxid,
 | 
			
		||||
			u32 word_index, u32 val)
 | 
			
		||||
{
 | 
			
		||||
	volatile char *plic_ie;
 | 
			
		||||
	volatile void *plic_ie;
 | 
			
		||||
 | 
			
		||||
	plic_ie = (char *)plic->addr +
 | 
			
		||||
		   PLIC_ENABLE_BASE + PLIC_ENABLE_STRIDE * cntxid;
 | 
			
		||||
	writel(val, plic_ie + word_index * 4);
 | 
			
		||||
		   PLIC_ENABLE_BASE + PLIC_ENABLE_STRIDE * cntxid +
 | 
			
		||||
		   4 * word_index;
 | 
			
		||||
	writel(val, plic_ie);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void plic_context_save(const struct plic_data *plic, int context_id,
 | 
			
		||||
		       u32 *enable, u32 *threshold)
 | 
			
		||||
{
 | 
			
		||||
	u32 ie_words = (plic->num_src + 31) / 32;
 | 
			
		||||
 | 
			
		||||
	for (u32 i = 0; i < ie_words; i++)
 | 
			
		||||
		enable[i] = plic_get_ie(plic, context_id, i);
 | 
			
		||||
 | 
			
		||||
	*threshold = plic_get_thresh(plic, context_id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void plic_context_restore(const struct plic_data *plic, int context_id,
 | 
			
		||||
			  const u32 *enable, u32 threshold)
 | 
			
		||||
{
 | 
			
		||||
	u32 ie_words = (plic->num_src + 31) / 32;
 | 
			
		||||
 | 
			
		||||
	for (u32 i = 0; i < ie_words; i++)
 | 
			
		||||
		plic_set_ie(plic, context_id, i, enable[i]);
 | 
			
		||||
 | 
			
		||||
	plic_set_thresh(plic, context_id, threshold);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int plic_context_init(const struct plic_data *plic, int context_id,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user