commit 1727c1665035a6db823eda3ca69377564f606bd9
parent b71df54443deaa7d24ba9768d3535cf55f90befd
Author: Roberto Vargas <roberto.vargas@arm.com>
Date: Fri, 8 Mar 2019 10:34:41 +0000
[dev] Simplify devuart
Using a counter makes the phy assignation simpler
Change-Id: I1535a724bbe8ba4d942618c39fe1415197fba87a
Diffstat:
1 file changed, 9 insertions(+), 22 deletions(-)
diff --git a/drivers/devuart.c b/drivers/devuart.c
@@ -23,6 +23,7 @@ static const Dirtab dirtab[] = {
};
static Uart *uarts[NR_UARTS];
+static int nuarts;
static int
uartwalk(Chan *c, const char *name)
@@ -206,25 +207,6 @@ uartwrite(Chan *c, void *buf, int n)
}
}
-static Uart *
-uartphy(Uartphy *phy)
-{
- size_t siz;
- Uart *up;
- int i;
-
- siz = sizeof(Uart);
- up = memset(alloc(siz), 0, siz);
- up->phy = phy;
-
- for (i = 0; i < NR_UARTS && uarts[i] ; i++)
- ;
- if (i == NR_UARTS)
- panic("uartphy");
-
- return uarts[i] = up;
-}
-
void
uartlink(Uartphy *phy, Attr *attr)
{
@@ -233,8 +215,13 @@ uartlink(Uartphy *phy, Attr *attr)
Attr *a;
char *cfg = NULL;
- up = uartphy(phy);
- /* init up->mutex */
+ if (nuarts == NR_UARTS)
+ panic("uartlink1");
+
+ siz = sizeof(Uart);
+ up = memset(alloc(siz), 0, siz);
+ up->phy = phy;
+ uarts[nuarts++] = up;
for (a = attr; a->key; a++) {
if (!strcmp(a->key, "base"))
@@ -251,7 +238,7 @@ uartlink(Uartphy *phy, Attr *attr)
siz = strlen(cfg);
if (uartctl(up, cfg, siz) != siz)
- panic("uartlink");
+ panic("uartlink2");
}
const Dev uartdevtab = {