Your SlideShare is downloading. ×
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
td
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

td

547

Published on

Apresentação do meu trabalho de diploma. UNIFEI 2010

Apresentação do meu trabalho de diploma. UNIFEI 2010

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
547
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Um estudo nos drivers de dispositivo do Linux Tiago Maluta maluta@unifei.edu.br Monday, June 28, 2010
  • 2. Evolução 1991 i386 avr32, frv, m32r, microblaze, parisc, score, um, alpha, blackfin, h8300, m68k, mips, powerpcsh, x86, 2010 arm, cris, ia64, m68knommu, mn10300, s390, sparc, xtensa Fonte: www.kernel.org Monday, June 28, 2010
  • 3. Como gerenciar este crescimento? Monday, June 28, 2010
  • 4. Monday, June 28, 2010
  • 5. Controle de versão descentralizado • Linus tem seu repositório: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git Linus • Recebe um e-mail do mantenedor do um subsistema “Linus, please pull from: ssh://master.kernel.org/pub/scm/linux/ A B C kernel/git/mchehab/linux-2.6.git v4l_for_2.6.35” • Ele [Linus] faz o merge no seu repositório no momento que achar adequado. Monday, June 28, 2010
  • 6. Módulos no kernel Módulos de sistemas vfat - suporte ao filesystem FAT32 usbnet - subsistema de rede com USB Módulos de dispositivo asix - controlador do conversor USB/Ethernet nvidia - placa de vídeo Podem existir módulos proprietários, mas algumas interfaces são exclusivas para licenças livres Monday, June 28, 2010
  • 7. #include <stdio.h> static int start(void) { printf(“Hello from userspace!”); return 0; } int main(void) { return start(); } Monday, June 28, 2010
  • 8. #include <stdio.h> static int start(void) { printf(“Hello from userspace!”); return 0; } int main(void) { return start(); } Monday, June 28, 2010
  • 9. #include <stdio.h> static int start(void) { printf(“Hello from userspace!”); return 0; } gcc -Wall main.c -o main int main(void) { return start(); } Monday, June 28, 2010
  • 10. #include <linux/kernel .h> #include <linux/init .h> #include <linux/module.h> static int __init start(void) { printk(“Hello from kernelspace!”); return 0; } static void __exit stop(void) { } module_init(start); module_exit(stop); MODULE_AUTHOR(“”); MODULE_DESCRIPTION(“”); MODULE_LICENSE(“GPL”) ; Monday, June 28, 2010
  • 11. #include <linux/kernel .h> #include <linux/init .h> #include <linux/module.h> static int __init start(void) { printk(“Hello from kernelspace!”); return 0; } static void __exit stop(void) { } module_init(start); module_exit(stop); MODULE_AUTHOR(“”); MODULE_DESCRIPTION(“”); MODULE_LICENSE(“GPL”) ; Monday, June 28, 2010
  • 12. #include <linux/kernel .h> #include <linux/init .h> #include <linux/module.h> static int __init start(void) { printk(“Hello from kernelspace!”); return 0; } static void __exit stop(void) { } module_init(start); module_exit(stop); MODULE_AUTHOR(“”); MODULE_DESCRIPTION(“”); MODULE_LICENSE(“GPL”) ; Monday, June 28, 2010
  • 13. #include <linux/kernel .h> #include <linux/init .h> #include <linux/module.h> static int __init start(void) { printk(“Hello from kernelspace!”); return 0; } static void __exit stop(void) { } module_init(start); module_exit(stop); MODULE_AUTHOR(“”); MODULE_DESCRIPTION(“”); MODULE_LICENSE(“GPL”) ; Monday, June 28, 2010
  • 14. #include <linux/kernel .h> #include <linux/init .h> #include <linux/module.h> static int __init start(void) { printk(“Hello from kernelspace!”); return 0; } static void __exit stop(void) { } module_init(start); module_exit(stop); MODULE_AUTHOR(“”); MODULE_DESCRIPTION(“”); MODULE_LICENSE(“GPL”) ; Monday, June 28, 2010
  • 15. #include <linux/kernel .h> #include <linux/init .h> #include <linux/module.h> static int __init start(void) { printk(“Hello from kernelspace!”); obj−m:= hello.o KDIR := /lib/modules/$(shell uname −r)/build return 0; PWD }:= $(shell pwd) default : $(MAKE) −C __exit stop(void) { } static void $(KDIR) M=$(PWD) modules clean : module_init(start); $(MAKE) −C $(KDIR) M=$(PWD) clean module_exit(stop); MODULE_AUTHOR(“”); MODULE_DESCRIPTION(“”); MODULE_LICENSE(“GPL”) ; Monday, June 28, 2010
  • 16. Liga BIOS/EFI Bootloader (GRUB/Lilo/U-boot) Kernel (modo real) Kernel (modo protegido) Processo init Processos dos usuários Monday, June 28, 2010
  • 17. Liga BIOS/EFI Bootloader (GRUB/Lilo/U-boot) Kernel (modo real) Kernel (modo protegido) Processo init Processos dos usuários Monday, June 28, 2010
  • 18. Liga BIOS/EFI Bootloader (GRUB/Lilo/U-boot) Kernel (modo real) Kernel (modo protegido) Processo init Processos dos usuários Monday, June 28, 2010
  • 19. Sincronismo • Spinlocks • Mutexes • Operações atômicas Monday, June 28, 2010
  • 20. Sincronismo • Spinlocks • Mutexes • Operações atômicas Monday, June 28, 2010
  • 21. Sincronismo #include <linux/spinlock .h> spinlock t mylock = SPIN_LOCK_ULOCKED; spin_lock(&mylock ); • Spinlocks /∗ região crítica ∗/ spin_unlock(&mylock ); • Mutexes • Operações atômicas Monday, June 28, 2010
  • 22. Sincronismo #include <linux/spinlock .h> spinlock t mylock = SPIN_LOCK_ULOCKED; spin_lock(&mylock ); • Spinlocks /∗ região crítica ∗/ spin_unlock(&mylock ); • Mutexes • Operações atômicas Monday, June 28, 2010
  • 23. Sincronismo #include <linux/spinlock .h> spinlock t mylock = SPIN_LOCK_ULOCKED; spin_lock(&mylock ); • Spinlocks /∗ região crítica ∗/ spin_unlock(&mylock ); • Mutexes • Operações atômicas #include <linux/mutex .h> static DEFINE_MUTEX(mymutex); mutex_lock(&mymutex); /∗ região crítica ∗/ mutex_unlock(&mymutex); Monday, June 28, 2010
  • 24. Facilitadores • Udev - para gerenciamento de nós /dev • Sysfs - exportar informações para os processos do usuário. • Kobjects e Krefs - contador de referências Monday, June 28, 2010
  • 25. Udev /etc/udev/rules.d/70-persistent-cd.rules ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="cdrom", ENV{GENERATED}="1" ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="cdrw", ENV{GENERATED}="1" ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="dvd", ENV{GENERATED}="1" ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="dvdrw", ENV{GENERATED}="1" Monday, June 28, 2010
  • 26. Udev /etc/udev/rules.d/70-persistent-cd.rules ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="cdrom", ENV{GENERATED}="1" ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="cdrw", ENV{GENERATED}="1" ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="dvd", ENV{GENERATED}="1" ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="dvdrw", ENV{GENERATED}="1" Monday, June 28, 2010
  • 27. sysfs kernel-space user-space Objetos Diretórios Atributos Arquivos Relações Links simbólicos /sys/class/mmc_host/mmc0/device/leds/mmc0:: $ echo “1” > brightness $ cat brightness Monday, June 28, 2010
  • 28. kobject krefs Contador de referências, para o kernel gerenciar o número de objetos associados em uma mesma estrutura. struct kobject { struct kref { const char *name; atomic_t refcount; struct list_head entry; } struct kobject *parent; struct kset *kset; struct kobj_type *ktype; struct sysfs_dirent *sd; struct kref kref; } Monday, June 28, 2010
  • 29. Modelo de Driver do Linux O modelo propôs uma representação genérica de objetos: • Devices • Devices drivers • Bus drivers • Devices Classes • Devices Interfaces Monday, June 28, 2010
  • 30. Modelo de Driver do Linux O modelo propôs uma representação genérica de objetos: • Devices • Devices drivers • Bus drivers • Devices Classes • Devices Interfaces Funções para operar e controlar cada tipo de objeto. Monday, June 28, 2010
  • 31. Modelo de Driver do Linux O modelo propôs uma representação genérica de objetos: • Devices • Devices drivers • Bus drivers • Devices Classes • Devices Interfaces Funções para operar e controlar cada tipo de objeto. Monday, June 28, 2010
  • 32. Modelo de Driver do Linux O modelo propôs uma representação genérica de objetos: • Devices Um device driver implementa uma ou mais interfaces (devices interfaces) de • Devices drivers uma classe de dispositivos (devices • Bus drivers classes) para um grupo de dipositivos • Devices Classes (devices) em um barramento (bus driver) específico. • Devices Interfaces Funções para operar e controlar cada tipo de objeto. Monday, June 28, 2010
  • 33. USB/Ethernet Ethernet USB Controlador asix.ko Monday, June 28, 2010
  • 34. USB/Ethernet Preenchimento de estruturas: Monday, June 28, 2010
  • 35. USB/Ethernet Preenchimento de estruturas: Monday, June 28, 2010
  • 36. USB/Ethernet static struct usb_driver asix_driver = { .name = "asix", .id_table = products, .probe = usbnet_probe, Preenchimento de estruturas: .suspend = usbnet_suspend, .resume = usbnet_resume, .disconnect = usbnet_disconnect, .supports_autosuspend = 1, }; Monday, June 28, 2010
  • 37. USB/Ethernet static struct usb_driver asix_driver = { .name = "asix", .id_table = products, .probe = usbnet_probe, Preenchimento de estruturas: .suspend = usbnet_suspend, .resume = usbnet_resume, .disconnect = usbnet_disconnect, .supports_autosuspend = 1, }; Monday, June 28, 2010
  • 38. USB/Ethernet static struct usb_driver asix_driver = { .name = "asix", .id_table = products, .probe = usbnet_probe, Preenchimento de estruturas: .suspend = usbnet_suspend, .resume = usbnet_resume, .disconnect = usbnet_disconnect, .supports_autosuspend = 1, }; static const struct net_device_ops ax88172_netdev_ops = { .ndo_open = usbnet_open, .ndo_stop = usbnet_stop, .ndo_start_xmit = usbnet_start_xmit, .ndo_tx_timeout = usbnet_tx_timeout, .ndo_change_mtu = usbnet_change_mtu, .ndo_set_mac_address = eth_mac_addr, .ndo_validate_addr = eth_validate_addr, .ndo_do_ioctl = asix_ioctl, .ndo_set_multicast_list = ax88172_set_multicast, }; Monday, June 28, 2010
  • 39. USB/Ethernet Operações: Monday, June 28, 2010
  • 40. USB/Ethernet Operações: Monday, June 28, 2010
  • 41. USB/Ethernet asix_read_cmd asix_read_medium_status asix_ioctl asix_write_cmd asix_write_medium_mode asix_set_mac_address Operações: asix_async_cmd_callback asix_write_gpio ax88172_set_multicast asix_write_cmd_async asix_set_multicast ax88172_link_reset asix_rx_fixup asix_mdio_read ax88172_bind asix_tx_fixup asix_mdio_write ax88772_link_reset asix_status asix_get_phyid ax88772_bind asix_set_sw_mii asix_get_wol marvell_phy_init asix_set_hw_mii asix_set_wol marvell_led_status asix_get_phy_addr asix_get_eeprom_len ax88178_link_reset asix_sw_reset asix_get_eeprom ax88178_set_mfb asix_read_rx_ctl asix_get_drvinfo ax88178_change_mtu asix_write_rx_ctl asix_get_link ax88178_bind Monday, June 28, 2010
  • 42. Conclusão Monday, June 28, 2010
  • 43. Crescimento com pouca manutenção do código. Monday, June 28, 2010
  • 44. Padronização das estruturas básicas. Monday, June 28, 2010
  • 45. Sistemas Embarcados Monday, June 28, 2010
  • 46. LKML et all; Linux Kernel Mail List Monday, June 28, 2010
  • 47. --tm Monday, June 28, 2010

×