consistent.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_warning("%s: unable to find empty space for resource\n",
  42. name);
  43. return -EINVAL;
  44. }
  45. memchunk_cmdline_override(name, &memsize);
  46. if (!memsize)
  47. return 0;
  48. buf = dma_alloc_coherent(&pdev->dev, memsize, &dma_handle, GFP_KERNEL);
  49. if (!buf) {
  50. pr_warning("%s: unable to allocate memory\n", name);
  51. return -ENOMEM;
  52. }
  53. memset(buf, 0, memsize);
  54. r->flags = IORESOURCE_MEM;
  55. r->start = dma_handle;
  56. r->end = r->start + memsize - 1;
  57. r->name = name;
  58. return 0;
  59. }