pcdp.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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/acpi.h>
  14. #include <linux/console.h>
  15. #include <linux/efi.h>
  16. #include <linux/serial.h>
  17. #include <linux/serial_8250.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.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY);
  28. p += sprintf(p, "uart8250,%s,0x%llx",
  29. mmio ? "mmio" : "io", uart->addr.address);
  30. if (uart->baud) {
  31. p += sprintf(p, ",%llu", 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. add_preferred_console("uart", 8250, &options[9]);
  42. return setup_early_serial8250_console(options);
  43. #else
  44. return -ENODEV;
  45. #endif
  46. }
  47. static int __init
  48. setup_vga_console(struct pcdp_device *dev)
  49. {
  50. #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
  51. u8 *if_ptr;
  52. if_ptr = ((u8 *)dev + sizeof(struct pcdp_device));
  53. if (if_ptr[0] == PCDP_IF_PCI) {
  54. struct pcdp_if_pci if_pci;
  55. /* struct copy since ifptr might not be correctly aligned */
  56. memcpy(&if_pci, if_ptr, sizeof(if_pci));
  57. if (if_pci.trans & PCDP_PCI_TRANS_IOPORT)
  58. vga_console_iobase = if_pci.ioport_tra;
  59. if (if_pci.trans & PCDP_PCI_TRANS_MMIO)
  60. vga_console_membase = if_pci.mmio_tra;
  61. }
  62. if (efi_mem_type(vga_console_membase + 0xA0000) == EFI_CONVENTIONAL_MEMORY) {
  63. printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n");
  64. return -ENODEV;
  65. }
  66. conswitchp = &vga_con;
  67. printk(KERN_INFO "PCDP: VGA console\n");
  68. return 0;
  69. #else
  70. return -ENODEV;
  71. #endif
  72. }
  73. int __init
  74. efi_setup_pcdp_console(char *cmdline)
  75. {
  76. struct pcdp *pcdp;
  77. struct pcdp_uart *uart;
  78. struct pcdp_device *dev, *end;
  79. int i, serial = 0;
  80. int rc = -ENODEV;
  81. if (efi.hcdp == EFI_INVALID_TABLE_ADDR)
  82. return -ENODEV;
  83. pcdp = ioremap(efi.hcdp, 4096);
  84. printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, efi.hcdp);
  85. if (strstr(cmdline, "console=hcdp")) {
  86. if (pcdp->rev < 3)
  87. serial = 1;
  88. } else if (strstr(cmdline, "console=")) {
  89. printk(KERN_INFO "Explicit \"console=\"; ignoring PCDP\n");
  90. goto out;
  91. }
  92. if (pcdp->rev < 3 && efi_uart_console_only())
  93. serial = 1;
  94. for (i = 0, uart = pcdp->uart; i < pcdp->num_uarts; i++, uart++) {
  95. if (uart->flags & PCDP_UART_PRIMARY_CONSOLE || serial) {
  96. if (uart->type == PCDP_CONSOLE_UART) {
  97. rc = setup_serial_console(uart);
  98. goto out;
  99. }
  100. }
  101. }
  102. end = (struct pcdp_device *) ((u8 *) pcdp + pcdp->length);
  103. for (dev = (struct pcdp_device *) (pcdp->uart + pcdp->num_uarts);
  104. dev < end;
  105. dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) {
  106. if (dev->flags & PCDP_PRIMARY_CONSOLE) {
  107. if (dev->type == PCDP_CONSOLE_VGA) {
  108. rc = setup_vga_console(dev);
  109. goto out;
  110. }
  111. }
  112. }
  113. out:
  114. iounmap(pcdp);
  115. return rc;
  116. }