base.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
  3. * Bjorn Helgaas <bjorn.helgaas@hp.com>
  4. */
  5. extern spinlock_t pnp_lock;
  6. extern struct device_attribute pnp_interface_attrs[];
  7. void *pnp_alloc(long size);
  8. int pnp_register_protocol(struct pnp_protocol *protocol);
  9. void pnp_unregister_protocol(struct pnp_protocol *protocol);
  10. #define PNP_EISA_ID_MASK 0x7fffffff
  11. void pnp_eisa_id_to_string(u32 id, char *str);
  12. struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id,
  13. const char *pnpid);
  14. struct pnp_card *pnp_alloc_card(struct pnp_protocol *, int id, char *pnpid);
  15. int pnp_add_device(struct pnp_dev *dev);
  16. struct pnp_id *pnp_add_id(struct pnp_dev *dev, const char *id);
  17. int pnp_add_card(struct pnp_card *card);
  18. void pnp_remove_card(struct pnp_card *card);
  19. int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
  20. void pnp_remove_card_device(struct pnp_dev *dev);
  21. struct pnp_port {
  22. resource_size_t min; /* min base number */
  23. resource_size_t max; /* max base number */
  24. resource_size_t align; /* align boundary */
  25. resource_size_t size; /* size of range */
  26. unsigned char flags; /* port flags */
  27. };
  28. #define PNP_IRQ_NR 256
  29. typedef struct { DECLARE_BITMAP(bits, PNP_IRQ_NR); } pnp_irq_mask_t;
  30. struct pnp_irq {
  31. pnp_irq_mask_t map; /* bitmap for IRQ lines */
  32. unsigned char flags; /* IRQ flags */
  33. };
  34. struct pnp_dma {
  35. unsigned char map; /* bitmask for DMA channels */
  36. unsigned char flags; /* DMA flags */
  37. };
  38. struct pnp_mem {
  39. resource_size_t min; /* min base number */
  40. resource_size_t max; /* max base number */
  41. resource_size_t align; /* align boundary */
  42. resource_size_t size; /* size of range */
  43. unsigned char flags; /* memory flags */
  44. };
  45. #define PNP_OPTION_DEPENDENT 0x80000000
  46. #define PNP_OPTION_SET_MASK 0xffff
  47. #define PNP_OPTION_SET_SHIFT 12
  48. #define PNP_OPTION_PRIORITY_MASK 0xfff
  49. #define PNP_OPTION_PRIORITY_SHIFT 0
  50. #define PNP_RES_PRIORITY_PREFERRED 0
  51. #define PNP_RES_PRIORITY_ACCEPTABLE 1
  52. #define PNP_RES_PRIORITY_FUNCTIONAL 2
  53. #define PNP_RES_PRIORITY_INVALID PNP_OPTION_PRIORITY_MASK
  54. struct pnp_option {
  55. struct list_head list;
  56. unsigned int flags; /* independent/dependent, set, priority */
  57. unsigned long type; /* IORESOURCE_{IO,MEM,IRQ,DMA} */
  58. union {
  59. struct pnp_port port;
  60. struct pnp_irq irq;
  61. struct pnp_dma dma;
  62. struct pnp_mem mem;
  63. } u;
  64. };
  65. int pnp_register_irq_resource(struct pnp_dev *dev, unsigned int option_flags,
  66. pnp_irq_mask_t *map, unsigned char flags);
  67. int pnp_register_dma_resource(struct pnp_dev *dev, unsigned int option_flags,
  68. unsigned char map, unsigned char flags);
  69. int pnp_register_port_resource(struct pnp_dev *dev, unsigned int option_flags,
  70. resource_size_t min, resource_size_t max,
  71. resource_size_t align, resource_size_t size,
  72. unsigned char flags);
  73. int pnp_register_mem_resource(struct pnp_dev *dev, unsigned int option_flags,
  74. resource_size_t min, resource_size_t max,
  75. resource_size_t align, resource_size_t size,
  76. unsigned char flags);
  77. static inline int pnp_option_is_dependent(struct pnp_option *option)
  78. {
  79. return option->flags & PNP_OPTION_DEPENDENT ? 1 : 0;
  80. }
  81. static inline unsigned int pnp_option_set(struct pnp_option *option)
  82. {
  83. return (option->flags >> PNP_OPTION_SET_SHIFT) & PNP_OPTION_SET_MASK;
  84. }
  85. static inline unsigned int pnp_option_priority(struct pnp_option *option)
  86. {
  87. return (option->flags >> PNP_OPTION_PRIORITY_SHIFT) &
  88. PNP_OPTION_PRIORITY_MASK;
  89. }
  90. static inline unsigned int pnp_new_dependent_set(struct pnp_dev *dev,
  91. int priority)
  92. {
  93. unsigned int flags;
  94. if (priority > PNP_RES_PRIORITY_FUNCTIONAL) {
  95. dev_warn(&dev->dev, "invalid dependent option priority %d "
  96. "clipped to %d", priority,
  97. PNP_RES_PRIORITY_INVALID);
  98. priority = PNP_RES_PRIORITY_INVALID;
  99. }
  100. flags = PNP_OPTION_DEPENDENT |
  101. ((dev->num_dependent_sets & PNP_OPTION_SET_MASK) <<
  102. PNP_OPTION_SET_SHIFT) |
  103. ((priority & PNP_OPTION_PRIORITY_MASK) <<
  104. PNP_OPTION_PRIORITY_SHIFT);
  105. dev->num_dependent_sets++;
  106. return flags;
  107. }
  108. char *pnp_option_priority_name(struct pnp_option *option);
  109. void dbg_pnp_show_option(struct pnp_dev *dev, struct pnp_option *option);
  110. void pnp_init_resources(struct pnp_dev *dev);
  111. void pnp_fixup_device(struct pnp_dev *dev);
  112. void pnp_free_options(struct pnp_dev *dev);
  113. int __pnp_add_device(struct pnp_dev *dev);
  114. void __pnp_remove_device(struct pnp_dev *dev);
  115. int pnp_check_port(struct pnp_dev *dev, struct resource *res);
  116. int pnp_check_mem(struct pnp_dev *dev, struct resource *res);
  117. int pnp_check_irq(struct pnp_dev *dev, struct resource *res);
  118. #ifdef CONFIG_ISA_DMA_API
  119. int pnp_check_dma(struct pnp_dev *dev, struct resource *res);
  120. #endif
  121. char *pnp_resource_type_name(struct resource *res);
  122. void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc);
  123. void pnp_free_resources(struct pnp_dev *dev);
  124. unsigned long pnp_resource_type(struct resource *res);
  125. struct pnp_resource {
  126. struct list_head list;
  127. struct resource res;
  128. };
  129. void pnp_free_resource(struct pnp_resource *pnp_res);
  130. struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
  131. int flags);
  132. struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
  133. int flags);
  134. struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
  135. resource_size_t start,
  136. resource_size_t end, int flags);
  137. struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
  138. resource_size_t start,
  139. resource_size_t end, int flags);
  140. struct pnp_resource *pnp_add_bus_resource(struct pnp_dev *dev,
  141. resource_size_t start,
  142. resource_size_t end);
  143. extern int pnp_debug;
  144. #if defined(CONFIG_PNP_DEBUG_MESSAGES)
  145. #define pnp_dbg(dev, format, arg...) \
  146. ({ if (pnp_debug) dev_printk(KERN_DEBUG, dev, format, ## arg); 0; })
  147. #else
  148. #define pnp_dbg(dev, format, arg...) \
  149. ({ if (0) dev_printk(KERN_DEBUG, dev, format, ## arg); 0; })
  150. #endif