blob: 0cff17d48c088be9d0309f9de53d0cfc95243274 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2018 MediaTek Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24/**
25 * @file mtk_wrapper.h
26 * @brief Header file of LK 2.0 wrapper for post-init
27 *
28 * LK 2.0 wrapper includes interface functions, which provides software
29 * environment functions. Several interfaces, virtual/physical address
30 * translation, muxtex/semaphore and debug are provided to execute the
31 * corresponding system calls.
32 */
33
34#pragma once
35
36#include <stddef.h>
37#include <stdint.h>
38#include <kernel/mutex.h>
39#include <kernel/semaphore.h>
40#include <kernel/vm.h>
41#include <debug.h>
42#include <platform.h>
43
44#ifndef __REG_H
45/* low level macros for accessing memory mapped hardware registers */
46#define REG64(addr) ((volatile uint64_t *)(uintptr_t)(addr))
47#define REG32(addr) ((volatile uint32_t *)(uintptr_t)(addr))
48#define REG16(addr) ((volatile uint16_t *)(uintptr_t)(addr))
49#define REG8(addr) ((volatile uint8_t *)(uintptr_t)(addr))
50
51#define RMWREG64(addr, startbit, width, val) *REG64(addr) = (*REG64(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))
52#define RMWREG32(addr, startbit, width, val) *REG32(addr) = (*REG32(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))
53#define RMWREG16(addr, startbit, width, val) *REG16(addr) = (*REG16(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))
54#define RMWREG8(addr, startbit, width, val) *REG8(addr) = (*REG8(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))
55
56#define writel(v, a) (*REG32(a) = (v))
57#define readl(a) (*REG32(a))
58#define writeb(v, a) (*REG8(a) = (v))
59#define readb(a) (*REG8(a))
60#endif
61
62#ifndef __DEBUG_H
63#if !defined(LK_DEBUGLEVEL)
64#define LK_DEBUGLEVEL 0
65#endif
66
67/* debug levels */
68#define CRITICAL 0
69#define ALWAYS 0
70#define INFO 1
71#define SPEW 2
72
73#define dprintf(level, x...) do { if ((level) <= LK_DEBUGLEVEL) { _dprintf(x); } } while (0)
74#endif
75
76enum wrap_handler_return {
77 WRAP_INT_NO_RESCHEDULE = 0,
78 WRAP_INT_RESCHEDULE,
79};
80
81typedef mutex_t wrap_mutex;
82typedef semaphore_t wrap_sem;
83typedef enum wrap_handler_return (*wrap_int_handler)(void *arg);
84
85//mutex interface functions
86void plat_wrap_mutex_init(wrap_mutex *m);
87void plat_wrap_mutex_destroy(wrap_mutex *m);
88status_t plat_wrap_mutex_acquire_timeout(wrap_mutex *m, uint32_t timeout);
89status_t plat_wrap_mutex_acquire(wrap_mutex *m);
90status_t plat_wrap_mutex_release(wrap_mutex *m);
91//semaphore interface functions
92void plat_wrap_sem_init(wrap_sem *sem, unsigned int value);
93void plat_wrap_sem_destroy(wrap_sem *sem);
94int plat_wrap_sem_post(wrap_sem *sem);
95status_t plat_wrap_sem_wait(wrap_sem *sem);
96status_t plat_wrap_sem_trywait(wrap_sem *sem);
97status_t plat_wrap_sem_timedwait(wrap_sem *sem, uint32_t timeout);
98//virtual/physical address translation function
99void *plat_wrap_paddr_to_kvaddr(unsigned long pa);
100unsigned long plat_wrap_kvaddr_to_paddr(void *ptr);
101//system delay function
102void plat_wrap_delay(uint32_t usecs);
103//interrupt function
104void plat_wrap_register_int_handler(unsigned int vector, wrap_int_handler handler, void *arg);
105int plat_wrap_unmask_interrupt(unsigned int vector);
106int plat_wrap_mask_interrupt(unsigned int vector);
107void plat_wrap_irq_set_polarity(unsigned int vector, unsigned int polarity);
108void plat_wrap_irq_set_sensitive(unsigned int vector, unsigned int sens);