1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
4 * Bjorn Helgaas <bjorn.helgaas@hp.com>
7 extern struct mutex pnp_lock
;
8 extern const struct attribute_group
*pnp_dev_groups
[];
9 void *pnp_alloc(long size
);
11 int pnp_register_protocol(struct pnp_protocol
*protocol
);
12 void pnp_unregister_protocol(struct pnp_protocol
*protocol
);
14 #define PNP_EISA_ID_MASK 0x7fffffff
15 void pnp_eisa_id_to_string(u32 id
, char *str
);
16 struct pnp_dev
*pnp_alloc_dev(struct pnp_protocol
*, int id
,
18 struct pnp_card
*pnp_alloc_card(struct pnp_protocol
*, int id
, char *pnpid
);
20 int pnp_add_device(struct pnp_dev
*dev
);
21 struct pnp_id
*pnp_add_id(struct pnp_dev
*dev
, const char *id
);
23 int pnp_add_card(struct pnp_card
*card
);
24 void pnp_remove_card(struct pnp_card
*card
);
25 int pnp_add_card_device(struct pnp_card
*card
, struct pnp_dev
*dev
);
26 void pnp_remove_card_device(struct pnp_dev
*dev
);
29 resource_size_t min
; /* min base number */
30 resource_size_t max
; /* max base number */
31 resource_size_t align
; /* align boundary */
32 resource_size_t size
; /* size of range */
33 unsigned char flags
; /* port flags */
36 #define PNP_IRQ_NR 256
37 typedef struct { DECLARE_BITMAP(bits
, PNP_IRQ_NR
); } pnp_irq_mask_t
;
40 pnp_irq_mask_t map
; /* bitmap for IRQ lines */
41 unsigned char flags
; /* IRQ flags */
45 unsigned char map
; /* bitmask for DMA channels */
46 unsigned char flags
; /* DMA flags */
50 resource_size_t min
; /* min base number */
51 resource_size_t max
; /* max base number */
52 resource_size_t align
; /* align boundary */
53 resource_size_t size
; /* size of range */
54 unsigned char flags
; /* memory flags */
57 #define PNP_OPTION_DEPENDENT 0x80000000
58 #define PNP_OPTION_SET_MASK 0xffff
59 #define PNP_OPTION_SET_SHIFT 12
60 #define PNP_OPTION_PRIORITY_MASK 0xfff
61 #define PNP_OPTION_PRIORITY_SHIFT 0
63 #define PNP_RES_PRIORITY_PREFERRED 0
64 #define PNP_RES_PRIORITY_ACCEPTABLE 1
65 #define PNP_RES_PRIORITY_FUNCTIONAL 2
66 #define PNP_RES_PRIORITY_INVALID PNP_OPTION_PRIORITY_MASK
69 struct list_head list
;
70 unsigned int flags
; /* independent/dependent, set, priority */
72 unsigned long type
; /* IORESOURCE_{IO,MEM,IRQ,DMA} */
81 int pnp_register_irq_resource(struct pnp_dev
*dev
, unsigned int option_flags
,
82 pnp_irq_mask_t
*map
, unsigned char flags
);
83 int pnp_register_dma_resource(struct pnp_dev
*dev
, unsigned int option_flags
,
84 unsigned char map
, unsigned char flags
);
85 int pnp_register_port_resource(struct pnp_dev
*dev
, unsigned int option_flags
,
86 resource_size_t min
, resource_size_t max
,
87 resource_size_t align
, resource_size_t size
,
89 int pnp_register_mem_resource(struct pnp_dev
*dev
, unsigned int option_flags
,
90 resource_size_t min
, resource_size_t max
,
91 resource_size_t align
, resource_size_t size
,
94 static inline int pnp_option_is_dependent(struct pnp_option
*option
)
96 return option
->flags
& PNP_OPTION_DEPENDENT
? 1 : 0;
99 static inline unsigned int pnp_option_set(struct pnp_option
*option
)
101 return (option
->flags
>> PNP_OPTION_SET_SHIFT
) & PNP_OPTION_SET_MASK
;
104 static inline unsigned int pnp_option_priority(struct pnp_option
*option
)
106 return (option
->flags
>> PNP_OPTION_PRIORITY_SHIFT
) &
107 PNP_OPTION_PRIORITY_MASK
;
110 static inline unsigned int pnp_new_dependent_set(struct pnp_dev
*dev
,
115 if (priority
> PNP_RES_PRIORITY_FUNCTIONAL
) {
116 dev_warn(&dev
->dev
, "invalid dependent option priority %d "
117 "clipped to %d", priority
,
118 PNP_RES_PRIORITY_INVALID
);
119 priority
= PNP_RES_PRIORITY_INVALID
;
122 flags
= PNP_OPTION_DEPENDENT
|
123 ((dev
->num_dependent_sets
& PNP_OPTION_SET_MASK
) <<
124 PNP_OPTION_SET_SHIFT
) |
125 ((priority
& PNP_OPTION_PRIORITY_MASK
) <<
126 PNP_OPTION_PRIORITY_SHIFT
);
128 dev
->num_dependent_sets
++;
133 char *pnp_option_priority_name(struct pnp_option
*option
);
134 void dbg_pnp_show_option(struct pnp_dev
*dev
, struct pnp_option
*option
);
136 void pnp_init_resources(struct pnp_dev
*dev
);
138 void pnp_fixup_device(struct pnp_dev
*dev
);
139 void pnp_free_options(struct pnp_dev
*dev
);
140 int __pnp_add_device(struct pnp_dev
*dev
);
141 void __pnp_remove_device(struct pnp_dev
*dev
);
143 int pnp_check_port(struct pnp_dev
*dev
, struct resource
*res
);
144 int pnp_check_mem(struct pnp_dev
*dev
, struct resource
*res
);
145 int pnp_check_irq(struct pnp_dev
*dev
, struct resource
*res
);
146 #ifdef CONFIG_ISA_DMA_API
147 int pnp_check_dma(struct pnp_dev
*dev
, struct resource
*res
);
150 char *pnp_resource_type_name(struct resource
*res
);
151 void dbg_pnp_show_resources(struct pnp_dev
*dev
, char *desc
);
153 void pnp_free_resources(struct pnp_dev
*dev
);
154 unsigned long pnp_resource_type(struct resource
*res
);
156 struct pnp_resource
{
157 struct list_head list
;
161 void pnp_free_resource(struct pnp_resource
*pnp_res
);
163 struct pnp_resource
*pnp_add_resource(struct pnp_dev
*dev
,
164 struct resource
*res
);
165 struct pnp_resource
*pnp_add_irq_resource(struct pnp_dev
*dev
, int irq
,
167 struct pnp_resource
*pnp_add_dma_resource(struct pnp_dev
*dev
, int dma
,
169 struct pnp_resource
*pnp_add_io_resource(struct pnp_dev
*dev
,
170 resource_size_t start
,
171 resource_size_t end
, int flags
);
172 struct pnp_resource
*pnp_add_mem_resource(struct pnp_dev
*dev
,
173 resource_size_t start
,
174 resource_size_t end
, int flags
);
175 struct pnp_resource
*pnp_add_bus_resource(struct pnp_dev
*dev
,
176 resource_size_t start
,
177 resource_size_t end
);
179 extern int pnp_debug
;
181 #if defined(CONFIG_PNP_DEBUG_MESSAGES)
182 #define pnp_dbg(dev, format, arg...) \
183 ({ if (pnp_debug) dev_printk(KERN_DEBUG, dev, format, ## arg); 0; })
185 #define pnp_dbg(dev, format, arg...) \
186 ({ if (0) dev_printk(KERN_DEBUG, dev, format, ## arg); 0; })