prom.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. *
  3. * Per Hallsmark, per.hallsmark@mvista.com
  4. *
  5. * Based on jmr3927/common/prom.c
  6. *
  7. * 2004 (c) MontaVista Software, Inc. This file is licensed under the
  8. * terms of the GNU General Public License version 2. This program is
  9. * licensed "as is" without any warranty of any kind, whether express
  10. * or implied.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/string.h>
  16. #include <linux/serial_pnx8xxx.h>
  17. #include <asm/bootinfo.h>
  18. #include <uart.h>
  19. /* #define DEBUG_CMDLINE */
  20. extern int prom_argc;
  21. extern char **prom_argv, **prom_envp;
  22. typedef struct
  23. {
  24. char *name;
  25. /* char *val; */
  26. }t_env_var;
  27. char * prom_getcmdline(void)
  28. {
  29. return &(arcs_cmdline[0]);
  30. }
  31. void prom_init_cmdline(void)
  32. {
  33. char *cp;
  34. int actr;
  35. actr = 1; /* Always ignore argv[0] */
  36. cp = &(arcs_cmdline[0]);
  37. while(actr < prom_argc) {
  38. strcpy(cp, prom_argv[actr]);
  39. cp += strlen(prom_argv[actr]);
  40. *cp++ = ' ';
  41. actr++;
  42. }
  43. if (cp != &(arcs_cmdline[0])) /* get rid of trailing space */
  44. --cp;
  45. *cp = '\0';
  46. }
  47. char *prom_getenv(char *envname)
  48. {
  49. /*
  50. * Return a pointer to the given environment variable.
  51. * Environment variables are stored in the form of "memsize=64".
  52. */
  53. t_env_var *env = (t_env_var *)prom_envp;
  54. int i;
  55. i = strlen(envname);
  56. while(env->name) {
  57. if(strncmp(envname, env->name, i) == 0) {
  58. return(env->name + strlen(envname) + 1);
  59. }
  60. env++;
  61. }
  62. return(NULL);
  63. }
  64. inline unsigned char str2hexnum(unsigned char c)
  65. {
  66. if(c >= '0' && c <= '9')
  67. return c - '0';
  68. if(c >= 'a' && c <= 'f')
  69. return c - 'a' + 10;
  70. if(c >= 'A' && c <= 'F')
  71. return c - 'A' + 10;
  72. return 0; /* foo */
  73. }
  74. inline void str2eaddr(unsigned char *ea, unsigned char *str)
  75. {
  76. int i;
  77. for(i = 0; i < 6; i++) {
  78. unsigned char num;
  79. if((*str == '.') || (*str == ':'))
  80. str++;
  81. num = str2hexnum(*str++) << 4;
  82. num |= (str2hexnum(*str++));
  83. ea[i] = num;
  84. }
  85. }
  86. int get_ethernet_addr(char *ethernet_addr)
  87. {
  88. char *ethaddr_str;
  89. ethaddr_str = prom_getenv("ethaddr");
  90. if (!ethaddr_str) {
  91. printk("ethaddr not set in boot prom\n");
  92. return -1;
  93. }
  94. str2eaddr(ethernet_addr, ethaddr_str);
  95. return 0;
  96. }
  97. unsigned long __init prom_free_prom_memory(void)
  98. {
  99. return 0;
  100. }
  101. extern int pnx8550_console_port;
  102. /* used by prom_printf */
  103. void prom_putchar(char c)
  104. {
  105. if (pnx8550_console_port != -1) {
  106. /* Wait until FIFO not full */
  107. while( ((ip3106_fifo(UART_BASE, pnx8550_console_port) & PNX8XXX_UART_FIFO_TXFIFO) >> 16) >= 16)
  108. ;
  109. /* Send one char */
  110. ip3106_fifo(UART_BASE, pnx8550_console_port) = c;
  111. }
  112. }
  113. EXPORT_SYMBOL(prom_getcmdline);
  114. EXPORT_SYMBOL(get_ethernet_addr);
  115. EXPORT_SYMBOL(str2eaddr);