pcdp.c 3.2 KB

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