blob: cdcfa39cf1673152d305f897041d9280cff988b1 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -06002/*
3 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
4 * Bjorn Helgaas <bjorn.helgaas@hp.com>
5 */
6
Rafael J. Wysocki38f6b382015-03-18 22:39:55 +01007extern struct mutex pnp_lock;
Greg Kroah-Hartman2df43902013-10-06 23:55:42 -07008extern const struct attribute_group *pnp_dev_groups[];
Linus Torvalds1da177e2005-04-16 15:20:36 -07009void *pnp_alloc(long size);
Bjorn Helgaas62cfb292008-04-28 16:34:40 -060010
11int pnp_register_protocol(struct pnp_protocol *protocol);
12void pnp_unregister_protocol(struct pnp_protocol *protocol);
13
Bjorn Helgaas25eb8462008-04-28 16:33:53 -060014#define PNP_EISA_ID_MASK 0x7fffffff
15void pnp_eisa_id_to_string(u32 id, char *str);
Thomas Renninger620e1122010-10-01 10:54:00 +020016struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id,
17 const char *pnpid);
Bjorn Helgaas6bf2aab2008-04-28 16:33:58 -060018struct pnp_card *pnp_alloc_card(struct pnp_protocol *, int id, char *pnpid);
Bjorn Helgaas62cfb292008-04-28 16:34:40 -060019
20int pnp_add_device(struct pnp_dev *dev);
Thomas Renninger620e1122010-10-01 10:54:00 +020021struct pnp_id *pnp_add_id(struct pnp_dev *dev, const char *id);
Bjorn Helgaas62cfb292008-04-28 16:34:40 -060022
23int pnp_add_card(struct pnp_card *card);
Bjorn Helgaas62cfb292008-04-28 16:34:40 -060024void pnp_remove_card(struct pnp_card *card);
25int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
26void pnp_remove_card_device(struct pnp_dev *dev);
27
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060028struct pnp_port {
Bjorn Helgaas169aaff2008-06-27 16:57:06 -060029 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 */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060033 unsigned char flags; /* port flags */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060034};
35
36#define PNP_IRQ_NR 256
Bjorn Helgaas7aefff52008-06-27 16:57:05 -060037typedef struct { DECLARE_BITMAP(bits, PNP_IRQ_NR); } pnp_irq_mask_t;
38
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060039struct pnp_irq {
Bjorn Helgaas7aefff52008-06-27 16:57:05 -060040 pnp_irq_mask_t map; /* bitmap for IRQ lines */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060041 unsigned char flags; /* IRQ flags */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060042};
43
44struct pnp_dma {
45 unsigned char map; /* bitmask for DMA channels */
46 unsigned char flags; /* DMA flags */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060047};
48
49struct pnp_mem {
Bjorn Helgaas169aaff2008-06-27 16:57:06 -060050 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 */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060054 unsigned char flags; /* memory flags */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060055};
56
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060057#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
62
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060063#define PNP_RES_PRIORITY_PREFERRED 0
64#define PNP_RES_PRIORITY_ACCEPTABLE 1
65#define PNP_RES_PRIORITY_FUNCTIONAL 2
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060066#define PNP_RES_PRIORITY_INVALID PNP_OPTION_PRIORITY_MASK
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060067
68struct pnp_option {
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060069 struct list_head list;
70 unsigned int flags; /* independent/dependent, set, priority */
71
72 unsigned long type; /* IORESOURCE_{IO,MEM,IRQ,DMA} */
73 union {
74 struct pnp_port port;
75 struct pnp_irq irq;
76 struct pnp_dma dma;
77 struct pnp_mem mem;
78 } u;
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060079};
80
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060081int pnp_register_irq_resource(struct pnp_dev *dev, unsigned int option_flags,
Bjorn Helgaasc2275362008-06-27 16:57:11 -060082 pnp_irq_mask_t *map, unsigned char flags);
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060083int pnp_register_dma_resource(struct pnp_dev *dev, unsigned int option_flags,
Bjorn Helgaasc2275362008-06-27 16:57:11 -060084 unsigned char map, unsigned char flags);
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060085int pnp_register_port_resource(struct pnp_dev *dev, unsigned int option_flags,
Bjorn Helgaasc2275362008-06-27 16:57:11 -060086 resource_size_t min, resource_size_t max,
87 resource_size_t align, resource_size_t size,
88 unsigned char flags);
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060089int pnp_register_mem_resource(struct pnp_dev *dev, unsigned int option_flags,
Bjorn Helgaasc2275362008-06-27 16:57:11 -060090 resource_size_t min, resource_size_t max,
91 resource_size_t align, resource_size_t size,
92 unsigned char flags);
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060093
94static inline int pnp_option_is_dependent(struct pnp_option *option)
95{
96 return option->flags & PNP_OPTION_DEPENDENT ? 1 : 0;
97}
98
99static inline unsigned int pnp_option_set(struct pnp_option *option)
100{
101 return (option->flags >> PNP_OPTION_SET_SHIFT) & PNP_OPTION_SET_MASK;
102}
103
104static inline unsigned int pnp_option_priority(struct pnp_option *option)
105{
106 return (option->flags >> PNP_OPTION_PRIORITY_SHIFT) &
107 PNP_OPTION_PRIORITY_MASK;
108}
109
110static inline unsigned int pnp_new_dependent_set(struct pnp_dev *dev,
111 int priority)
112{
113 unsigned int flags;
114
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;
120 }
121
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);
127
128 dev->num_dependent_sets++;
129
130 return flags;
131}
132
133char *pnp_option_priority_name(struct pnp_option *option);
134void dbg_pnp_show_option(struct pnp_dev *dev, struct pnp_option *option);
135
Bjorn Helgaas62cfb292008-04-28 16:34:40 -0600136void pnp_init_resources(struct pnp_dev *dev);
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138void pnp_fixup_device(struct pnp_dev *dev);
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600139void pnp_free_options(struct pnp_dev *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140int __pnp_add_device(struct pnp_dev *dev);
141void __pnp_remove_device(struct pnp_dev *dev);
142
Bjorn Helgaasf5d94ff2008-04-28 16:34:22 -0600143int pnp_check_port(struct pnp_dev *dev, struct resource *res);
144int pnp_check_mem(struct pnp_dev *dev, struct resource *res);
145int pnp_check_irq(struct pnp_dev *dev, struct resource *res);
David Rientjes586f83e2011-03-22 16:34:56 -0700146#ifdef CONFIG_ISA_DMA_API
Bjorn Helgaasf5d94ff2008-04-28 16:34:22 -0600147int pnp_check_dma(struct pnp_dev *dev, struct resource *res);
David Rientjes586f83e2011-03-22 16:34:56 -0700148#endif
Bjorn Helgaas81b5c752008-04-28 16:34:08 -0600149
Bjorn Helgaas9fdee4e2008-06-27 16:56:55 -0600150char *pnp_resource_type_name(struct resource *res);
Bjorn Helgaas81b5c752008-04-28 16:34:08 -0600151void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc);
Bjorn Helgaasd948a8d2008-04-28 16:34:13 -0600152
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600153void pnp_free_resources(struct pnp_dev *dev);
Rene Hermanb563cf52008-10-15 22:03:58 -0700154unsigned long pnp_resource_type(struct resource *res);
Bjorn Helgaas02d83b52008-04-28 16:34:28 -0600155
Bjorn Helgaas784f01d2008-04-28 16:34:30 -0600156struct pnp_resource {
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600157 struct list_head list;
Bjorn Helgaas784f01d2008-04-28 16:34:30 -0600158 struct resource res;
159};
160
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600161void pnp_free_resource(struct pnp_resource *pnp_res);
Bjorn Helgaasdbddd032008-04-28 16:34:34 -0600162
Rafael J. Wysocki046d9ce2012-11-15 00:30:01 +0100163struct pnp_resource *pnp_add_resource(struct pnp_dev *dev,
164 struct resource *res);
Bjorn Helgaasdbddd032008-04-28 16:34:34 -0600165struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
166 int flags);
Bjorn Helgaasdc16f5f2008-04-28 16:34:35 -0600167struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
168 int flags);
Bjorn Helgaascc8c2e32008-04-28 16:34:36 -0600169struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
170 resource_size_t start,
171 resource_size_t end, int flags);
Bjorn Helgaasd6180f32008-04-28 16:34:37 -0600172struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
173 resource_size_t start,
174 resource_size_t end, int flags);
Bjorn Helgaas7e0e9c02010-03-05 10:47:57 -0700175struct pnp_resource *pnp_add_bus_resource(struct pnp_dev *dev,
176 resource_size_t start,
177 resource_size_t end);
Bjorn Helgaas97ef0622008-08-19 16:53:41 -0600178
179extern int pnp_debug;
180
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; })
184#else
185#define pnp_dbg(dev, format, arg...) \
186 ({ if (0) dev_printk(KERN_DEBUG, dev, format, ## arg); 0; })
187#endif