prom.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 * __init prom_getcmdline(void)
  28. {
  29. return &(arcs_cmdline[0]);
  30. }
  31. void __init prom_init_cmdline(void)
  32. {
  33. int i;
  34. arcs_cmdline[0] = '\0';
  35. for (i = 0; i < prom_argc; i++) {
  36. strcat(arcs_cmdline, prom_argv[i]);
  37. strcat(arcs_cmdline, " ");
  38. }
  39. }
  40. char *prom_getenv(char *envname)
  41. {
  42. /*
  43. * Return a pointer to the given environment variable.
  44. * Environment variables are stored in the form of "memsize=64".
  45. */
  46. t_env_var *env = (t_env_var *)prom_envp;
  47. int i;
  48. i = strlen(envname);
  49. while(env->name) {
  50. if(strncmp(envname, env->name, i) == 0) {
  51. return(env->name + strlen(envname) + 1);
  52. }
  53. env++;
  54. }
  55. return(NULL);
  56. }
  57. inline unsigned char str2hexnum(unsigned char c)
  58. {
  59. if(c >= '0' && c <= '9')
  60. return c - '0';
  61. if(c >= 'a' && c <= 'f')
  62. return c - 'a' + 10;
  63. if(c >= 'A' && c <= 'F')
  64. return c - 'A' + 10;
  65. return 0; /* foo */
  66. }
  67. inline void str2eaddr(unsigned char *ea, unsigned char *str)
  68. {
  69. int i;
  70. for(i = 0; i < 6; i++) {
  71. unsigned char num;
  72. if((*str == '.') || (*str == ':'))
  73. str++;
  74. num = str2hexnum(*str++) << 4;
  75. num |= (str2hexnum(*str++));
  76. ea[i] = num;
  77. }
  78. }
  79. int get_ethernet_addr(char *ethernet_addr)
  80. {
  81. char *ethaddr_str;
  82. ethaddr_str = prom_getenv("ethaddr");
  83. if (!ethaddr_str) {
  84. printk("ethaddr not set in boot prom\n");
  85. return -1;
  86. }
  87. str2eaddr(ethernet_addr, ethaddr_str);
  88. return 0;
  89. }
  90. void __init prom_free_prom_memory(void)
  91. {
  92. }
  93. extern int pnx8550_console_port;
  94. /* used by early printk */
  95. void prom_putchar(char c)
  96. {
  97. if (pnx8550_console_port != -1) {
  98. /* Wait until FIFO not full */
  99. while( ((ip3106_fifo(UART_BASE, pnx8550_console_port) & PNX8XXX_UART_FIFO_TXFIFO) >> 16) >= 16)
  100. ;
  101. /* Send one char */
  102. ip3106_fifo(UART_BASE, pnx8550_console_port) = c;
  103. }
  104. }
  105. EXPORT_SYMBOL(get_ethernet_addr);
  106. EXPORT_SYMBOL(str2eaddr);