blob: 0bab84ebb15da8961e20be1ebfd120355ea3cdea [file] [log] [blame]
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -06001/*
2 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
3 * Bjorn Helgaas <bjorn.helgaas@hp.com>
4 */
5
Linus Torvalds1da177e2005-04-16 15:20:36 -07006extern spinlock_t pnp_lock;
Drew Moseley8a89efd2008-09-28 01:31:35 +02007extern struct device_attribute pnp_interface_attrs[];
Linus Torvalds1da177e2005-04-16 15:20:36 -07008void *pnp_alloc(long size);
Bjorn Helgaas62cfb292008-04-28 16:34:40 -06009
10int pnp_register_protocol(struct pnp_protocol *protocol);
11void pnp_unregister_protocol(struct pnp_protocol *protocol);
12
Bjorn Helgaas25eb8462008-04-28 16:33:53 -060013#define PNP_EISA_ID_MASK 0x7fffffff
14void pnp_eisa_id_to_string(u32 id, char *str);
Bjorn Helgaasbda1e4e2008-04-28 16:33:54 -060015struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid);
Bjorn Helgaas6bf2aab2008-04-28 16:33:58 -060016struct pnp_card *pnp_alloc_card(struct pnp_protocol *, int id, char *pnpid);
Bjorn Helgaas62cfb292008-04-28 16:34:40 -060017
18int pnp_add_device(struct pnp_dev *dev);
Bjorn Helgaas772defc2008-04-28 16:33:52 -060019struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
Bjorn Helgaas62cfb292008-04-28 16:34:40 -060020
21int pnp_add_card(struct pnp_card *card);
Bjorn Helgaas62cfb292008-04-28 16:34:40 -060022void pnp_remove_card(struct pnp_card *card);
23int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
24void pnp_remove_card_device(struct pnp_dev *dev);
25
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060026struct pnp_port {
Bjorn Helgaas169aaff2008-06-27 16:57:06 -060027 resource_size_t min; /* min base number */
28 resource_size_t max; /* max base number */
29 resource_size_t align; /* align boundary */
30 resource_size_t size; /* size of range */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060031 unsigned char flags; /* port flags */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060032};
33
34#define PNP_IRQ_NR 256
Bjorn Helgaas7aefff52008-06-27 16:57:05 -060035typedef struct { DECLARE_BITMAP(bits, PNP_IRQ_NR); } pnp_irq_mask_t;
36
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060037struct pnp_irq {
Bjorn Helgaas7aefff52008-06-27 16:57:05 -060038 pnp_irq_mask_t map; /* bitmap for IRQ lines */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060039 unsigned char flags; /* IRQ flags */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060040};
41
42struct pnp_dma {
43 unsigned char map; /* bitmask for DMA channels */
44 unsigned char flags; /* DMA flags */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060045};
46
47struct pnp_mem {
Bjorn Helgaas169aaff2008-06-27 16:57:06 -060048 resource_size_t min; /* min base number */
49 resource_size_t max; /* max base number */
50 resource_size_t align; /* align boundary */
51 resource_size_t size; /* size of range */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060052 unsigned char flags; /* memory flags */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060053};
54
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060055#define PNP_OPTION_DEPENDENT 0x80000000
56#define PNP_OPTION_SET_MASK 0xffff
57#define PNP_OPTION_SET_SHIFT 12
58#define PNP_OPTION_PRIORITY_MASK 0xfff
59#define PNP_OPTION_PRIORITY_SHIFT 0
60
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060061#define PNP_RES_PRIORITY_PREFERRED 0
62#define PNP_RES_PRIORITY_ACCEPTABLE 1
63#define PNP_RES_PRIORITY_FUNCTIONAL 2
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060064#define PNP_RES_PRIORITY_INVALID PNP_OPTION_PRIORITY_MASK
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060065
66struct pnp_option {
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060067 struct list_head list;
68 unsigned int flags; /* independent/dependent, set, priority */
69
70 unsigned long type; /* IORESOURCE_{IO,MEM,IRQ,DMA} */
71 union {
72 struct pnp_port port;
73 struct pnp_irq irq;
74 struct pnp_dma dma;
75 struct pnp_mem mem;
76 } u;
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060077};
78
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060079int pnp_register_irq_resource(struct pnp_dev *dev, unsigned int option_flags,
Bjorn Helgaasc2275362008-06-27 16:57:11 -060080 pnp_irq_mask_t *map, unsigned char flags);
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060081int pnp_register_dma_resource(struct pnp_dev *dev, unsigned int option_flags,
Bjorn Helgaasc2275362008-06-27 16:57:11 -060082 unsigned char map, unsigned char flags);
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060083int pnp_register_port_resource(struct pnp_dev *dev, unsigned int option_flags,
Bjorn Helgaasc2275362008-06-27 16:57:11 -060084 resource_size_t min, resource_size_t max,
85 resource_size_t align, resource_size_t size,
86 unsigned char flags);
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060087int pnp_register_mem_resource(struct pnp_dev *dev, unsigned int option_flags,
Bjorn Helgaasc2275362008-06-27 16:57:11 -060088 resource_size_t min, resource_size_t max,
89 resource_size_t align, resource_size_t size,
90 unsigned char flags);
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060091
92static inline int pnp_option_is_dependent(struct pnp_option *option)
93{
94 return option->flags & PNP_OPTION_DEPENDENT ? 1 : 0;
95}
96
97static inline unsigned int pnp_option_set(struct pnp_option *option)
98{
99 return (option->flags >> PNP_OPTION_SET_SHIFT) & PNP_OPTION_SET_MASK;
100}
101
102static inline unsigned int pnp_option_priority(struct pnp_option *option)
103{
104 return (option->flags >> PNP_OPTION_PRIORITY_SHIFT) &
105 PNP_OPTION_PRIORITY_MASK;
106}
107
108static inline unsigned int pnp_new_dependent_set(struct pnp_dev *dev,
109 int priority)
110{
111 unsigned int flags;
112
113 if (priority > PNP_RES_PRIORITY_FUNCTIONAL) {
114 dev_warn(&dev->dev, "invalid dependent option priority %d "
115 "clipped to %d", priority,
116 PNP_RES_PRIORITY_INVALID);
117 priority = PNP_RES_PRIORITY_INVALID;
118 }
119
120 flags = PNP_OPTION_DEPENDENT |
121 ((dev->num_dependent_sets & PNP_OPTION_SET_MASK) <<
122 PNP_OPTION_SET_SHIFT) |
123 ((priority & PNP_OPTION_PRIORITY_MASK) <<
124 PNP_OPTION_PRIORITY_SHIFT);
125
126 dev->num_dependent_sets++;
127
128 return flags;
129}
130
131char *pnp_option_priority_name(struct pnp_option *option);
132void dbg_pnp_show_option(struct pnp_dev *dev, struct pnp_option *option);
133
Bjorn Helgaas62cfb292008-04-28 16:34:40 -0600134void pnp_init_resources(struct pnp_dev *dev);
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136void pnp_fixup_device(struct pnp_dev *dev);
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600137void pnp_free_options(struct pnp_dev *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138int __pnp_add_device(struct pnp_dev *dev);
139void __pnp_remove_device(struct pnp_dev *dev);
140
Bjorn Helgaasf5d94ff2008-04-28 16:34:22 -0600141int pnp_check_port(struct pnp_dev *dev, struct resource *res);
142int pnp_check_mem(struct pnp_dev *dev, struct resource *res);
143int pnp_check_irq(struct pnp_dev *dev, struct resource *res);
144int pnp_check_dma(struct pnp_dev *dev, struct resource *res);
Bjorn Helgaas81b5c752008-04-28 16:34:08 -0600145
Bjorn Helgaas9fdee4e2008-06-27 16:56:55 -0600146char *pnp_resource_type_name(struct resource *res);
Bjorn Helgaas81b5c752008-04-28 16:34:08 -0600147void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc);
Bjorn Helgaasd948a8d2008-04-28 16:34:13 -0600148
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600149void pnp_free_resources(struct pnp_dev *dev);
Rene Hermanb563cf52008-10-15 22:03:58 -0700150unsigned long pnp_resource_type(struct resource *res);
Bjorn Helgaas02d83b52008-04-28 16:34:28 -0600151
Bjorn Helgaas784f01d2008-04-28 16:34:30 -0600152struct pnp_resource {
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600153 struct list_head list;
Bjorn Helgaas784f01d2008-04-28 16:34:30 -0600154 struct resource res;
155};
156
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600157void pnp_free_resource(struct pnp_resource *pnp_res);
Bjorn Helgaasdbddd032008-04-28 16:34:34 -0600158
159struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
160 int flags);
Bjorn Helgaasdc16f5f2008-04-28 16:34:35 -0600161struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
162 int flags);
Bjorn Helgaascc8c2e32008-04-28 16:34:36 -0600163struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
164 resource_size_t start,
165 resource_size_t end, int flags);
Bjorn Helgaasd6180f32008-04-28 16:34:37 -0600166struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
167 resource_size_t start,
168 resource_size_t end, int flags);
Bjorn Helgaas7e0e9c02010-03-05 10:47:57 -0700169struct pnp_resource *pnp_add_bus_resource(struct pnp_dev *dev,
170 resource_size_t start,
171 resource_size_t end);
Bjorn Helgaas97ef0622008-08-19 16:53:41 -0600172
173extern int pnp_debug;
174
175#if defined(CONFIG_PNP_DEBUG_MESSAGES)
176#define pnp_dbg(dev, format, arg...) \
177 ({ if (pnp_debug) dev_printk(KERN_DEBUG, dev, format, ## arg); 0; })
178#else
179#define pnp_dbg(dev, format, arg...) \
180 ({ if (0) dev_printk(KERN_DEBUG, dev, format, ## arg); 0; })
181#endif