linux kernel中cache代码解读

1、 在kernel中调用__dma_flush_range,底层是如何操作的呢?

/* remove any dirty cache lines on the kernel alias */
	__dma_flush_range(ptr, ptr + size);
/*
 *	__dma_flush_range(start, end)
 *	- start   - virtual start address of region
 *	- end     - virtual end address of region
 */
ENTRY(__dma_flush_range)
	dcache_line_size x2, x3    //获取cache line size, 保存在x2中
	sub	x3, x2, #1			//x3=x2-1,用于对其的Mask
	bic	x0, x0, x3			//地址对齐,x0就是__dma_flush_range(ptr, ptr + size)中的ptr虚拟地址
1:	dc	civac, x0			// invalid一行cache line,下面这一段是一个循环
	add	x0, x0, x2			//x0 = x0 + cache line size
	cmp	x0, x1				//比较x0和__dma_flush_range(ptr, ptr + size)中的ptr+size
	b.lo	1b
	dsb	sy
	ret
ENDPIPROC(__dma_flush_range)
/*

 * dcache_line_size - get the minimum D-cache line size from the CTR register.
 */
	.macro	dcache_line_size, reg, tmp
	mrs	\tmp, ctr_el0			// read CTR
	ubfm	\tmp, \tmp, #16, #19		// cache line size encoding
	mov	\reg, #4			// bytes per word
	lsl	\reg, \reg, \tmp		// actual cache line size

附上civac的寄存器和指令:
在这里插入图片描述

最后总结一下,__dma_flush_range(ptr, ptr+size)其实就是 invalid cache这一段虚拟地址

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Arm精选

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值