pcdp.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 <asm/vga.h>
  18. #include "pcdp.h"
  19. static int __init
  20. setup_serial_console(struct pcdp_uart *uart)
  21. {
  22. #ifdef CONFIG_SERIAL_8250_CONSOLE
  23. int mmio;
  24. static char options[64], *p = options;
  25. char parity;
  26. mmio = (uart->addr.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. switch (uart->parity) {
  33. case 0x2: parity = 'e'; break;
  34. case 0x3: parity = 'o'; break;
  35. default: parity = 'n';
  36. }
  37. p += sprintf(p, "%c%d", parity, uart->bits);
  38. }
  39. }
  40. return early_serial_console_init(options);
  41. #else
  42. return -ENODEV;
  43. #endif
  44. }
  45. static int __init
  46. setup_vga_console(struct pcdp_device *dev)
  47. {
  48. #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
  49. u8 *if_ptr;
  50. if_ptr = ((u8 *)dev + sizeof(struct pcdp_device));
  51. if (if_ptr[0] == PCDP_IF_PCI) {
  52. struct pcdp_if_pci if_pci;
  53. /* struct copy since ifptr might not be correctly aligned */
  54. memcpy(&if_pci, if_ptr, sizeof(if_pci));
  55. if (if_pci.trans & PCDP_PCI_TRANS_IOPORT)
  56. vga_console_iobase = if_pci.ioport_tra;
  57. if (if_pci.trans & PCDP_PCI_TRANS_MMIO)
  58. vga_console_membase = if_pci.mmio_tra;
  59. }
  60. if (efi_mem_type(vga_console_membase + 0xA0000) == EFI_CONVENTIONAL_MEMORY) {
  61. printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n");
  62. return -ENODEV;
  63. }
  64. conswitchp = &vga_con;
  65. printk(KERN_INFO "PCDP: VGA console\n");
  66. return 0;
  67. #else
  68. return -ENODEV;
  69. #endif
  70. }
  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 (efi.hcdp == EFI_INVALID_TABLE_ADDR)
  80. return -ENODEV;
  81. pcdp = ioremap(efi.hcdp, 4096);
  82. printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, efi.hcdp);
  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. iounmap(pcdp);
  113. return rc;
  114. }