consistent.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (C) 2004 - 2007 Paul Mundt
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. */
  8. #include <linux/mm.h>
  9. #include <linux/init.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/dma-mapping.h>
  12. #include <linux/io.h>
  13. static int __init memchunk_setup(char *str)
  14. {
  15. return 1; /* accept anything that begins with "memchunk." */
  16. }
  17. __setup("memchunk.", memchunk_setup);
  18. static void __init memchunk_cmdline_override(char *name, unsigned long *sizep)
  19. {
  20. char *p = boot_command_line;
  21. int k = strlen(name);
  22. while ((p = strstr(p, "memchunk."))) {
  23. p += 9; /* strlen("memchunk.") */
  24. if (!strncmp(name, p, k) && p[k] == '=') {
  25. p += k + 1;
  26. *sizep = memparse(p, NULL);
  27. pr_info("%s: forcing memory chunk size to 0x%08lx\n",
  28. name, *sizep);
  29. break;
  30. }
  31. }
  32. }
  33. int __init platform_resource_setup_memory(struct platform_device *pdev,
  34. char *name, unsigned long memsize)
  35. {
  36. struct resource *r;
  37. dma_addr_t dma_handle;
  38. void *buf;
  39. r = pdev->resource + pdev->num_resources - 1;
  40. if (r->flags) {
  41. pr_warn("%s: unable to find empty space for resource\n", name);
  42. return -EINVAL;
  43. }
  44. memchunk_cmdline_override(name, &memsize);
  45. if (!memsize)
  46. return 0;
  47. buf = dma_alloc_coherent(&pdev->dev, memsize, &dma_handle, GFP_KERNEL);
  48. if (!buf) {
  49. pr_warn("%s: unable to allocate memory\n", name);
  50. return -ENOMEM;
  51. }
  52. r->flags = IORESOURCE_MEM;
  53. r->start = dma_handle;
  54. r->end = r->start + memsize - 1;
  55. r->name = name;
  56. return 0;
  57. }