포럼 회원으로 등록하신분만 다운로드가 가능합니다. 최대 업로드 가능한 용량은 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=161
List of Articles
번호 제목 글쓴이 날짜sort 조회 수
70 embedded linux porting guide(ppcboot & mpc860) file [4] 고현철 2007-12-17 15950
69 ARM EABI cross-toolchain howto file [4] 고현철 2008-07-09 16030
68 U-Boot 실무 위주의 간단한 강좌 #1 - Makefile 사용법 file [3] 김재훈 2008-07-11 18861
67 Making ARM-EABI Toolchain #1 - Crosstool 환경 설정 file [1] 김재훈 2008-07-13 16926
66 Crosstool 0.43 - ARM Softfloat / ARM11-VFP EABI 지원 file [6] 김재훈 2008-07-19 16518
65 간단한 uBoot 사용 및 환경 설정 방법 [4] 김재훈 2009-01-29 19660
64 autologin 고현철 2009-01-30 9886
63 debug print문(kernel & app용) 고현철 2009-01-30 10060
62 Embedded linux Swap howto 고현철 2009-01-30 10252
61 ramdisk howto file 고현철 2009-01-30 10622
60 NFS howto & options 고현철 2009-01-30 11154
59 Windows CE에서 NK.bin에 포함된 모듈 확인 하는 방법 file [1] 김재훈 2009-02-04 11030
58 2.6.28 kernel에서 sk_buff에서 mac header를 가져오고 찍는 방법 [1] 고현철 2009-02-10 10864
57 리눅스 루트 파일 시스템 기본 구조 및 스펙 문서 file [3] 김재훈 2009-02-12 14388
56 kernel 2.6(S3C64XX)용 kernel image구조 고현철 2009-02-16 10982
55 uBuntu 8.10에서 Crosstool 0.43 사용 방법 [2] 김재훈 2009-02-18 10780
54 linux kernel의 ethernet(MAC) address를 자동 지정해 주는 방법 [1] 고현철 2009-03-05 11513
53 고현철님의 리눅스 Root File System 만들기 동영상 강좌 [2] 김재훈 2009-04-05 15537
52 고현철님의 리눅스 Root File System 만들기 동영상 실습 김재훈 2009-04-05 12658
51 mdev and udev 사용 방법 및 적용 가이드 file 김재훈 2009-04-06 16105

사용자 로그인