Commit c9377667e6cdf4ac910b0932868275eb0dbfcfeb
Committed by
Rafael J. Wysocki
1 parent
d1c3ed669a
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
PNP: Simplify setting of resources
This patch factors out the setting of PNP resources into one function which is then reused for all PNP resource types. This makes the code more concise and avoids duplication. The parameters "type" and "flags" are not used at the moment but may be used by follow-up patches. Placeholders for these patches can be found in the comment lines that contain the "TBD" marker. As the code does not make any changes to the ABI, no regressions are expected. NB: While at it, support for bus type resources is added. Signed-off-by: Witold Szczeponik <Witold.Szczeponik@gmx.net> Reviewed-by: Bjorn Helgaas <bhelgaas@google.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Showing 1 changed file with 68 additions and 37 deletions Side-by-side Diff
drivers/pnp/interface.c
... | ... | @@ -298,6 +298,39 @@ |
298 | 298 | return ret; |
299 | 299 | } |
300 | 300 | |
301 | +static char *pnp_get_resource_value(char *buf, | |
302 | + unsigned long type, | |
303 | + resource_size_t *start, | |
304 | + resource_size_t *end, | |
305 | + unsigned long *flags) | |
306 | +{ | |
307 | + if (start) | |
308 | + *start = 0; | |
309 | + if (end) | |
310 | + *end = 0; | |
311 | + if (flags) | |
312 | + *flags = 0; | |
313 | + | |
314 | + /* TBD: allow for disabled resources */ | |
315 | + | |
316 | + buf = skip_spaces(buf); | |
317 | + if (start) { | |
318 | + *start = simple_strtoull(buf, &buf, 0); | |
319 | + if (end) { | |
320 | + buf = skip_spaces(buf); | |
321 | + if (*buf == '-') { | |
322 | + buf = skip_spaces(buf + 1); | |
323 | + *end = simple_strtoull(buf, &buf, 0); | |
324 | + } else | |
325 | + *end = *start; | |
326 | + } | |
327 | + } | |
328 | + | |
329 | + /* TBD: allow for additional flags, e.g., IORESOURCE_WINDOW */ | |
330 | + | |
331 | + return buf; | |
332 | +} | |
333 | + | |
301 | 334 | static ssize_t pnp_set_current_resources(struct device *dmdev, |
302 | 335 | struct device_attribute *attr, |
303 | 336 | const char *ubuf, size_t count) |
... | ... | @@ -305,7 +338,6 @@ |
305 | 338 | struct pnp_dev *dev = to_pnp_dev(dmdev); |
306 | 339 | char *buf = (void *)ubuf; |
307 | 340 | int retval = 0; |
308 | - resource_size_t start, end; | |
309 | 341 | |
310 | 342 | if (dev->status & PNP_ATTACHED) { |
311 | 343 | retval = -EBUSY; |
... | ... | @@ -349,6 +381,10 @@ |
349 | 381 | goto done; |
350 | 382 | } |
351 | 383 | if (!strnicmp(buf, "set", 3)) { |
384 | + resource_size_t start; | |
385 | + resource_size_t end; | |
386 | + unsigned long flags; | |
387 | + | |
352 | 388 | if (dev->active) |
353 | 389 | goto done; |
354 | 390 | buf += 3; |
... | ... | @@ -357,42 +393,37 @@ |
357 | 393 | while (1) { |
358 | 394 | buf = skip_spaces(buf); |
359 | 395 | if (!strnicmp(buf, "io", 2)) { |
360 | - buf = skip_spaces(buf + 2); | |
361 | - start = simple_strtoul(buf, &buf, 0); | |
362 | - buf = skip_spaces(buf); | |
363 | - if (*buf == '-') { | |
364 | - buf = skip_spaces(buf + 1); | |
365 | - end = simple_strtoul(buf, &buf, 0); | |
366 | - } else | |
367 | - end = start; | |
368 | - pnp_add_io_resource(dev, start, end, 0); | |
369 | - continue; | |
370 | - } | |
371 | - if (!strnicmp(buf, "mem", 3)) { | |
372 | - buf = skip_spaces(buf + 3); | |
373 | - start = simple_strtoul(buf, &buf, 0); | |
374 | - buf = skip_spaces(buf); | |
375 | - if (*buf == '-') { | |
376 | - buf = skip_spaces(buf + 1); | |
377 | - end = simple_strtoul(buf, &buf, 0); | |
378 | - } else | |
379 | - end = start; | |
380 | - pnp_add_mem_resource(dev, start, end, 0); | |
381 | - continue; | |
382 | - } | |
383 | - if (!strnicmp(buf, "irq", 3)) { | |
384 | - buf = skip_spaces(buf + 3); | |
385 | - start = simple_strtoul(buf, &buf, 0); | |
386 | - pnp_add_irq_resource(dev, start, 0); | |
387 | - continue; | |
388 | - } | |
389 | - if (!strnicmp(buf, "dma", 3)) { | |
390 | - buf = skip_spaces(buf + 3); | |
391 | - start = simple_strtoul(buf, &buf, 0); | |
392 | - pnp_add_dma_resource(dev, start, 0); | |
393 | - continue; | |
394 | - } | |
395 | - break; | |
396 | + buf = pnp_get_resource_value(buf + 2, | |
397 | + IORESOURCE_IO, | |
398 | + &start, &end, | |
399 | + &flags); | |
400 | + pnp_add_io_resource(dev, start, end, flags); | |
401 | + } else if (!strnicmp(buf, "mem", 3)) { | |
402 | + buf = pnp_get_resource_value(buf + 3, | |
403 | + IORESOURCE_MEM, | |
404 | + &start, &end, | |
405 | + &flags); | |
406 | + pnp_add_mem_resource(dev, start, end, flags); | |
407 | + } else if (!strnicmp(buf, "irq", 3)) { | |
408 | + buf = pnp_get_resource_value(buf + 3, | |
409 | + IORESOURCE_IRQ, | |
410 | + &start, NULL, | |
411 | + &flags); | |
412 | + pnp_add_irq_resource(dev, start, flags); | |
413 | + } else if (!strnicmp(buf, "dma", 3)) { | |
414 | + buf = pnp_get_resource_value(buf + 3, | |
415 | + IORESOURCE_DMA, | |
416 | + &start, NULL, | |
417 | + &flags); | |
418 | + pnp_add_dma_resource(dev, start, flags); | |
419 | + } else if (!strnicmp(buf, "bus", 3)) { | |
420 | + buf = pnp_get_resource_value(buf + 3, | |
421 | + IORESOURCE_BUS, | |
422 | + &start, &end, | |
423 | + NULL); | |
424 | + pnp_add_bus_resource(dev, start, end); | |
425 | + } else | |
426 | + break; | |
396 | 427 | } |
397 | 428 | mutex_unlock(&pnp_res_mutex); |
398 | 429 | goto done; |