92 lines
2.8 KiB
C
92 lines
2.8 KiB
C
/*
|
|
* VAS_EBOOT -- GRand Unified Bootloader
|
|
* Copyright (C) 2023 Free Software Foundation, Inc.
|
|
*
|
|
* VAS_EBOOT is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* VAS_EBOOT is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with VAS_EBOOT. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <VasEBoot/serial.h>
|
|
#include <VasEBoot/term.h>
|
|
#include <VasEBoot/types.h>
|
|
#include <VasEBoot/pci.h>
|
|
#include <VasEBoot/mm.h>
|
|
#include <VasEBoot/misc.h>
|
|
|
|
static int
|
|
find_pciserial (VasEBoot_pci_device_t dev, VasEBoot_pci_id_t pciid __attribute__ ((unused)), void *data __attribute__ ((unused)))
|
|
{
|
|
VasEBoot_pci_address_t cmd_addr, class_addr, bar_addr;
|
|
struct VasEBoot_serial_port *port;
|
|
VasEBoot_uint32_t class, bar;
|
|
VasEBoot_uint16_t cmdreg;
|
|
VasEBoot_err_t err;
|
|
|
|
cmd_addr = VasEBoot_pci_make_address (dev, VAS_EBOOT_PCI_REG_COMMAND);
|
|
cmdreg = VasEBoot_pci_read (cmd_addr);
|
|
|
|
class_addr = VasEBoot_pci_make_address (dev, VAS_EBOOT_PCI_REG_REVISION);
|
|
class = VasEBoot_pci_read (class_addr);
|
|
|
|
bar_addr = VasEBoot_pci_make_address (dev, VAS_EBOOT_PCI_REG_ADDRESS_REG0);
|
|
bar = VasEBoot_pci_read (bar_addr);
|
|
|
|
/* 16550 compatible MODEM or SERIAL. */
|
|
if (((class >> 16) != VAS_EBOOT_PCI_CLASS_COMMUNICATION_MODEM &&
|
|
(class >> 16) != VAS_EBOOT_PCI_CLASS_COMMUNICATION_SERIAL) ||
|
|
((class >> 8) & 0xff) != VAS_EBOOT_PCI_SERIAL_16550_COMPATIBLE)
|
|
return 0;
|
|
|
|
if ((bar & VAS_EBOOT_PCI_ADDR_SPACE_MASK) != VAS_EBOOT_PCI_ADDR_SPACE_IO)
|
|
return 0;
|
|
|
|
port = VasEBoot_zalloc (sizeof (*port));
|
|
if (port == NULL)
|
|
return 0;
|
|
|
|
port->name = VasEBoot_xasprintf ("pci,%02x:%02x.%x",
|
|
VasEBoot_pci_get_bus (dev),
|
|
VasEBoot_pci_get_device (dev),
|
|
VasEBoot_pci_get_function (dev));
|
|
if (port->name == NULL)
|
|
goto fail;
|
|
|
|
VasEBoot_pci_write (cmd_addr, cmdreg | VAS_EBOOT_PCI_COMMAND_IO_ENABLED);
|
|
|
|
port->driver = &VasEBoot_ns8250_driver;
|
|
port->port = bar & VAS_EBOOT_PCI_ADDR_IO_MASK;
|
|
err = VasEBoot_serial_config_defaults (port);
|
|
if (err != VAS_EBOOT_ERR_NONE)
|
|
{
|
|
VasEBoot_print_error ();
|
|
goto fail;
|
|
}
|
|
|
|
err = VasEBoot_serial_register (port);
|
|
if (err != VAS_EBOOT_ERR_NONE)
|
|
goto fail;
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
VasEBoot_free (port->name);
|
|
VasEBoot_free (port);
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
VasEBoot_pciserial_init (void)
|
|
{
|
|
VasEBoot_pci_iterate (find_pciserial, NULL);
|
|
}
|