Landfall

pkg/landfall-examples/qi_lb60_keypad/memory.c

270:bde5d7799e65
8 months ago Paul Boddie Added support for shadow GPIO (PZ) registers. cpm-library-improvements
     1 /*     2  * Memory allocation utility functions.     3  *     4  * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>     5  *     6  * This program is free software; you can redistribute it and/or     7  * modify it under the terms of the GNU General Public License as     8  * published by the Free Software Foundation; either version 2 of     9  * the License, or (at your option) any later version.    10  *    11  * This program is distributed in the hope that it will be useful,    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    14  * GNU General Public License for more details.    15  *    16  * You should have received a copy of the GNU General Public License    17  * along with this program; if not, write to the Free Software    18  * Foundation, Inc., 51 Franklin Street, Fifth Floor,    19  * Boston, MA  02110-1301, USA    20  */    21     22 #include <l4/io/io.h>    23 #include <l4/re/env.h>    24 #include <l4/re/c/mem_alloc.h>    25 #include <l4/re/c/util/cap_alloc.h>    26 #include <l4/util/util.h>    27 #include <l4/vbus/vbus.h>    28     29 #include "memory.h"    30     31 int get_device(char const *hid, l4io_device_handle_t *dh, l4io_resource_handle_t *rh)    32 {    33   return l4io_lookup_device(hid, dh, 0, rh);    34 }    35     36 int get_resource(l4io_device_handle_t dh, l4io_resource_t *res,    37                              enum l4io_resource_types_t type)    38 {    39   int current = 0, result = 0;    40   l4_cap_idx_t vbus = l4re_env_get_cap("vbus");    41     42   do    43   {    44     result = l4vbus_get_resource(vbus, dh, current, res);    45     current++;    46   }    47   while ((!result) && (res->type != type));    48     49   return result;    50 }    51     52 int get_memory(char const *hid, l4_addr_t *start, l4_addr_t *end)    53 {    54   l4io_device_handle_t dh;    55   l4io_resource_handle_t rh;    56   l4io_resource_t res;    57   int result;    58     59   result = get_device(hid, &dh, &rh);    60     61   if (result < 0)    62     return result;    63     64   result = get_resource(dh, &res, L4IO_RESOURCE_MEM);    65     66   if (result)    67     return result;    68     69   result = l4io_request_iomem(res.start, res.end - res.start + 1,    70                               L4IO_MEM_NONCACHED, start);    71     72   if (result)    73     return result;    74     75   *end = *start + (res.end - res.start + 1);    76     77   return 0;    78 }