base.h 5.9 KB

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