prom_common.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* prom_common.c: OF device tree support common code.
  2. *
  3. * Paul Mackerras August 1996.
  4. * Copyright (C) 1996-2005 Paul Mackerras.
  5. *
  6. * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
  7. * {engebret|bergner}@us.ibm.com
  8. *
  9. * Adapted for sparc by David S. Miller davem@davemloft.net
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/errno.h>
  19. #include <linux/mutex.h>
  20. #include <linux/slab.h>
  21. #include <linux/of.h>
  22. #include <asm/prom.h>
  23. #include <asm/oplib.h>
  24. #include <asm/leon.h>
  25. #include "prom.h"
  26. struct device_node *of_console_device;
  27. EXPORT_SYMBOL(of_console_device);
  28. char *of_console_path;
  29. EXPORT_SYMBOL(of_console_path);
  30. char *of_console_options;
  31. EXPORT_SYMBOL(of_console_options);
  32. int of_getintprop_default(struct device_node *np, const char *name, int def)
  33. {
  34. struct property *prop;
  35. int len;
  36. prop = of_find_property(np, name, &len);
  37. if (!prop || len != 4)
  38. return def;
  39. return *(int *) prop->value;
  40. }
  41. EXPORT_SYMBOL(of_getintprop_default);
  42. DEFINE_MUTEX(of_set_property_mutex);
  43. EXPORT_SYMBOL(of_set_property_mutex);
  44. int of_set_property(struct device_node *dp, const char *name, void *val, int len)
  45. {
  46. struct property **prevp;
  47. void *new_val;
  48. int err;
  49. new_val = kmalloc(len, GFP_KERNEL);
  50. if (!new_val)
  51. return -ENOMEM;
  52. memcpy(new_val, val, len);
  53. err = -ENODEV;
  54. mutex_lock(&of_set_property_mutex);
  55. write_lock(&devtree_lock);
  56. prevp = &dp->properties;
  57. while (*prevp) {
  58. struct property *prop = *prevp;
  59. if (!strcasecmp(prop->name, name)) {
  60. void *old_val = prop->value;
  61. int ret;
  62. ret = prom_setprop(dp->phandle, name, val, len);
  63. err = -EINVAL;
  64. if (ret >= 0) {
  65. prop->value = new_val;
  66. prop->length = len;
  67. if (OF_IS_DYNAMIC(prop))
  68. kfree(old_val);
  69. OF_MARK_DYNAMIC(prop);
  70. err = 0;
  71. }
  72. break;
  73. }
  74. prevp = &(*prevp)->next;
  75. }
  76. write_unlock(&devtree_lock);
  77. mutex_unlock(&of_set_property_mutex);
  78. /* XXX Upate procfs if necessary... */
  79. return err;
  80. }
  81. EXPORT_SYMBOL(of_set_property);
  82. int of_find_in_proplist(const char *list, const char *match, int len)
  83. {
  84. while (len > 0) {
  85. int l;
  86. if (!strcmp(list, match))
  87. return 1;
  88. l = strlen(list) + 1;
  89. list += l;
  90. len -= l;
  91. }
  92. return 0;
  93. }
  94. EXPORT_SYMBOL(of_find_in_proplist);
  95. unsigned int prom_early_allocated __initdata;
  96. #include "../../../drivers/of/pdt.c"