freeBSD 还真是闭塞,资料太少~~
// char driver
struct cdev *
make_dev(struct cdevsw *devsw, int unit, uid_t uid, gid_t gid, int mode,
const char *fmt, ...)
conf.h: struct cdevsw ; struct cdev
地址空间映射
ioremap == pmap_mapdev
注册中断
A: bus_setup_intr
intr_event_add_handler
B: cpu_establish_hardintr
internal: (1)intr_event_create
(2)intr_event_add_handler
关闭所有中端
splhigh
splx
拷贝数据
copyin
copyout
uiomove
Poll 实现
selrecord
selwakeuppri
selwakeup
mmap实现: ???
1)phisical addr map:
typedef int d_mmap_t(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr,
int nprot);
paddr = physical address
2)内存
call vm_mmap
内核线程创建
kproc_create(old: kthread_create)
睡眠/唤醒
msleep,msleep_spin,pause,tsleep;wakeup.
mtx_sleep
rw_sleep
sx_sleep
初始进程栈:
/* Steal thread0 kstack.*/
kstack0 = pmap_steal_memory(KSTACK_PAGES << PAGE_SHIFT);
////LINUX/////
struct task_struct init_task = INIT_TASK(init_task);
////////////////////////////////
内存分配
物理内存分页 struct vm_page
//
整页 contigmalloc vtophys
DMA 分配 bus_dmamem_alloc
//
初始化:mi_startup->vm_mem_init->vm_page_startup->vm_phys_add_page
page to physical: VM_PAGE_TO_PHYS
物理page的预留:
new_end = trunc_page(end - page_range * sizeof(struct vm_page));
全局变量记录物理内存 physmem, phys_avail[]//修订
软中断
int swi_add(struct intr_event **eventp, const char *name, driver_intr_t handler,
void *arg, int pri, enum intr_type flags, void **cookiep)
swi_sched
swi_remove
任务队列
taskqueue_create
taskqueue_start_threads + taskqueue_thread_enqueue// (taskqueue_enqueue+taskqueue_run)
Difference: taskqueue_thread_enqueue / taskqueue_enqueue
TASK_INIT
taskqueue_drain taskqueue_free
网络驱动
//网络软中断
swi_net->netisr_queue_workstream :: raise by NWS_SIGNAL
//network driver.
if_var.c:struct ifnet ;
ifp->if_transmit = xxx_tx;// write code
if_ethersubr.c||ether_ifattach:
ifp->if_output = ether_output;
ifp->if_input = ether_input; // call this
ether_output->ether_output_frame->((ifp->if_transmit)(ifp, m));
pf_test->pf_route->if_output
ether_input->ether_demux->(ip_fastforward return m, will not handle)==>
ef_input->netisr_dispatch...>netisr_queue_internal
//NAPI通过 taskqueue_start_threads实现
阅读(897) | 评论(0) | 转发(0) |