Skip to content

Commit d948a8d

Browse files
Bjorn Helgaaslenb
authored andcommitted
PNP: factor pnp_init_resource_table() and pnp_clean_resource_table()
Move the common part of pnp_init_resource_table() and pnp_clean_resource_table() into a new pnp_init_resource(). This reduces a little code duplication and will be useful later to initialize an individual resource. Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent af11cb2 commit d948a8d

2 files changed

Lines changed: 54 additions & 46 deletions

File tree

‎drivers/pnp/base.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ int pnp_check_irq(struct pnp_dev * dev, int idx);
1818
int pnp_check_dma(struct pnp_dev * dev, int idx);
1919

2020
void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc);
21+
22+
void pnp_init_resource(struct resource *res);

‎drivers/pnp/manager.c‎

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -234,42 +234,52 @@ static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
234234
dev_dbg(&dev->dev, " disable dma %d\n", idx);
235235
}
236236

237+
void pnp_init_resource(struct resource *res)
238+
{
239+
unsigned long type;
240+
241+
type = res->flags & (IORESOURCE_IO | IORESOURCE_MEM |
242+
IORESOURCE_IRQ | IORESOURCE_DMA);
243+
244+
res->name = NULL;
245+
res->flags = type | IORESOURCE_AUTO | IORESOURCE_UNSET;
246+
if (type == IORESOURCE_IRQ || type == IORESOURCE_DMA) {
247+
res->start = -1;
248+
res->end = -1;
249+
} else {
250+
res->start = 0;
251+
res->end = 0;
252+
}
253+
}
254+
237255
/**
238256
* pnp_init_resources - Resets a resource table to default values.
239257
* @table: pointer to the desired resource table
240258
*/
241259
void pnp_init_resources(struct pnp_dev *dev)
242260
{
243-
struct pnp_resource_table *table = &dev->res;
261+
struct resource *res;
244262
int idx;
245263

246264
for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
247-
table->irq_resource[idx].name = NULL;
248-
table->irq_resource[idx].start = -1;
249-
table->irq_resource[idx].end = -1;
250-
table->irq_resource[idx].flags =
251-
IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET;
265+
res = &dev->res.irq_resource[idx];
266+
res->flags = IORESOURCE_IRQ;
267+
pnp_init_resource(res);
252268
}
253269
for (idx = 0; idx < PNP_MAX_DMA; idx++) {
254-
table->dma_resource[idx].name = NULL;
255-
table->dma_resource[idx].start = -1;
256-
table->dma_resource[idx].end = -1;
257-
table->dma_resource[idx].flags =
258-
IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET;
270+
res = &dev->res.dma_resource[idx];
271+
res->flags = IORESOURCE_DMA;
272+
pnp_init_resource(res);
259273
}
260274
for (idx = 0; idx < PNP_MAX_PORT; idx++) {
261-
table->port_resource[idx].name = NULL;
262-
table->port_resource[idx].start = 0;
263-
table->port_resource[idx].end = 0;
264-
table->port_resource[idx].flags =
265-
IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET;
275+
res = &dev->res.port_resource[idx];
276+
res->flags = IORESOURCE_IO;
277+
pnp_init_resource(res);
266278
}
267279
for (idx = 0; idx < PNP_MAX_MEM; idx++) {
268-
table->mem_resource[idx].name = NULL;
269-
table->mem_resource[idx].start = 0;
270-
table->mem_resource[idx].end = 0;
271-
table->mem_resource[idx].flags =
272-
IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET;
280+
res = &dev->res.mem_resource[idx];
281+
res->flags = IORESOURCE_MEM;
282+
pnp_init_resource(res);
273283
}
274284
}
275285

@@ -279,40 +289,36 @@ void pnp_init_resources(struct pnp_dev *dev)
279289
*/
280290
static void pnp_clean_resource_table(struct pnp_dev *dev)
281291
{
282-
struct pnp_resource_table *res = &dev->res;
292+
struct resource *res;
283293
int idx;
284294

285295
for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
286-
if (!(res->irq_resource[idx].flags & IORESOURCE_AUTO))
287-
continue;
288-
res->irq_resource[idx].start = -1;
289-
res->irq_resource[idx].end = -1;
290-
res->irq_resource[idx].flags =
291-
IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET;
296+
res = &dev->res.irq_resource[idx];
297+
if (res->flags & IORESOURCE_AUTO) {
298+
res->flags = IORESOURCE_IRQ;
299+
pnp_init_resource(res);
300+
}
292301
}
293302
for (idx = 0; idx < PNP_MAX_DMA; idx++) {
294-
if (!(res->dma_resource[idx].flags & IORESOURCE_AUTO))
295-
continue;
296-
res->dma_resource[idx].start = -1;
297-
res->dma_resource[idx].end = -1;
298-
res->dma_resource[idx].flags =
299-
IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET;
303+
res = &dev->res.dma_resource[idx];
304+
if (res->flags & IORESOURCE_AUTO) {
305+
res->flags = IORESOURCE_DMA;
306+
pnp_init_resource(res);
307+
}
300308
}
301309
for (idx = 0; idx < PNP_MAX_PORT; idx++) {
302-
if (!(res->port_resource[idx].flags & IORESOURCE_AUTO))
303-
continue;
304-
res->port_resource[idx].start = 0;
305-
res->port_resource[idx].end = 0;
306-
res->port_resource[idx].flags =
307-
IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET;
310+
res = &dev->res.port_resource[idx];
311+
if (res->flags & IORESOURCE_AUTO) {
312+
res->flags = IORESOURCE_IO;
313+
pnp_init_resource(res);
314+
}
308315
}
309316
for (idx = 0; idx < PNP_MAX_MEM; idx++) {
310-
if (!(res->mem_resource[idx].flags & IORESOURCE_AUTO))
311-
continue;
312-
res->mem_resource[idx].start = 0;
313-
res->mem_resource[idx].end = 0;
314-
res->mem_resource[idx].flags =
315-
IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET;
317+
res = &dev->res.mem_resource[idx];
318+
if (res->flags & IORESOURCE_AUTO) {
319+
res->flags = IORESOURCE_MEM;
320+
pnp_init_resource(res);
321+
}
316322
}
317323
}
318324

0 commit comments

Comments
 (0)