2 * support.c - standard functions for the use of pnp protocol drivers
4 * Copyright 2003 Adam Belay <ambx1@neo.rr.com>
5 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
6 * Bjorn Helgaas <bjorn.helgaas@hp.com>
9 #include <linux/module.h>
10 #include <linux/ctype.h>
11 #include <linux/pnp.h>
15 * pnp_is_active - Determines if a device is active based on its current
17 * @dev: pointer to the desired PnP device
19 int pnp_is_active(struct pnp_dev
*dev
)
22 * I don't think this is very reliable because pnp_disable_dev()
23 * only clears out auto-assigned resources.
25 if (!pnp_port_start(dev
, 0) && pnp_port_len(dev
, 0) <= 1 &&
26 !pnp_mem_start(dev
, 0) && pnp_mem_len(dev
, 0) <= 1 &&
27 pnp_irq(dev
, 0) == -1 && pnp_dma(dev
, 0) == -1)
33 EXPORT_SYMBOL(pnp_is_active
);
36 * Functionally similar to acpi_ex_eisa_id_to_string(), but that's
37 * buried in the ACPI CA, and we can't depend on it being present.
39 void pnp_eisa_id_to_string(u32 id
, char *str
)
44 * According to the specs, the first three characters are five-bit
45 * compressed ASCII, and the left-over high order bit should be zero.
46 * However, the Linux ISAPNP code historically used six bits for the
47 * first character, and there seem to be IDs that depend on that,
48 * e.g., "nEC8241" in the Linux 8250_pnp serial driver and the
49 * FreeBSD sys/pc98/cbus/sio_cbus.c driver.
51 str
[0] = 'A' + ((id
>> 26) & 0x3f) - 1;
52 str
[1] = 'A' + ((id
>> 21) & 0x1f) - 1;
53 str
[2] = 'A' + ((id
>> 16) & 0x1f) - 1;
54 str
[3] = hex_asc_hi(id
>> 8);
55 str
[4] = hex_asc_lo(id
>> 8);
56 str
[5] = hex_asc_hi(id
);
57 str
[6] = hex_asc_lo(id
);
61 char *pnp_resource_type_name(struct resource
*res
)
63 switch (pnp_resource_type(res
)) {
76 void dbg_pnp_show_resources(struct pnp_dev
*dev
, char *desc
)
80 struct pnp_resource
*pnp_res
;
83 if (list_empty(&dev
->resources
)) {
84 pnp_dbg(&dev
->dev
, "%s: no current resources\n", desc
);
88 pnp_dbg(&dev
->dev
, "%s: current resources:\n", desc
);
89 list_for_each_entry(pnp_res
, &dev
->resources
, list
) {
93 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
, " %-3s ",
94 pnp_resource_type_name(res
));
96 if (res
->flags
& IORESOURCE_DISABLED
) {
97 pnp_dbg(&dev
->dev
, "%sdisabled\n", buf
);
101 switch (pnp_resource_type(res
)) {
104 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
,
105 "%#llx-%#llx flags %#lx",
106 (unsigned long long) res
->start
,
107 (unsigned long long) res
->end
,
112 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
,
114 (unsigned long long) res
->start
,
118 pnp_dbg(&dev
->dev
, "%s\n", buf
);
122 char *pnp_option_priority_name(struct pnp_option
*option
)
124 switch (pnp_option_priority(option
)) {
125 case PNP_RES_PRIORITY_PREFERRED
:
127 case PNP_RES_PRIORITY_ACCEPTABLE
:
129 case PNP_RES_PRIORITY_FUNCTIONAL
:
135 void dbg_pnp_show_option(struct pnp_dev
*dev
, struct pnp_option
*option
)
139 struct pnp_port
*port
;
144 if (pnp_option_is_dependent(option
))
145 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
,
146 " dependent set %d (%s) ",
147 pnp_option_set(option
),
148 pnp_option_priority_name(option
));
150 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
,
153 switch (option
->type
) {
155 port
= &option
->u
.port
;
156 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
, "io min %#llx "
157 "max %#llx align %lld size %lld flags %#x",
158 (unsigned long long) port
->min
,
159 (unsigned long long) port
->max
,
160 (unsigned long long) port
->align
,
161 (unsigned long long) port
->size
, port
->flags
);
164 mem
= &option
->u
.mem
;
165 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
, "mem min %#llx "
166 "max %#llx align %lld size %lld flags %#x",
167 (unsigned long long) mem
->min
,
168 (unsigned long long) mem
->max
,
169 (unsigned long long) mem
->align
,
170 (unsigned long long) mem
->size
, mem
->flags
);
173 irq
= &option
->u
.irq
;
174 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
, "irq");
175 if (bitmap_empty(irq
->map
.bits
, PNP_IRQ_NR
))
176 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
,
179 for (i
= 0; i
< PNP_IRQ_NR
; i
++)
180 if (test_bit(i
, irq
->map
.bits
))
181 len
+= scnprintf(buf
+ len
,
185 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
, " flags %#x",
187 if (irq
->flags
& IORESOURCE_IRQ_OPTIONAL
)
188 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
,
192 dma
= &option
->u
.dma
;
193 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
, "dma");
195 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
,
198 for (i
= 0; i
< 8; i
++)
199 if (dma
->map
& (1 << i
))
200 len
+= scnprintf(buf
+ len
,
204 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
, " (bitmask %#x) "
205 "flags %#x", dma
->map
, dma
->flags
);
208 pnp_dbg(&dev
->dev
, "%s\n", buf
);