Skip to content

Commit

Permalink
x86, galileo: Fix UART system call authorization initialization
Browse files Browse the repository at this point in the history
This patch fixes UART system call authorization initialization (when
protection domain support is enabled) to only initialize the system call
entrypoint and authorization data structures once, prior to per-port
setup. Previously, if two UARTs were configured, the setup procedure for
the second UART would erase the system call authorization for the
first (console) UART, resulting in a crash upon the next attempt to
perform console output.
  • Loading branch information
Michael LeMay committed Aug 4, 2016
1 parent 31ad67a commit bde8eb3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
20 changes: 15 additions & 5 deletions cpu/x86/drivers/legacy_pc/uart-16x50.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,36 @@ SYSCALLS_DEFINE(uart_16x50_tx, uart_16x50_driver_t c_this, uint8_t c)
prot_domains_disable_mmio();
}
/*---------------------------------------------------------------------------*/
/**
* \brief Perform common initialization that must precede per-port
* initialization.
*/
/*---------------------------------------------------------------------------*/
void
uart_16x50_init(void)
{
SYSCALLS_INIT(uart_16x50_setup);
SYSCALLS_INIT(uart_16x50_tx);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Initialize an MMIO-programmable 16X50 UART.
* \param c_this Structure that will be initialized to represent the device.
* \param pci_addr PCI address of device.
* \param dl Divisor setting to configure the baud rate.
*/
void
uart_16x50_init(uart_16x50_driver_t ATTR_KERN_ADDR_SPACE *c_this,
pci_config_addr_t pci_addr,
uint16_t dl)
uart_16x50_init_port(uart_16x50_driver_t ATTR_KERN_ADDR_SPACE *c_this,
pci_config_addr_t pci_addr,
uint16_t dl)
{
uart_16x50_driver_t loc_c_this;

/* This assumes that the UART had an MMIO range assigned to it by the
* firmware during boot.
*/
pci_init(c_this, pci_addr, UART_MMIO_SZ, 0, 0);
SYSCALLS_INIT(uart_16x50_setup);
SYSCALLS_AUTHZ(uart_16x50_setup, *c_this);
SYSCALLS_INIT(uart_16x50_tx);
SYSCALLS_AUTHZ(uart_16x50_tx, *c_this);

prot_domains_copy_dcd(&loc_c_this, c_this);
Expand Down
8 changes: 5 additions & 3 deletions cpu/x86/drivers/legacy_pc/uart-16x50.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@

typedef pci_driver_t uart_16x50_driver_t;

void uart_16x50_init(uart_16x50_driver_t ATTR_KERN_ADDR_SPACE *c_this,
pci_config_addr_t pci_addr,
uint16_t dl);
void uart_16x50_init(void);

void uart_16x50_init_port(uart_16x50_driver_t ATTR_KERN_ADDR_SPACE *c_this,
pci_config_addr_t pci_addr,
uint16_t dl);

void uart_16x50_tx(uart_16x50_driver_t c_this, uint8_t c);

Expand Down
14 changes: 12 additions & 2 deletions cpu/x86/drivers/quarkX1000/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,23 @@ PROT_DOMAINS_ALLOC(uart_16x50_driver_t, quarkX1000_uart1);
*/
#define QUARK_X1000_UART_FBASE 44236800

/*---------------------------------------------------------------------------*/
/**
* \brief Perform common initialization that must precede per-port
* initialization.
*/
void
quarkX1000_uart_init(void)
{
uart_16x50_init();
}
/*---------------------------------------------------------------------------*/
/**
* \brief Initialize a UART.
* \param dev Device to initialize.
*/
void
quarkX1000_uart_init(quarkX1000_uart_dev_t dev, unsigned baud)
quarkX1000_uart_init_port(quarkX1000_uart_dev_t dev, unsigned baud)
{
uint16_t dl;
pci_config_addr_t pci_addr;
Expand All @@ -70,7 +80,7 @@ quarkX1000_uart_init(quarkX1000_uart_dev_t dev, unsigned baud)
}
/* Divisor setting from section 18.2.2 of Intel Quark SoC X1000 Datasheet. */
dl = QUARK_X1000_UART_FBASE / (16 * baud);
uart_16x50_init(drv, pci_addr, dl);
uart_16x50_init_port(drv, pci_addr, dl);
}
/*---------------------------------------------------------------------------*/
/**
Expand Down
3 changes: 2 additions & 1 deletion cpu/x86/drivers/quarkX1000/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ typedef enum {
QUARK_X1000_UART_1
} quarkX1000_uart_dev_t;

void quarkX1000_uart_init(quarkX1000_uart_dev_t dev, unsigned baud);
void quarkX1000_uart_init(void);
void quarkX1000_uart_init_port(quarkX1000_uart_dev_t dev, unsigned baud);
void quarkX1000_uart_tx(quarkX1000_uart_dev_t dev, uint8_t c);

#endif /* CPU_X86_DRIVERS_QUARKX1000_UART_H_ */
3 changes: 2 additions & 1 deletion platform/galileo/contiki-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ main(void)
quarkX1000_imr_conf();
#endif
irq_init();
quarkX1000_uart_init();
/* Initialize UART connected to Galileo Gen1 3.5mm audio-style jack or
* Galileo Gen2 FTDI header
*/
quarkX1000_uart_init(QUARK_X1000_UART_1, 115200);
quarkX1000_uart_init_port(QUARK_X1000_UART_1, 115200);
clock_init();
rtimer_init();

Expand Down

0 comments on commit bde8eb3

Please sign in to comment.