[블로그 통합으로 이전해 온 자료] - 2008. 4. 30. 12:24

 

 

* platform device

platform_bus_type 이라는 가상의 플랫폼 버스 상에 새로운 디바이스를 등록하는 방법

 

 struct platform_device xxx_device =
 {
  .name =
  .id =
  .dev = xxx_device,   -> struct device
  .num_resources =
  .resource =     -> struct resource
 };

 platform_device_register()
 platform_device_register_simple()
 platform_device_unregister()

 xxx_init() / xxx_cleanup() 에서 등록
 


* platform driver

 struct platform_driver xxx_driver =
 {
  .probe =
  .remove =
  .shutdown =
  .suspend =
  .resume =
  .driver =
 }

 platform_driver_register()
 platform_driver_unregister()

 xxx_init() / xxx_cleanup() 에서 등록/해제

* 버스를 갖는 드라이버를 등록/해제

 struct device_driver xxx_driver
 {
  .name =
  .bus =
  .probe =
  .remove =
  .shutdown =
  .suspend =
  .resume =
 }
 
 driver_registrer()
 driver_unregistrer()

 xxx_init() / xxx_cleanup() 에서 등록

* platform resource

 struct resource
 {
  const char *name;
  unsigned long start, end;
  unsigned long flags;
  struct resource *parent, *sibling, *child;
 };
 

platform_device, platform_driver, device_driver 등의 구조체..
어떻게 써야하는지 아직도 모르겠다..

'실습 > 리눅스 커널' 카테고리의 다른 글

디바이스 드라이버의 동작  (0) 2021.02.08
Major, Minor #  (0) 2021.02.08
DMA 처리  (0) 2021.02.08
Memory Mapping  (0) 2021.02.08
인터럽트 (Interrupt) 처리  (0) 2021.02.08

[블로그 통합으로 이전해 온 자료] - 2008. 4. 29. 21:45

 

 

* 초기화

- 드라이버의 등록
- 드라이버의 동작에 필요한 내부 구조체 메모리 할당
- 여러 프로세스가 하나의 디바이스에 접근하는 경우에 필요한 사전 처리
- 주 번호에 종속된 부 번호를 관리하기 위한 사전 처리
- 하드웨어 검출 처리 및 에러 처리
- 하드웨어 초기화
- 사용 자원 등록
- 인터럽트 핸들러 등록


* 종료

- 드라이버의 해제
- 드라이버의 동작에 필요한 내부 구조체 메모리 해제
- 여러 프로세스가 하나의 디바이스에 접근하는 경우에 종료 처리
- 제거 가능한 하드웨어의 경우 제거 처리
- 사용 자원 해제
- 인터럽트 핸들러 해제


* 열기

- 여러 프로세스가 하나의 디바이스에 접근하는 경우에 필요한 사전 처리
- 하드웨어 검출 처리 및 에러 처리
- 하드웨어 초기화
- 응용 프로그램에서 드라이버를 사용하는 경우 초기 처리
- 부 번호에 관련된 프로세스별 처리
- 프로세스별 메모리 할당
- 사용 자원 등록
- 인터럽트 핸들러 등록


* 닫기

- 여러 프로세스가 하나의 디바이스에 접근하는 경우에 종료 처리
- 제거 가능한 하드웨어의 경우 제거 처리
- 응용 프로그램에서 드라이버를 사용하지 않는 경우 종료 처리
- 프로세스별 메모리 해제
- 사용 자원 해제
- 인터럽트 핸들러 해제


[서적] 리눅스 디바이스 드라이버 - 유영창 에서 발췌

'실습 > 리눅스 커널' 카테고리의 다른 글

platform driver, device  (0) 2021.02.08
Major, Minor #  (0) 2021.02.08
DMA 처리  (0) 2021.02.08
Memory Mapping  (0) 2021.02.08
인터럽트 (Interrupt) 처리  (0) 2021.02.08

[블로그 통합으로 이전해 온 자료] - 2008. 4. 29. 21:11

 

 

- 테스트나 특정 플랫폼용으로 사용 가능한 Major #

60 ~ 63
120 ~ 127
240 ~ 254


- Major 10 의 사용 가능한 Minor

240 ~ 255


- character device 중 major # 10을 가지는 device의 등록
char dev - major # 10의 minor #을 가지는 디바이스는
miscdevice이라고 해서 등록하는 함수가 따로 있다.

 

 <linux/miscdevice.h>
 
 struct file_operations xxx_misc_fop =
 {
 };
 
 struct miscdev xxx_miscdev =
 {
  .fops = &xxx_misc_fop,
  .minor = XXX_MINOR,
  .name = "xxx_misc",
 };
 
 xxx_init()
 {
  misc_register( &xxx_miscdev );
 }
 
 xxx_exit()
 {
  misc_deregister( &xxx_miscdev );
 }
 

 <linux/coda.h>
 <linux/kdev_t.h>
 
 dev_t devNum = MKDEV( XXX_MAJOR, XXX_MINOR );
 
 MINOR( inode->i_rdev )
 MAJOR( inode->i_rdev )

 
 
 

'실습 > 리눅스 커널' 카테고리의 다른 글

platform driver, device  (0) 2021.02.08
디바이스 드라이버의 동작  (0) 2021.02.08
DMA 처리  (0) 2021.02.08
Memory Mapping  (0) 2021.02.08
인터럽트 (Interrupt) 처리  (0) 2021.02.08

[블로그 통합으로 이전해 온 자료] - 2008. 4. 29. 20:58

 

 

* DMA

 DMA 할당/해제
 
 int request_dma( unsigned int dma, const char *device_id );
 void free_dma( unsigned int dma );


 DMA를 위한 메모리 할당/해제
 
 void *dma_alloc_coherent( struct device *dev, size_t size, dma_addr_t *dma_handle, int flags );
 void *dma_free_coherent( struct device *dev, size_t size, void *cpu_addr, dma_addr_t dma_handle );


 unsigned long clain_dma_lock( void );
 void disable_dma( unsigned int dma );
 void clear_dma_ff( unsigned int dma );
 void set_dma_mode( unsigned int dma, char mode );
 void set_dma_addr( unsigned int dma, unsigned int a );
 void set_dma_count( unsigned int dma, unsigned int count );
 void enable_dma( unsigned int dma );
 void release_dma_lock( unsigned long flags );
 int get_dma_residue( unsigned int dma );


- DMA 전송 준비 함수 / DMA 완료 점검 함수 필요

 unsigned template_dma_prepare( int channel, int mode, unsigned int buf, unsigned int count )
 {
  unsigned long flags = claim_dma_lock();
 
  disable_dma( channel );
  clear_dma_ff( channel );
  set_dma_mode( channel, mode );
  set_dma_addr( channel, virt_to_bus( buf ) );
  set_dma_count( channel, count );
  enable_dma( channel );
  release_dma_lock( flags );
 
  return 0;
 }
 
 int template_dma_isdone( int channel )
 {
  int residue;
  unsigned long flags = claim_dma_lock( );
 
  residue = get_dma_residue( channel );
  release_dma_lock( flags );
 
  return ( residue == 0 );
 }
 
 SetPageReserved( ) 할당된 페이지를 예약
 ClearPageReserved( ) 예약된 페이지의 해제
 

 file_operations 구조체의 mmap 필드
 
 int dma_mmap_mmap( struct file *filp, struct vm_area_struct *vma )
 {
  unsigned long phys_addr;
 
  phys_addr = virt_to_phys( dmabuff )
 
  if ( remap_page_range( vma, vma->vm_start, phys_addr, DMA_BUFF_SIZE, vma->vm_page_prot ) )
   return -EAGAIN;
 
  return 0;
 }

'실습 > 리눅스 커널' 카테고리의 다른 글

디바이스 드라이버의 동작  (0) 2021.02.08
Major, Minor #  (0) 2021.02.08
Memory Mapping  (0) 2021.02.08
인터럽트 (Interrupt) 처리  (0) 2021.02.08
커널 타이머, 태스크릿, 작업큐  (0) 2021.02.08

[블로그 통합으로 이전해 온 자료] - 2008. 4. 29. 20:57

 

* mmap

* I/O 물리 주소의 커널 가상 주소로 맵팽

 <asm/io.h>
 
 void *ioremap( unsigned long offset, unsigned long size );
 void *ioremap_nocache( unsigned long offset, unsigned long size );
 void *iounmap( void *data );


 *_nocache() 버전은 pci 디바이스의 non-prefetchable 영역에 사용

* I/O 물리 주소와 커널 가상 주소간의 변환

 <asm/page.h>
 
 unsigned long virt_to_phys( volatile void *address );
 void *phys_to_virt( unsigned long address );
 unsigned long virt_to_bus( volatile void *address );
 void *phys_to_virt( unsigned long address );
 
 - 맵핑은 하지 않고 주소 변환 계산만 한다.
 - DMA 관련 루틴에서는 _bus_ 함수만 사용.

* 프로세스를 위한 메모리 맵핑
 
 app. 영역에서 사용하는 mmap() 시스템 콜에 대하여 처리하는 드라이버 메소드

 file_operations 구조체의 mmap 필드 에서
  remap_page_range() 함수나 xxx_nopage() 함수를 호출한다.

 <linux/mmh.>
 
 int remap_page_range( struct vm_area_struct *vma,
   unsigned long from, unsigned long to, unsigned long size, pgprot_t prot );
 
 struct page *xxx_nopage( struct vm_area_struct *vma, unsigned long addr, int *type );


 remap_page_range() 함수를 호출하는 경우는 '한방'에 맵핑하는 방식
 xxx_nopage() 함수를 사용하는 경우는 page 단위로 맵핑하는 방식으로 사용자가 직접 작성해야함.
  주로 드라이버에 의해 할당된 메모리를 공유하기 위해 사용된다. ex) DMA

'실습 > 리눅스 커널' 카테고리의 다른 글

Major, Minor #  (0) 2021.02.08
DMA 처리  (0) 2021.02.08
인터럽트 (Interrupt) 처리  (0) 2021.02.08
커널 타이머, 태스크릿, 작업큐  (0) 2021.02.08
드라이버 코드의 실행 지연  (0) 2021.02.08

+ Recent posts