포럼 회원으로 등록하신분만 다운로드가 가능합니다. 최대 업로드 가능한 용량은 20MB 입니다.

1.container_of // ==> 이녀석은 전체 문서에서 appendix로 보내야 하겠다.
 
- kernel.h
/**
 * container_of - cast a member of a structure out to the containing structure
 *
 * @ptr:        the pointer to the member.
 * @type:       the type of the container struct this is embedded in.
 * @member:     the name of the member within the struct.
 *
 */
#define container_of(ptr, type, member) ({                     
        const typeof( ((type *)0)->member ) *__mptr = (ptr);   
        (type *)( (char *)__mptr - offsetof(type,member) );})

ptr : 멤버의 포인터
type: 이 멤버를 포함하고 있는 컨테이너 스트럭쳐의 타입
member: type structure에 안에서 존재하는 멤버의 이름

 

ex> s3c2410 framebuffer의 경우

 

struct s3c2410fb_info {
 struct fb_info  fb;
 struct device  *dev;
 struct clk  *clk;

 struct s3c2410fb_mach_info *mach_info;

 /* raw memory addresses */
 dma_addr_t  map_dma; /* physical */
 u_char *  map_cpu; /* virtual */
 u_int   map_size;

 struct s3c2410fb_hw regs;

 /* addresses of pieces placed in raw buffer */
 u_char *  screen_cpu; /* virtual address of buffer */
 dma_addr_t  screen_dma; /* physical address of buffer */
 unsigned int  palette_ready;

 /* keep these registers in case we need to re-write palette */
 u32   palette_buffer[256];
 u32   pseudo_pal[16];
};

 

라는 s3c2410 고유의 스트럭쳐가 있을 경우  framebuffer main frame에서는 실제로

 

struct fb_info  fb;

 

만을 사용한다. 하지만 드라이버에서는 s3c2410 고유의 스트럭쳐를 필요로 한다.

해서 fb만을 가지고 s3c2410fb를 가져와야 한다.(실제로는 fb의 ptr을 가지고 해야한다.


왜냐하면 등록할때 s3c2410fb의 fb의 ptr을 가지고 등록하기 때문이다.)

해서 다음과 같은 inline함수를 만들어서 사용한다.

 

static inline struct s3c2410fb_info *fb_to_s3cfb(struct fb_info *info)
{
 return container_of(info, struct s3c2410fb_info, fb);
}

 

입력은 당연히 fb_info 형 ptr이 되고


출력은 이 녀석을 품고 있는 s3c2410fb_info structure의 ptr을 리턴해 줘야 한다.

맨 마지막 인자인 fb는 s3c2410fb_info에서의 fb_info라는 형을 가지는 녀석의 이름이
fb라고 얘기하는 것이다.

 

더 자세한 실제 코드는 aesop 2440 2.6.13 커널이나, 공식
리눅스 커널 2.6.13의 drivers/video/s3c2410_fb.c를 보시면 될겁니다.

 

"사람은 자기가 보고 싶은 현실만 볼 뿐이다." - Gaius Julius Caesar
엮인글 :
http://www.aesop.or.kr/index.php?mid=Board_Documents_Linux_Kernel&document_srl=35388&act=trackback&key=547
List of Articles
번호 제목 글쓴이 날짜sort 조회 수
70 devicetree usage 번역판 file [1] 고도리 2016-09-17 716
69 MTD/JFFS2 howto file 고도리 2015-06-17 403
68 DeviceTree for ARM 관련 간단 글. [3] 고도리 2013-08-27 5328
67 드라이버의 다이내믹 설정? [1] lveritas 2013-07-29 3479
66 Linux kernel Documentation DocBook 만들기 [1] 고도리 2012-08-25 5626
65 USB Gadget RNDIS ethernet howto - for C110/V210 file [5] 고도리 2012-02-28 11996
64 kernel architecture number(mach-types) 직접 커널에 입력하기 고도리 2011-08-15 9234
63 crosstool-ng 관련 site 고도리 2011-08-15 8462
» 리눅스 커널에서의 container_of macro 설명 고도리 2011-08-15 8895
61 리눅스 커널 dump_stack() 사용방법입니다. pinebud 2011-05-15 12105
60 ubuntu 에서 kubuntu ppa backports repository 지정방법 [1] 고도리 2011-05-10 10402
59 이광우님 android v4l2 camera porting자료 file [6] 고도리 2011-01-27 16691
58 초보자를 위한 부트로더/커널/안드로이드 빌드 환경 설정 및 실습 [10] 이제현 2010-12-25 28983
57 sysvinit howto입니다. file 고도리 2010-11-16 13902
56 busybox howto입니다 file 고도리 2010-11-16 13372
55 SMP kernel에서 interrut를 각 CPU별로 공유 하는 기사 입니다. 시안 2010-10-21 14222
54 cramfs 사용하기 file [2] 김경수 2010-09-07 14393
53 uboot에서 ubifs 이미지 nand에 쓰는 방법 [4] 엉금엉금 2010-08-04 19465
52 android-x86/Donut 을 viliv S5에 포팅해본본 내용입니다. [3] pinebud 2010-06-25 18591
51 Android WiFi 포팅하기 file [6] 김경수 2010-05-07 19902

사용자 로그인