pcdp.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Parse the EFI PCDP table to locate the console device.
  3. *
  4. * (c) Copyright 2002, 2003, 2004 Hewlett-Packard Development Company, L.P.
  5. * Khalid Aziz <khalid.aziz@hp.com>
  6. * Alex Williamson <alex.williamson@hp.com>
  7. * Bjorn Helgaas <bjorn.helgaas@hp.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/config.h>
  14. #include <linux/acpi.h>
  15. #include <linux/console.h>
  16. #include <linux/efi.h>
  17. #include <linux/serial.h>
  18. #include <asm/vga.h>
  19. #include "pcdp.h"
  20. static int __init
  21. setup_serial_console(struct pcdp_uart *uart)
  22. {
  23. #ifdef CONFIG_SERIAL_8250_CONSOLE
  24. int mmio;
  25. static char options[64], *p = options;
  26. char parity;
  27. mmio = (uart->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY);
  28. p += sprintf(p, "console=uart,%s,0x%lx",
  29. mmio ? "mmio" : "io", uart->addr.address);
  30. if (uart->baud) {
  31. p += sprintf(p, ",%lu", uart->baud);
  32. if (uart->bits) {
  33. switch (uart->parity) {
  34. case 0x2: parity = 'e'; break;
  35. case 0x3: parity = 'o'; break;
  36. default: parity = 'n';
  37. }
  38. p += sprintf(p, "%c%d", parity, uart->bits);
  39. }
  40. }
  41. return early_serial_console_init(options);
  42. #else
  43. return -ENODEV;
  44. #endif
  45. }
  46. static int __init
  47. setup_vga_console(struct pcdp_device *dev)
  48. {
  49. #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
  50. u8 *if_ptr;
  51. if_ptr = ((u8 *)dev + sizeof(struct pcdp_device));
  52. if (if_ptr[0] == PCDP_IF_PCI) {
  53. struct pcdp_if_pci if_pci;
  54. /* struct copy since ifptr might not be correctly aligned */
  55. memcpy(&if_pci, if_ptr, sizeof(if_pci));
  56. if (if_pci.trans & PCDP_PCI_TRANS_IOPORT)
  57. vga_console_iobase = if_pci.ioport_tra;
  58. if (if_pci.trans & PCDP_PCI_TRANS_MMIO)
  59. vga_console_membase = if_pci.mmio_tra;
  60. }
  61. if (efi_mem_type(vga_console_membase + 0xA0000) == EFI_CONVENTIONAL_MEMORY) {
  62. printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n");
  63. return -ENODEV;
  64. }
  65. conswitchp = &vga_con;
  66. printk(KERN_INFO "PCDP: VGA console\n");
  67. return 0;
  68. #else
  69. return -ENODEV;
  70. #endif
  71. }
  72. int __init
  73. efi_setup_pcdp_console(char *cmdline)
  74. {
  75. struct pcdp *pcdp;
  76. struct pcdp_uart *uart;
  77. struct pcdp_device *dev, *end;
  78. int i, serial = 0;
  79. int rc = -ENODEV;
  80. if (efi.hcdp == EFI_INVALID_TABLE_ADDR)
  81. return -ENODEV;
  82. pcdp = ioremap(efi.hcdp, 4096);
  83. printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, efi.hcdp);
  84. if (strstr(cmdline, "console=hcdp")) {
  85. if (pcdp->rev < 3)
  86. serial = 1;
  87. } else if (strstr(cmdline, "console=")) {
  88. printk(KERN_INFO "Explicit \"console=\"; ignoring PCDP\n");
  89. goto out;
  90. }
  91. if (pcdp->rev < 3 && efi_uart_console_only())
  92. serial = 1;
  93. for (i = 0, uart = pcdp->uart; i < pcdp->num_uarts; i++, uart++) {
  94. if (uart->flags & PCDP_UART_PRIMARY_CONSOLE || serial) {
  95. if (uart->type == PCDP_CONSOLE_UART) {
  96. rc = setup_serial_console(uart);
  97. goto out;
  98. }
  99. }
  100. }
  101. end = (struct pcdp_device *) ((u8 *) pcdp + pcdp->length);
  102. for (dev = (struct pcdp_device *) (pcdp->uart + pcdp->num_uarts);
  103. dev < end;
  104. dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) {
  105. if (dev->flags & PCDP_PRIMARY_CONSOLE) {
  106. if (dev->type == PCDP_CONSOLE_VGA) {
  107. rc = setup_vga_console(dev);
  108. goto out;
  109. }
  110. }
  111. }
  112. out:
  113. iounmap(pcdp);
  114. return rc;
  115. }