포럼 회원으로 등록하신분만 다운로드가 가능합니다. 최대 업로드 가능한 용량은 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=687
List of Articles
번호 제목 글쓴이 날짜 조회 수sort
70 초보자를 위한 부트로더/커널/안드로이드 빌드 환경 설정 및 실습 [10] 이제현 2010-12-25 28983
69 USB만을 이용한 NFS 부팅 [23] 이제현 2010-01-11 21126
68 Android WiFi 포팅하기 file [6] 김경수 2010-05-07 19902
67 간단한 uBoot 사용 및 환경 설정 방법 [4] 김재훈 2009-01-29 19660
66 uboot에서 ubifs 이미지 nand에 쓰는 방법 [4] 엉금엉금 2010-08-04 19465
65 U-Boot 실무 위주의 간단한 강좌 #1 - Makefile 사용법 file [3] 김재훈 2008-07-11 18861
64 android-x86/Donut 을 viliv S5에 포팅해본본 내용입니다. [3] pinebud 2010-06-25 18591
63 Linux 2.6 커널의 이해 (Embedded World) file [19] 김재훈 2009-10-21 18038
62 임베디드 시스템 포팅 가이드(PXA255 ) #1 file [7] 김재훈 2009-05-17 18027
61 임베디드 엔지니어를 위한 리눅스 커널 file [9] 김재훈 2009-05-17 17400
60 Making ARM-EABI Toolchain #1 - Crosstool 환경 설정 file [1] 김재훈 2008-07-13 16926
59 범용 운영체제를 위한 리눅스 커널 완전분석 file [5] 김재훈 2009-05-17 16708
58 이광우님 android v4l2 camera porting자료 file [6] 고도리 2011-01-27 16691
57 Crosstool 0.43 - ARM Softfloat / ARM11-VFP EABI 지원 file [6] 김재훈 2008-07-19 16518
56 u-boot.lds 분석(aesop6410) 이세종 2009-04-13 16165
55 mdev and udev 사용 방법 및 적용 가이드 file 김재훈 2009-04-06 16105
54 U-Boot 및 펌웨어에서 MMU 매핑코드 분석 방법 [2] 김재훈 2009-10-21 16071
53 ARM EABI cross-toolchain howto file [4] 고현철 2008-07-09 16030
52 embedded linux porting guide(ppcboot & mpc860) file [4] 고현철 2007-12-17 15949
51 고현철님의 리눅스 Root File System 만들기 동영상 강좌 [2] 김재훈 2009-04-05 15537

사용자 로그인