skip to main
|
skip to sidebar
顯示具有
linux driver
標籤的文章。
顯示所有文章
顯示具有
linux driver
標籤的文章。
顯示所有文章
2008年9月11日 星期四
scsi_execute_req
int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd,
int data_direction, void *buffer, unsigned bufflen,
struct scsi_sense_hdr *sshdr, int timeout, int retries)
scsi command code
include/scsi/scsi.h
READ_6 0x08
WRITE_6 0x0a
READ_10 0x28
WRITE_10 0x2a
READ_16 0x88
WRITE_16 0x8a
website about block driver
http://www.geocities.com/ravikiran_uvs/articles/
proc
read_proc
struct dentry *
proc_lookup
(struct inode * dir, struct dentry *dentry)
2008年9月9日 星期二
struct scsi_cmnd
/* These elements define the operation we are about to perform */
#define MAX_COMMAND_SIZE 16
unsigned char cmnd[MAX_COMMAND_SIZE];
2008年9月4日 星期四
struct scsi_sense_hdr
scsi_en.h
struct scsi_sense_hdr { /* See SPC-3 section 4.5 */
u8 response_code; /* permit: 0x0, 0x70, 0x71, 0x72, 0x73 */
u8 sense_key;
u8 asc;
u8 ascq;
u8 byte4;
u8 byte5;
u8 byte6;
u8 additional_length; /* always 0 for fixed sense format */
};
2008年8月29日 星期五
random number in driver
get_random_bytes():
ex:
unsigned char uuid[16];
get_random_bytes(uuid, sizeof (uuid));
2008年8月28日 星期四
type definition
struct block_device:
linux/fs.h
dev_t:
linux/types.h
struct page:
linux/mm_types.h
struct gendisk:
linux/genhd.h
struct request_queue:
linux/blkdev.h
wait_queue_head_t:
linux/wait.h
spinlock_t:
linux/spinlock_types.h
struct semaphore:
linux/semaphore.h
2008年8月19日 星期二
dm
//The request function that just remaps the bio built up by dm_merge_bvec
static int dm_request(struct request_queue *q, struct bio *bio)
call __split_bio
// Split the bio into several clones.
static int __split_bio(struct mapped_device *md, struct bio *bio)
call __clone_and_map with parameter ci
( ci.sector_count= bio_sectors(bio) )
static int __clone_and_map(struct clone_info *ci)
call split_bvec
2008年8月18日 星期一
sector_t
typedef unsigned long
sector_t
;
2008年8月17日 星期日
struct bio
struct bio
:
struct block_device *bi_bdev;
struct bio_vec *bi_io_vec; /* the actual vec list */
unsigned short bi_vcnt; /* how many bio_vec's */
unsigned int bi_size; /* residual I/O count */
struct bio_vec:
struct
page
*
bv_page
;
unsigned int
bv_len
;
unsigned int
bv_offset
;
do I/O without request queue
three steps:
1. define a make_request function
ex:
static int sbull_make_request(request_queue_t *q, struct bio *bio)
in the make_request function, transfer bio & call bio_endio(struct bio *bio, unsigned int bytes, int error) to signal completion
2. use blk_alloc_queue(GFP_KERNEL) to allocate a queue
3. call blk_queue_make_request(request_queue_t *queue, make_request_fn *func)
when make_request function return non-zero:
the bio is submitted again. Hence, we can modify bi_bdev & starting sector to redirect bio to another device
split bio into multiple chunks:
bio_split
kthread
show kthread list
ps -ef
2008年8月16日 星期六
interrupt
prevent interrupt entering critical section
method 1:
local_irq_disable(); /* Disable Interrupts in local CPU */
/* ... Critical Section ... */
local_irq_enable(); /* Enable Interrupts in local CPU */
method 2:
unsigned long flags;
Point A:
local_irq_save(flags); /* Disable Interrupts */
/* ... Critical Section ... */
local_irq_restore(flags); /* Restore state to what it was at point A */
spinlock & mutex
spinlock ensures only one thread can enter critical section
spinlock example:
#include
spinlock_t mylock = SPIN_LOCK_UNLOCKED; /* Initialize */
/* Acquire the spinlock. This is inexpensive if there
* is no one inside the critical section. In the face of
* contention, spinlock() has to busy-wait.
*/
spin_lock(&mylock);
/* ... Critical Section code ... */
spin_unlock(&mylock); /* Release the lock */
spinlock will busy-wait, mutex will sleep
mutex example:
#include
/* Statically declare a mutex. To dynamically
create a mutex, use mutex_init() */
static DEFINE_MUTEX(mymutex);
/* Acquire the mutex. This is inexpensive if there
* is no one inside the critical section. In the face of
* contention, mutex_lock() puts the calling thread to sleep.
*/
mutex_lock(&mymutex);
/* ... Critical Section code ... */
mutex_unlock(&mymutex); /* Release the mutex */
linux開機設定
GRUB:
/boot/grub/grub.conf or /boot/grub/menu.lst
grub.conf example:
default 0 #Boot the 2.6.23 kernel by default
timeout 5 #5 second to alter boot order or parameters
title kernel 2.6.23 #Boot Option 1
#The boot image resides in the first partition of the first disk
#under the /boot/ directory and is named vmlinuz-2.6.23. 'ro'
#indicates that the root partition should be mounted read-only.
kernel (hd0,0)/boot/vmlinuz-2.6.23 ro root=/dev/hda1
#Look under section "Freeing initrd memory:387k freed"
initrd (hd0,0)/boot/initrd
#...
LILO:
/etc/lilo.conf
compile driver
method 1:
Makefile:
obj-m+=test.ko
make -C /usr/src/kernels/x.y.z/ M=`pwd` modules
kernel source module
compile module:
1. cd /usr/src/linux-x.y.z/
2. make modules
install module
1. make modules_install
the generated module( ko) is stored in /lib/modules/x.y.z/kernel/
2008年8月15日 星期五
patch
A patch is a text file containing source code differences between a development tree and the original snapshot from which the developer started work
apply patch:
ex: if x.y.z-mm2.bz2 is a patch, go to the directory of linux source
bzip2 -dc ../x.y.z-mm2.bz2 | patch -p1
create patch:
ex:
diff -Nur /path/originalKernal/ /path/newKernel > change changes.patch
2008年8月13日 星期三
linux module location
/lib/modules/2.6.18-92.el5/kernel/drivers
較舊的文章
首頁
訂閱:
文章 (Atom)
deeply love linux
標籤
c
linux command
linux driver
linux network
linux programming
linux socket
linux software
網誌存檔
▼
2009
(5)
▼
9月
(1)
install java on linux
►
1月
(4)
►
2008
(75)
►
12月
(10)
►
11月
(3)
►
10月
(5)
►
9月
(8)
►
8月
(25)
►
7月
(3)
►
6月
(4)
►
5月
(16)
►
4月
(1)
關於我自己
彼得潘
App程式設計入門 iPhone . iPad 第二版 2012.2 App程式設計入門 iPhone . iPad 第一版 2010.11
檢視我的完整簡介