pcdp.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. mmio = (uart->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY);
  27. p += sprintf(p, "console=uart,%s,0x%lx",
  28. mmio ? "mmio" : "io", uart->addr.address);
  29. if (uart->baud)
  30. p += sprintf(p, ",%lu", uart->baud);
  31. if (uart->bits)
  32. p += sprintf(p, "n%d", uart->bits);
  33. return early_serial_console_init(options);
  34. #else
  35. return -ENODEV;
  36. #endif
  37. }
  38. static int __init
  39. setup_vga_console(struct pcdp_device *dev)
  40. {
  41. #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
  42. u8 *if_ptr;
  43. if_ptr = ((u8 *)dev + sizeof(struct pcdp_device));
  44. if (if_ptr[0] == PCDP_IF_PCI) {
  45. struct pcdp_if_pci if_pci;
  46. /* struct copy since ifptr might not be correctly aligned */
  47. memcpy(&if_pci, if_ptr, sizeof(if_pci));
  48. if (if_pci.trans & PCDP_PCI_TRANS_IOPORT)
  49. vga_console_iobase = if_pci.ioport_tra;
  50. if (if_pci.trans & PCDP_PCI_TRANS_MMIO)
  51. vga_console_membase = if_pci.mmio_tra;
  52. }
  53. if (efi_mem_type(vga_console_membase + 0xA0000) == EFI_CONVENTIONAL_MEMORY) {
  54. printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n");
  55. return -ENODEV;
  56. }
  57. conswitchp = &vga_con;
  58. printk(KERN_INFO "PCDP: VGA console\n");
  59. return 0;
  60. #else
  61. return -ENODEV;
  62. #endif
  63. }
  64. int __init
  65. efi_setup_pcdp_console(char *cmdline)
  66. {
  67. struct pcdp *pcdp;
  68. struct pcdp_uart *uart;
  69. struct pcdp_device *dev, *end;
  70. int i, serial = 0;
  71. pcdp = efi.hcdp;
  72. if (!pcdp)
  73. return -ENODEV;
  74. printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, __pa(pcdp));
  75. if (strstr(cmdline, "console=hcdp")) {
  76. if (pcdp->rev < 3)
  77. serial = 1;
  78. } else if (strstr(cmdline, "console=")) {
  79. printk(KERN_INFO "Explicit \"console=\"; ignoring PCDP\n");
  80. return -ENODEV;
  81. }
  82. if (pcdp->rev < 3 && efi_uart_console_only())
  83. serial = 1;
  84. for (i = 0, uart = pcdp->uart; i < pcdp->num_uarts; i++, uart++) {
  85. if (uart->flags & PCDP_UART_PRIMARY_CONSOLE || serial) {
  86. if (uart->type == PCDP_CONSOLE_UART) {
  87. return setup_serial_console(uart);
  88. }
  89. }
  90. }
  91. end = (struct pcdp_device *) ((u8 *) pcdp + pcdp->length);
  92. for (dev = (struct pcdp_device *) (pcdp->uart + pcdp->num_uarts);
  93. dev < end;
  94. dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) {
  95. if (dev->flags & PCDP_PRIMARY_CONSOLE) {
  96. if (dev->type == PCDP_CONSOLE_VGA) {
  97. return setup_vga_console(dev);
  98. }
  99. }
  100. }
  101. return -ENODEV;
  102. }