포럼 회원으로 등록하신분만 다운로드가 가능합니다. 최대 업로드 가능한 용량은 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=63f
List of Articles
번호 제목 글쓴이 날짜 조회 수sort
70 MTD/JFFS2 howto file 고도리 2015-06-17 403
69 devicetree usage 번역판 file [1] 고도리 2016-09-17 716
68 드라이버의 다이내믹 설정? [1] lveritas 2013-07-29 3479
67 DeviceTree for ARM 관련 간단 글. [3] 고도리 2013-08-27 5423
66 Linux kernel Documentation DocBook 만들기 [1] 고도리 2012-08-25 5626
65 crosstool-ng 관련 site 고도리 2011-08-15 8462
» 리눅스 커널에서의 container_of macro 설명 고도리 2011-08-15 8895
63 kernel architecture number(mach-types) 직접 커널에 입력하기 고도리 2011-08-15 9234
62 autologin 고현철 2009-01-30 9886
61 debug print문(kernel & app용) 고현철 2009-01-30 10060
60 Creating a Root File System for Linux on OMAP35x 장석원 2009-04-24 10114
59 Embedded linux Swap howto 고현철 2009-01-30 10252
58 ubuntu 에서 kubuntu ppa backports repository 지정방법 [1] 고도리 2011-05-10 10403
57 ramdisk howto file 고현철 2009-01-30 10622
56 uBuntu 8.10에서 Crosstool 0.43 사용 방법 [2] 김재훈 2009-02-18 10780
55 2.6.28 kernel에서 sk_buff에서 mac header를 가져오고 찍는 방법 [1] 고현철 2009-02-10 10864
54 GStreamer on TI DaVinci and OMAP 장석원 2009-04-25 10929
53 kernel 2.6(S3C64XX)용 kernel image구조 고현철 2009-02-16 10982
52 임베디드 시스템 포팅 가이드(PXA255 ) #2 file 김재훈 2009-05-17 11018
51 Windows CE에서 NK.bin에 포함된 모듈 확인 하는 방법 file [1] 김재훈 2009-02-04 11030

사용자 로그인