Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

x86_uart.c 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. /** @file
  25. *
  26. * 16550-compatible UART
  27. *
  28. */
  29. #include <errno.h>
  30. #include <ipxe/uart.h>
  31. /** UART port bases */
  32. static uint16_t uart_base[] = {
  33. [COM1] = 0x3f8,
  34. [COM2] = 0x2f8,
  35. [COM3] = 0x3e8,
  36. [COM4] = 0x2e8,
  37. };
  38. /**
  39. * Select UART port
  40. *
  41. * @v uart UART
  42. * @v port Port number, or 0 to disable
  43. * @ret rc Return status code
  44. */
  45. int uart_select ( struct uart *uart, unsigned int port ) {
  46. int rc;
  47. /* Set new UART base */
  48. if ( port >= ( sizeof ( uart_base ) / sizeof ( uart_base[0] ) ) ) {
  49. rc = -ENODEV;
  50. goto err;
  51. }
  52. uart->base = ( ( void * ) ( intptr_t ) uart_base[port] );
  53. /* Check that UART exists */
  54. if ( ( rc = uart_exists ( uart ) ) != 0 )
  55. goto err;
  56. return 0;
  57. err:
  58. uart->base = NULL;
  59. return rc;
  60. }