1 /*
2  * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef TS_PLATFORM_INTERFACE_UART_H
8 #define TS_PLATFORM_INTERFACE_UART_H
9 
10 /*
11  * Interface definintion for a platform uart driver.  A platform provider will
12  * provide concrete implementations of this interface for each alternative
13  * implementation supported.
14  */
15 #include <stddef.h>
16 
17 #include "device_region.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /*
24  * A platform uart driver context.
25  */
26 typedef struct {
27 	/* Base address of the driver instance */
28 	uintptr_t base_address;
29 } platform_uart_context;
30 
31 /*
32  * Virtual interface for a platform uart driver.  A platform will provide
33  * one or more concrete implementations of this interface.
34  */
35 struct platform_uart_iface {
36 	/**
37 	 * \brief Putc to submit a character to platform uart
38 	 * *
39 	 * * \param context     Platform driver context
40 	 * \param ch	         Character to be written to UART
41 	 *
42 	 * \return            0 if successful.
43 	 */
44 	int (*uart_putc)(platform_uart_context *context, uint8_t ch);
45 	/**
46 	 * \brief Wait for empty input FIFO in platform uart
47 	 *
48 	 * * \param context     Platform driver context
49 	 * *
50 	 * \return            0 if successful.
51 	 */
52 	int (*uart_flush)(platform_uart_context *context);
53 };
54 
55 /*
56  * A platform uart driver instance.
57  */
58 struct platform_uart_driver {
59 	void *context; /**< Opaque driver context */
60 	const struct platform_uart_iface *iface; /**< Interface methods */
61 };
62 
63 /**
64  * \brief Factory method to construct a platform specific uart driver
65  *
66  * \param driver    Pointer to driver structure to initialize on construction.
67  * \param instance    Deployment specific uart instance.
68  *
69  * \return          0 if successful.
70  */
71 int platform_uart_create(struct platform_uart_driver *driver, int instance);
72 
73 /**
74  * \brief Destroy a driver constructed using the factory method
75  *
76  * \param driver    Pointer to driver structure for constructed driver.
77  */
78 void platform_uart_destroy(struct platform_uart_driver *driver);
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif /* TS_PLATFORM_INTERFACE_UART_H */
85