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