1 // SPDX-License-Identifier: GPL-2.0
3 * support.c - standard functions for the use of pnp protocol drivers
6 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
10 #include <linux/module.h>
11 #include <linux/ctype.h>
12 #include <linux/pnp.h>
16 * pnp_is_active - Determines if a device is active based on its current
18 * @dev: pointer to the desired PnP device
20 int pnp_is_active(struct pnp_dev *dev)
23 * I don't think this is very reliable because pnp_disable_dev()
24 * only clears out auto-assigned resources.
26 if (!pnp_port_start(dev, 0) && pnp_port_len(dev, 0) <= 1 &&
27 !pnp_mem_start(dev, 0) && pnp_mem_len(dev, 0) <= 1 &&
28 pnp_irq(dev, 0) == -1 && pnp_dma(dev, 0) == -1)
34 EXPORT_SYMBOL(pnp_is_active);
37 * Functionally similar to acpi_ex_eisa_id_to_string(), but that's
38 * buried in the ACPI CA, and we can't depend on it being present.
40 void pnp_eisa_id_to_string(u32 id, char *str)
45 * According to the specs, the first three characters are five-bit
46 * compressed ASCII, and the left-over high order bit should be zero.
47 * However, the Linux ISAPNP code historically used six bits for the
48 * first character, and there seem to be IDs that depend on that,
49 * e.g., "nEC8241" in the Linux 8250_pnp serial driver and the
50 * FreeBSD sys/pc98/cbus/sio_cbus.c driver.
52 str[0] = 'A' + ((id >> 26) & 0x3f) - 1;
53 str[1] = 'A' + ((id >> 21) & 0x1f) - 1;
54 str[2] = 'A' + ((id >> 16) & 0x1f) - 1;
55 str[3] = hex_asc_hi(id >> 8);
56 str[4] = hex_asc_lo(id >> 8);
57 str[5] = hex_asc_hi(id);
58 str[6] = hex_asc_lo(id);
62 char *pnp_resource_type_name(struct resource *res)
64 switch (pnp_resource_type(res)) {
79 void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc)
81 struct pnp_resource *pnp_res;
83 if (list_empty(&dev->resources))
84 pnp_dbg(&dev->dev, "%s: no current resources\n", desc);
86 pnp_dbg(&dev->dev, "%s: current resources:\n", desc);
87 list_for_each_entry(pnp_res, &dev->resources, list)
88 pnp_dbg(&dev->dev, "%pr\n", &pnp_res->res);
92 char *pnp_option_priority_name(struct pnp_option *option)
94 switch (pnp_option_priority(option)) {
95 case PNP_RES_PRIORITY_PREFERRED:
97 case PNP_RES_PRIORITY_ACCEPTABLE:
99 case PNP_RES_PRIORITY_FUNCTIONAL:
105 void dbg_pnp_show_option(struct pnp_dev *dev, struct pnp_option *option)
109 struct pnp_port *port;
114 if (pnp_option_is_dependent(option))
115 len += scnprintf(buf + len, sizeof(buf) - len,
116 " dependent set %d (%s) ",
117 pnp_option_set(option),
118 pnp_option_priority_name(option));
120 len += scnprintf(buf + len, sizeof(buf) - len,
123 switch (option->type) {
125 port = &option->u.port;
126 len += scnprintf(buf + len, sizeof(buf) - len, "io min %#llx "
127 "max %#llx align %lld size %lld flags %#x",
128 (unsigned long long) port->min,
129 (unsigned long long) port->max,
130 (unsigned long long) port->align,
131 (unsigned long long) port->size, port->flags);
134 mem = &option->u.mem;
135 len += scnprintf(buf + len, sizeof(buf) - len, "mem min %#llx "
136 "max %#llx align %lld size %lld flags %#x",
137 (unsigned long long) mem->min,
138 (unsigned long long) mem->max,
139 (unsigned long long) mem->align,
140 (unsigned long long) mem->size, mem->flags);
143 irq = &option->u.irq;
144 len += scnprintf(buf + len, sizeof(buf) - len, "irq");
145 if (bitmap_empty(irq->map.bits, PNP_IRQ_NR))
146 len += scnprintf(buf + len, sizeof(buf) - len,
149 for (i = 0; i < PNP_IRQ_NR; i++)
150 if (test_bit(i, irq->map.bits))
151 len += scnprintf(buf + len,
155 len += scnprintf(buf + len, sizeof(buf) - len, " flags %#x",
157 if (irq->flags & IORESOURCE_IRQ_OPTIONAL)
158 len += scnprintf(buf + len, sizeof(buf) - len,
162 dma = &option->u.dma;
163 len += scnprintf(buf + len, sizeof(buf) - len, "dma");
165 len += scnprintf(buf + len, sizeof(buf) - len,
168 for (i = 0; i < 8; i++)
169 if (dma->map & (1 << i))
170 len += scnprintf(buf + len,
174 len += scnprintf(buf + len, sizeof(buf) - len, " (bitmask %#x) "
175 "flags %#x", dma->map, dma->flags);
178 pnp_dbg(&dev->dev, "%s\n", buf);