
linux驱动
不想做火影的海贼王
这个作者很懒,什么都没留下…
展开
-
Page migration
网址:https://www.kernel.org/doc/html/latest/vm/page_migration.htmlPage migration allows moving the physical location of pages between nodes in a NUMA system while the process is running. This means that the virtual addresses that the process sees do not cha原创 2021-05-24 20:46:12 · 175 阅读 · 0 评论 -
linux kernel-4.9 PageActive PageLRU等定义
code path:https://elixir.bootlin.com/linux/v4.9.269/source/include/linux/page-flags.hPAGEFLAG(Active, active, PF_HEAD) __CLEARPAGEFLAG(Active, active, PF_HEAD)TESTCLEARFLAG(Active, active, PF_HEAD)#define PAGEFLAG(uname, lname, policy) \ TESTPAGE原创 2021-05-24 20:20:44 · 825 阅读 · 0 评论 -
Linux gup
/** * __get_user_pages() - pin user pages in memory * @tsk: task_struct of target task * @mm: mm_struct of target mm * @start: starting user address * @nr_pages: number of pages from start to pin * @gup_flags: flags modifying pin behaviour * @pages原创 2021-05-24 11:58:14 · 1089 阅读 · 0 评论 -
vmap; kmap ; remap_vmalloc_range ; remap_pfn_range
vmap(). This can be used to make a long duration mapping of multiple physical pages into a contiguous virtual space. It needs global synchronization to unmap.kmap(). This permits a short duration mapping of a single page. It needs global synchronization,原创 2021-05-20 18:05:07 · 1002 阅读 · 0 评论 -
dump_stack 实现分析
1 .lib/dump_stack.cstatic void __dump_stack(void){ dump_stack_print_info(KERN_DEFAULT); show_stack(NULL, NULL);}2 .arch/arm64/kernel/traps.cvoid show_stack(struct task_struct *tsk, unsigned long *sp){ dump_backtrace(NULL, tsk); barrier();}dum原创 2021-04-25 20:36:01 · 539 阅读 · 0 评论 -
v4l2 use V4L2_MEMORY_MMAP方式,driver将buffer 转换为DMA 地址
建议使用以下方式进行vb2_queue 进行initstruct vb2_queue *q;q->mem_ops = &vb2_dma_sg_memops;这样 userspace reqbufs 就会使用 vb2_dma_sg_alloc 最终得到的是 struct sg_table *sgt;[ 43.365265]<3>[W](3)[<ffffff800808bb7c>] dump_backtrace+0x0/0x2c0[ 43.366029]原创 2021-04-14 11:13:26 · 1124 阅读 · 0 评论 -
v4l2 use V4L2_MEMORY_MMAP方式导出为 DMA BUF fd 方式使用
V4L2_MEMORY_MMAP 导出 fd 需要使用 vb2_ioctl_expbuf (只能使用于VB2_MEMORY_MMAP 方式)。int buffer_export(int v4lfd, enum v4l2_buf_type bt, int index, int *dmafd){ struct v4l2_exportbuffer expbuf; memset(&expbuf, 0, sizeof(expbuf)); expbuf.type = bt;原创 2021-04-13 11:57:36 · 4796 阅读 · 0 评论 -
v4l2 use dma buffer mode
user space struct v4l2_buffer buf; memset(&buf, 0, sizeof buf); buf.index = 0; buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_DMABUF; buf.m.fd = dbuf_fd; ret = ioctl(v4lfd, VIDIOC_QBUF, &buf);kernel/** * __qbuf_d原创 2021-04-13 10:21:59 · 3024 阅读 · 0 评论 -
spin_lock 调用 wait_for_completion 出现 KE 分析
spinlock_t数据类型,spin_lock(&lock)和spin_unlock(&lock)是加锁和解锁等待解锁的进程将反复检查锁是否释放,而不会进入睡眠状态(忙等待),所以常用于短期保护某段代码同时,持有自旋锁的进程也不允许睡眠,不然会造成死锁——因为睡眠可能造成持有锁的进程被重新调度,而再次申请自己已持有的锁。wait_for_completion,主要调用wait_for_common,而wait_for_common则主要是将当前线程加入等待队列,然后调用schedul原创 2021-03-19 21:39:39 · 289 阅读 · 0 评论 -
Linux GPIO使用以及debug 方法
debug 方法1cat /sys/kernel/debug/gpio原创 2021-02-25 09:52:42 · 966 阅读 · 0 评论 -
linux init时初始化中断号
[ 6.535890]<3>[I](3)OF: of_irq_parse_one: dev=/soc/xxx@12300000, index=0[ 6.536771]<3>[W](3)CPU: 3 PID: 1 Comm: swapper/0 Not tainted 4.9.118+ #356[ 6.537638]<3>[W](3)Hardware name: ATC Inc. AC8x (DT)[ 6.538266]<3>[W]原创 2021-02-22 20:42:19 · 458 阅读 · 0 评论 -
dma_map_single dma_map_sg理解
What memory is DMA'able?========================The first piece of information you must know is what kernel memory canbe used with the DMA mapping facilities. There has been an unwrittenset of rules regarding this, and this text is an attempt to fin.原创 2020-12-09 09:34:09 · 6021 阅读 · 0 评论 -
kernel 调试 API
dump 寄存器 show_regs(regs);code : https://elixir.bootlin.com/linux/v4.9.185/source/arch/arm64/kernel/process.cvoid __show_regs(struct pt_regs *regs){int i, top_reg;u64 lr, sp;if (compat_user_mode(regs)) { lr = regs->compat_lr; sp = regs->co.原创 2020-10-29 09:25:29 · 490 阅读 · 0 评论 -
slab 内存泄漏
kernel log 出现 lowmemorykiller 判断 kernel 出现了内存泄漏多次测试后对比 procrank 数据adb shell procrank > C:\procrank.txt测试前:RAM: 1814588K total, 359780K free, 7372K buffers, 701496K cached, 964K shmem, 138804K slab测试后:RAM: 1814588K total, 229016K free, 10204K原创 2020-10-14 14:02:22 · 1038 阅读 · 0 评论 -
v4l2 mmap 的原理
1.使用方法userspacestruct v4l2_requestbuffers reqbufs = { .count = 5, .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, .memory = V4L2_MEMORY_MMAP,};ioctl(dev_fd,VIDIOC_REQBUFS,&reqbufs);void *ptr[5];for (int i =0; i < 5 ; i++) { ptr[i] = mmap()NULL,buffe原创 2020-09-12 18:02:28 · 1424 阅读 · 0 评论 -
wait_event_interruptible 等到条件并被wakeup执行时,再次执行 wake_up_interruptible 会发生什么
wait_event_interruptible souece code#define __wait_event_interruptible(wq, condition, ret) \do { \ DEFINE_WAIT(__wait); \ \ for (;;) { \ prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \ if (condition)原创 2020-06-11 10:23:21 · 518 阅读 · 0 评论 -
qcom v4l2 实现分析
1.queue buf 过程Qcom HAL code/*=========================================================================== * FUNCTION : mm_stream_qbuf * * DESCRIPTION: enqueue buffer back to kernel queue for fu...原创 2020-04-14 21:11:44 · 492 阅读 · 0 评论 -
android YV12 地址偏移 与 line_stride 对齐
1.buffer地址偏移以分辨率 1280*720 格式为YV12 为例,Y起始地址为0x100000000 ,且是连续y_addr = 0x100000000;cb_addr = y_addr + 1280×720;cr_addr = cb_addr + 1280*720/4;2.line stride计算需要考虑到不同硬件使用相同的地址,如camera 写buffer...原创 2020-04-14 14:56:32 · 962 阅读 · 0 评论 -
Linux 常用调试命令汇总
top -H -O CPU 查看线程运行在相应的CPU上···top -H -O CPU[?25l[0m[H[J[s[999C[999B[6n[uTasks: 907 total, 2 running, 901 sleeping, 0 stopped, 0 zombieMem: 1853188k total, 1307684k used, 54550...原创 2020-04-10 18:00:58 · 670 阅读 · 1 评论 -
kernel 中 对 mutex 使用了memset 导致了 mutex_lock_nested 中出现了kernel panic
假设定义了一个结构体struct mutex_lock { struct mutex lock; }struct mutex_lock mutex_lock_t;在 mutex_init(&mutex_lock_t.lock)在后面的函数中调用了 memset(&mutex_lock_t,0,sizeof(struct mutex_lock)) ,...原创 2019-11-12 21:44:59 · 1537 阅读 · 0 评论 -
为自己的驱动写Kconfig 和 Makefile
写 android 驱动 的基本功就是把自己driver如何在kernel 中编译,下面将以led驱动为例1.定义使用的deconfig代码路径:kernel/arch/arm64/configs/xxxxx_defconfigCONFIG_XX_YY=y y 编译到内核m 编译成ko文件2.驱动上级目录中的配置代码路径:drivers/soc/Makefileobj-$(...原创 2019-06-10 09:14:41 · 313 阅读 · 0 评论 -
Linux驱动mmap内存映射
mmap在linux哪里?什么是mmap?上图说了,mmap是操作这些设备的一种方法,所谓操作设备,比如IO端口(点亮一个LED)、LCD控制器、磁盘控制器,实际上就是往设备的物理地址读写数据。但是,由于应用程序不能直接操作设备硬件地址,所以操作系统提供了这样的一种机制——内存映射,把设备地址映射到进程虚拟地址,mmap就是实现内存映射的接口。操作设备还有很多方法,如ioctl、iore...转载 2018-08-25 15:14:17 · 319 阅读 · 0 评论 -
Interrupt Context
ISRs (Interrupt handlers (ISRs))are critical pieces of code that directly converse with the hardware. They are given the privilege of instant execution in the larger interest of system performance. Ho...原创 2018-06-26 17:02:58 · 364 阅读 · 0 评论