Blame view
drivers/pnp/support.c
4.8 KB
1da177e4c Linux-2.6.12-rc2 |
1 |
/* |
07d4e9af1 PNP: fix up after... |
2 |
* support.c - standard functions for the use of pnp protocol drivers |
1da177e4c Linux-2.6.12-rc2 |
3 4 |
* * Copyright 2003 Adam Belay <ambx1@neo.rr.com> |
1f32ca31e PNP: convert reso... |
5 6 |
* Copyright (C) 2008 Hewlett-Packard Development Company, L.P. * Bjorn Helgaas <bjorn.helgaas@hp.com> |
1da177e4c Linux-2.6.12-rc2 |
7 |
*/ |
1da177e4c Linux-2.6.12-rc2 |
8 9 |
#include <linux/module.h> #include <linux/ctype.h> |
1da177e4c Linux-2.6.12-rc2 |
10 11 12 13 |
#include <linux/pnp.h> #include "base.h" /** |
07d4e9af1 PNP: fix up after... |
14 15 |
* pnp_is_active - Determines if a device is active based on its current * resources |
1da177e4c Linux-2.6.12-rc2 |
16 |
* @dev: pointer to the desired PnP device |
1da177e4c Linux-2.6.12-rc2 |
17 |
*/ |
9dd78466c PNP: Lindent all ... |
18 |
int pnp_is_active(struct pnp_dev *dev) |
1da177e4c Linux-2.6.12-rc2 |
19 |
{ |
aee3ad815 PNP: replace pnp_... |
20 21 22 23 |
/* * I don't think this is very reliable because pnp_disable_dev() * only clears out auto-assigned resources. */ |
1da177e4c Linux-2.6.12-rc2 |
24 25 |
if (!pnp_port_start(dev, 0) && pnp_port_len(dev, 0) <= 1 && !pnp_mem_start(dev, 0) && pnp_mem_len(dev, 0) <= 1 && |
9dd78466c PNP: Lindent all ... |
26 27 |
pnp_irq(dev, 0) == -1 && pnp_dma(dev, 0) == -1) return 0; |
1da177e4c Linux-2.6.12-rc2 |
28 29 30 |
else return 1; } |
1da177e4c Linux-2.6.12-rc2 |
31 |
EXPORT_SYMBOL(pnp_is_active); |
25eb84618 PNP: add pnp_eisa... |
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
/* * Functionally similar to acpi_ex_eisa_id_to_string(), but that's * buried in the ACPI CA, and we can't depend on it being present. */ void pnp_eisa_id_to_string(u32 id, char *str) { id = be32_to_cpu(id); /* * According to the specs, the first three characters are five-bit * compressed ASCII, and the left-over high order bit should be zero. * However, the Linux ISAPNP code historically used six bits for the * first character, and there seem to be IDs that depend on that, * e.g., "nEC8241" in the Linux 8250_pnp serial driver and the * FreeBSD sys/pc98/cbus/sio_cbus.c driver. */ str[0] = 'A' + ((id >> 26) & 0x3f) - 1; str[1] = 'A' + ((id >> 21) & 0x1f) - 1; str[2] = 'A' + ((id >> 16) & 0x1f) - 1; |
3fc957721 lib: create commo... |
52 53 54 55 |
str[3] = hex_asc_hi(id >> 8); str[4] = hex_asc_lo(id >> 8); str[5] = hex_asc_hi(id); str[6] = hex_asc_lo(id); |
25eb84618 PNP: add pnp_eisa... |
56 57 |
str[7] = '\0'; } |
81b5c75f0 PNP: add debug wh... |
58 |
|
9fdee4e02 PNP: add pnp_reso... |
59 60 61 62 63 64 65 66 67 68 69 |
char *pnp_resource_type_name(struct resource *res) { switch (pnp_resource_type(res)) { case IORESOURCE_IO: return "io"; case IORESOURCE_MEM: return "mem"; case IORESOURCE_IRQ: return "irq"; case IORESOURCE_DMA: return "dma"; |
7e0e9c042 PNPACPI: add bus ... |
70 71 |
case IORESOURCE_BUS: return "bus"; |
9fdee4e02 PNP: add pnp_reso... |
72 |
} |
7e0e9c042 PNPACPI: add bus ... |
73 |
return "unknown"; |
9fdee4e02 PNP: add pnp_reso... |
74 |
} |
81b5c75f0 PNP: add debug wh... |
75 76 |
void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc) { |
aee3ad815 PNP: replace pnp_... |
77 |
struct pnp_resource *pnp_res; |
81b5c75f0 PNP: add debug wh... |
78 |
|
9a007b379 PNP: print resour... |
79 |
if (list_empty(&dev->resources)) |
2f53432c2 PNP: convert to u... |
80 81 |
pnp_dbg(&dev->dev, "%s: no current resources ", desc); |
9a007b379 PNP: print resour... |
82 83 84 85 |
else { pnp_dbg(&dev->dev, "%s: current resources: ", desc); list_for_each_entry(pnp_res, &dev->resources, list) |
c7dabef8a vsprintf: use %pR... |
86 87 |
pnp_dbg(&dev->dev, "%pr ", &pnp_res->res); |
81b5c75f0 PNP: add debug wh... |
88 |
} |
81b5c75f0 PNP: add debug wh... |
89 |
} |
1f32ca31e PNP: convert reso... |
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
char *pnp_option_priority_name(struct pnp_option *option) { switch (pnp_option_priority(option)) { case PNP_RES_PRIORITY_PREFERRED: return "preferred"; case PNP_RES_PRIORITY_ACCEPTABLE: return "acceptable"; case PNP_RES_PRIORITY_FUNCTIONAL: return "functional"; } return "invalid"; } void dbg_pnp_show_option(struct pnp_dev *dev, struct pnp_option *option) { |
1f32ca31e PNP: convert reso... |
106 107 108 109 110 111 112 113 |
char buf[128]; int len = 0, i; struct pnp_port *port; struct pnp_mem *mem; struct pnp_irq *irq; struct pnp_dma *dma; if (pnp_option_is_dependent(option)) |
ea44c1d60 PNP: fix formatti... |
114 115 116 117 |
len += scnprintf(buf + len, sizeof(buf) - len, " dependent set %d (%s) ", pnp_option_set(option), pnp_option_priority_name(option)); |
1f32ca31e PNP: convert reso... |
118 |
else |
ea44c1d60 PNP: fix formatti... |
119 120 |
len += scnprintf(buf + len, sizeof(buf) - len, " independent "); |
1f32ca31e PNP: convert reso... |
121 122 123 124 |
switch (option->type) { case IORESOURCE_IO: port = &option->u.port; |
ea44c1d60 PNP: fix formatti... |
125 126 127 128 129 130 |
len += scnprintf(buf + len, sizeof(buf) - len, "io min %#llx " "max %#llx align %lld size %lld flags %#x", (unsigned long long) port->min, (unsigned long long) port->max, (unsigned long long) port->align, (unsigned long long) port->size, port->flags); |
1f32ca31e PNP: convert reso... |
131 132 133 |
break; case IORESOURCE_MEM: mem = &option->u.mem; |
ea44c1d60 PNP: fix formatti... |
134 135 136 137 138 139 |
len += scnprintf(buf + len, sizeof(buf) - len, "mem min %#llx " "max %#llx align %lld size %lld flags %#x", (unsigned long long) mem->min, (unsigned long long) mem->max, (unsigned long long) mem->align, (unsigned long long) mem->size, mem->flags); |
1f32ca31e PNP: convert reso... |
140 141 142 |
break; case IORESOURCE_IRQ: irq = &option->u.irq; |
ea44c1d60 PNP: fix formatti... |
143 |
len += scnprintf(buf + len, sizeof(buf) - len, "irq"); |
1f32ca31e PNP: convert reso... |
144 |
if (bitmap_empty(irq->map.bits, PNP_IRQ_NR)) |
ea44c1d60 PNP: fix formatti... |
145 146 |
len += scnprintf(buf + len, sizeof(buf) - len, " <none>"); |
1f32ca31e PNP: convert reso... |
147 148 149 |
else { for (i = 0; i < PNP_IRQ_NR; i++) if (test_bit(i, irq->map.bits)) |
ea44c1d60 PNP: fix formatti... |
150 151 152 |
len += scnprintf(buf + len, sizeof(buf) - len, " %d", i); |
1f32ca31e PNP: convert reso... |
153 |
} |
ea44c1d60 PNP: fix formatti... |
154 155 |
len += scnprintf(buf + len, sizeof(buf) - len, " flags %#x", irq->flags); |
1f32ca31e PNP: convert reso... |
156 |
if (irq->flags & IORESOURCE_IRQ_OPTIONAL) |
ea44c1d60 PNP: fix formatti... |
157 158 |
len += scnprintf(buf + len, sizeof(buf) - len, " (optional)"); |
1f32ca31e PNP: convert reso... |
159 160 161 |
break; case IORESOURCE_DMA: dma = &option->u.dma; |
ea44c1d60 PNP: fix formatti... |
162 |
len += scnprintf(buf + len, sizeof(buf) - len, "dma"); |
1f32ca31e PNP: convert reso... |
163 |
if (!dma->map) |
ea44c1d60 PNP: fix formatti... |
164 165 |
len += scnprintf(buf + len, sizeof(buf) - len, " <none>"); |
1f32ca31e PNP: convert reso... |
166 167 168 |
else { for (i = 0; i < 8; i++) if (dma->map & (1 << i)) |
ea44c1d60 PNP: fix formatti... |
169 170 171 |
len += scnprintf(buf + len, sizeof(buf) - len, " %d", i); |
1f32ca31e PNP: convert reso... |
172 |
} |
ea44c1d60 PNP: fix formatti... |
173 174 |
len += scnprintf(buf + len, sizeof(buf) - len, " (bitmask %#x) " "flags %#x", dma->map, dma->flags); |
1f32ca31e PNP: convert reso... |
175 176 |
break; } |
2f53432c2 PNP: convert to u... |
177 178 |
pnp_dbg(&dev->dev, "%s ", buf); |
1f32ca31e PNP: convert reso... |
179 |
} |