diff options
Diffstat (limited to 'drivers/pnp/base.h')
-rw-r--r-- | drivers/pnp/base.h | 148 |
1 files changed, 119 insertions, 29 deletions
diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h index 886dac823ed6..e3fa9a2d9a3d 100644 --- a/drivers/pnp/base.h +++ b/drivers/pnp/base.h | |||
@@ -1,3 +1,8 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. | ||
3 | * Bjorn Helgaas <bjorn.helgaas@hp.com> | ||
4 | */ | ||
5 | |||
1 | extern spinlock_t pnp_lock; | 6 | extern spinlock_t pnp_lock; |
2 | void *pnp_alloc(long size); | 7 | void *pnp_alloc(long size); |
3 | 8 | ||
@@ -19,22 +24,118 @@ void pnp_remove_card(struct pnp_card *card); | |||
19 | int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev); | 24 | int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev); |
20 | void pnp_remove_card_device(struct pnp_dev *dev); | 25 | void pnp_remove_card_device(struct pnp_dev *dev); |
21 | 26 | ||
22 | struct pnp_option *pnp_build_option(int priority); | 27 | struct pnp_port { |
23 | struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev); | 28 | resource_size_t min; /* min base number */ |
24 | struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev, | 29 | resource_size_t max; /* max base number */ |
25 | int priority); | 30 | resource_size_t align; /* align boundary */ |
26 | int pnp_register_irq_resource(struct pnp_dev *dev, struct pnp_option *option, | 31 | resource_size_t size; /* size of range */ |
27 | struct pnp_irq *data); | 32 | unsigned char flags; /* port flags */ |
28 | int pnp_register_dma_resource(struct pnp_dev *dev, struct pnp_option *option, | 33 | }; |
29 | struct pnp_dma *data); | 34 | |
30 | int pnp_register_port_resource(struct pnp_dev *dev, struct pnp_option *option, | 35 | #define PNP_IRQ_NR 256 |
31 | struct pnp_port *data); | 36 | typedef struct { DECLARE_BITMAP(bits, PNP_IRQ_NR); } pnp_irq_mask_t; |
32 | int pnp_register_mem_resource(struct pnp_dev *dev, struct pnp_option *option, | 37 | |
33 | struct pnp_mem *data); | 38 | struct pnp_irq { |
39 | pnp_irq_mask_t map; /* bitmap for IRQ lines */ | ||
40 | unsigned char flags; /* IRQ flags */ | ||
41 | }; | ||
42 | |||
43 | struct pnp_dma { | ||
44 | unsigned char map; /* bitmask for DMA channels */ | ||
45 | unsigned char flags; /* DMA flags */ | ||
46 | }; | ||
47 | |||
48 | struct pnp_mem { | ||
49 | resource_size_t min; /* min base number */ | ||
50 | resource_size_t max; /* max base number */ | ||
51 | resource_size_t align; /* align boundary */ | ||
52 | resource_size_t size; /* size of range */ | ||
53 | unsigned char flags; /* memory flags */ | ||
54 | }; | ||
55 | |||
56 | #define PNP_OPTION_DEPENDENT 0x80000000 | ||
57 | #define PNP_OPTION_SET_MASK 0xffff | ||
58 | #define PNP_OPTION_SET_SHIFT 12 | ||
59 | #define PNP_OPTION_PRIORITY_MASK 0xfff | ||
60 | #define PNP_OPTION_PRIORITY_SHIFT 0 | ||
61 | |||
62 | #define PNP_RES_PRIORITY_PREFERRED 0 | ||
63 | #define PNP_RES_PRIORITY_ACCEPTABLE 1 | ||
64 | #define PNP_RES_PRIORITY_FUNCTIONAL 2 | ||
65 | #define PNP_RES_PRIORITY_INVALID PNP_OPTION_PRIORITY_MASK | ||
66 | |||
67 | struct pnp_option { | ||
68 | struct list_head list; | ||
69 | unsigned int flags; /* independent/dependent, set, priority */ | ||
70 | |||
71 | unsigned long type; /* IORESOURCE_{IO,MEM,IRQ,DMA} */ | ||
72 | union { | ||
73 | struct pnp_port port; | ||
74 | struct pnp_irq irq; | ||
75 | struct pnp_dma dma; | ||
76 | struct pnp_mem mem; | ||
77 | } u; | ||
78 | }; | ||
79 | |||
80 | int pnp_register_irq_resource(struct pnp_dev *dev, unsigned int option_flags, | ||
81 | pnp_irq_mask_t *map, unsigned char flags); | ||
82 | int pnp_register_dma_resource(struct pnp_dev *dev, unsigned int option_flags, | ||
83 | unsigned char map, unsigned char flags); | ||
84 | int pnp_register_port_resource(struct pnp_dev *dev, unsigned int option_flags, | ||
85 | resource_size_t min, resource_size_t max, | ||
86 | resource_size_t align, resource_size_t size, | ||
87 | unsigned char flags); | ||
88 | int pnp_register_mem_resource(struct pnp_dev *dev, unsigned int option_flags, | ||
89 | resource_size_t min, resource_size_t max, | ||
90 | resource_size_t align, resource_size_t size, | ||
91 | unsigned char flags); | ||
92 | |||
93 | static inline int pnp_option_is_dependent(struct pnp_option *option) | ||
94 | { | ||
95 | return option->flags & PNP_OPTION_DEPENDENT ? 1 : 0; | ||
96 | } | ||
97 | |||
98 | static inline unsigned int pnp_option_set(struct pnp_option *option) | ||
99 | { | ||
100 | return (option->flags >> PNP_OPTION_SET_SHIFT) & PNP_OPTION_SET_MASK; | ||
101 | } | ||
102 | |||
103 | static inline unsigned int pnp_option_priority(struct pnp_option *option) | ||
104 | { | ||
105 | return (option->flags >> PNP_OPTION_PRIORITY_SHIFT) & | ||
106 | PNP_OPTION_PRIORITY_MASK; | ||
107 | } | ||
108 | |||
109 | static inline unsigned int pnp_new_dependent_set(struct pnp_dev *dev, | ||
110 | int priority) | ||
111 | { | ||
112 | unsigned int flags; | ||
113 | |||
114 | if (priority > PNP_RES_PRIORITY_FUNCTIONAL) { | ||
115 | dev_warn(&dev->dev, "invalid dependent option priority %d " | ||
116 | "clipped to %d", priority, | ||
117 | PNP_RES_PRIORITY_INVALID); | ||
118 | priority = PNP_RES_PRIORITY_INVALID; | ||
119 | } | ||
120 | |||
121 | flags = PNP_OPTION_DEPENDENT | | ||
122 | ((dev->num_dependent_sets & PNP_OPTION_SET_MASK) << | ||
123 | PNP_OPTION_SET_SHIFT) | | ||
124 | ((priority & PNP_OPTION_PRIORITY_MASK) << | ||
125 | PNP_OPTION_PRIORITY_SHIFT); | ||
126 | |||
127 | dev->num_dependent_sets++; | ||
128 | |||
129 | return flags; | ||
130 | } | ||
131 | |||
132 | char *pnp_option_priority_name(struct pnp_option *option); | ||
133 | void dbg_pnp_show_option(struct pnp_dev *dev, struct pnp_option *option); | ||
134 | |||
34 | void pnp_init_resources(struct pnp_dev *dev); | 135 | void pnp_init_resources(struct pnp_dev *dev); |
35 | 136 | ||
36 | void pnp_fixup_device(struct pnp_dev *dev); | 137 | void pnp_fixup_device(struct pnp_dev *dev); |
37 | void pnp_free_option(struct pnp_option *option); | 138 | void pnp_free_options(struct pnp_dev *dev); |
38 | int __pnp_add_device(struct pnp_dev *dev); | 139 | int __pnp_add_device(struct pnp_dev *dev); |
39 | void __pnp_remove_device(struct pnp_dev *dev); | 140 | void __pnp_remove_device(struct pnp_dev *dev); |
40 | 141 | ||
@@ -43,29 +144,18 @@ int pnp_check_mem(struct pnp_dev *dev, struct resource *res); | |||
43 | int pnp_check_irq(struct pnp_dev *dev, struct resource *res); | 144 | int pnp_check_irq(struct pnp_dev *dev, struct resource *res); |
44 | int pnp_check_dma(struct pnp_dev *dev, struct resource *res); | 145 | int pnp_check_dma(struct pnp_dev *dev, struct resource *res); |
45 | 146 | ||
147 | char *pnp_resource_type_name(struct resource *res); | ||
46 | void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc); | 148 | void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc); |
47 | 149 | ||
48 | void pnp_init_resource(struct resource *res); | 150 | void pnp_free_resources(struct pnp_dev *dev); |
49 | 151 | int pnp_resource_type(struct resource *res); | |
50 | struct pnp_resource *pnp_get_pnp_resource(struct pnp_dev *dev, | ||
51 | unsigned int type, unsigned int num); | ||
52 | |||
53 | #define PNP_MAX_PORT 40 | ||
54 | #define PNP_MAX_MEM 24 | ||
55 | #define PNP_MAX_IRQ 2 | ||
56 | #define PNP_MAX_DMA 2 | ||
57 | 152 | ||
58 | struct pnp_resource { | 153 | struct pnp_resource { |
154 | struct list_head list; | ||
59 | struct resource res; | 155 | struct resource res; |
60 | unsigned int index; /* ISAPNP config register index */ | ||
61 | }; | 156 | }; |
62 | 157 | ||
63 | struct pnp_resource_table { | 158 | void pnp_free_resource(struct pnp_resource *pnp_res); |
64 | struct pnp_resource port[PNP_MAX_PORT]; | ||
65 | struct pnp_resource mem[PNP_MAX_MEM]; | ||
66 | struct pnp_resource dma[PNP_MAX_DMA]; | ||
67 | struct pnp_resource irq[PNP_MAX_IRQ]; | ||
68 | }; | ||
69 | 159 | ||
70 | struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq, | 160 | struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq, |
71 | int flags); | 161 | int flags); |