WHENCE: Update licensing information about the a56 assembler given the GPLed patches...
[linux-libre-firmware.git] / ath9k_htc / target_firmware / magpie_fw_dev / target / inc / k2 / athos_api.h
1 /*
2  * Copyright (c) 2013 Qualcomm Atheros, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted (subject to the limitations in the
7  * disclaimer below) provided that the following conditions are met:
8  *
9  *  * Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  *  * Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the
15  *    distribution.
16  *
17  *  * Neither the name of Qualcomm Atheros nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22  * GRANTED BY THIS LICENSE.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 #ifndef __ATHOS_API_H__
36 #define __ATHOS_API_H__
37
38 /*
39  * This file contains wrappers to OS operating system functions
40  * that are available in the Athos version of the operating system.
41  *
42  * Target software must always use these wrappers to access OS
43  * services -- it may not access any OS services directly.
44  *
45  * These wrappers are intended to provide OS-independence for applications.
46  * Using this header file, an application should be able to compile and
47  * fully link without any other OS header files, source files, or
48  * binary files.
49  */
50
51 #include <osapi.h>
52 #include "dt_defs.h"
53 #include "cmnos_api.h"
54 #include "Magpie_api.h"
55
56 /* ROM Patch API */
57
58 /* save the ROM printf function point */
59 extern int (* save_cmnos_printf)(const char * fmt, ...);
60
61 extern unsigned int _data_start_in_rom;
62 extern unsigned int _data_start;
63 extern unsigned int _data_end;
64 extern unsigned int _bss_start;
65 extern unsigned int _bss_end;
66 extern unsigned int _stack_sentry;
67 extern unsigned int __stack;
68 extern unsigned int _fw_image_end;
69
70 #if defined(__XTENSA__)
71 #define START_DATA      _data_start
72 #define END_DATA        _data_end
73 #define START_BSS       _bss_start
74 #define END_BSS         _bss_end
75
76 #define STACK_START  _stack_sentry
77 #define STACK_END    __stack
78 #endif
79
80 struct _A_os_linkage_check {
81         int version;
82         int table;
83 };
84
85 /* 
86  * A_INIT() handles any initialization needed by the OS abstraction,
87  * and it clears the application's BSS, if necessary.  (Application BSS
88  * is not cleared if the application is linked into a single image that
89  * includes AthOS.)
90  *
91  * A_INIT() must be called first thing in the application (from app_start)
92  * in order to guarantee that BSS has been cleared properly.
93  */
94 static INLINE int
95 A_INIT(void)
96 {
97         struct _A_os_linkage_check link_check;
98         unsigned int *clrptr;
99     
100         if (&START_BSS != _A_MAGPIE_INDIRECTION_TABLE->cmnos.start_bss) {
101                 /* Clear BSS */
102                 for (clrptr = &START_BSS; clrptr < &END_BSS; clrptr++) {
103                         *clrptr = 0;
104                 }
105         }
106
107         /* Copy writable data from flash to RAM.  */
108         unsigned int *srcptr, *destptr;
109
110         /*
111          * The _data_start symbol points to the start of data IN FLASH.
112          * It is defined by flash.ld at application link time.  If flash.ld
113          * is not used, it is defined (on the link line) as 0.
114          */
115         static int *data_start_addr = &_data_start;
116
117         if (data_start_addr != 0) {
118                 for (srcptr = &_data_start, destptr = &START_DATA;
119                      destptr < &END_DATA;
120                      srcptr++, destptr++) {
121                         *destptr = *srcptr;
122                 }
123         }
124
125 #define OS_LINKAGE_VERSION 4
126         link_check.version = OS_LINKAGE_VERSION;
127         link_check.table = _A_MAGPIE_INDIRECTION_TABLE_SIZE;
128
129         return A_CMN(hal_linkage_check(sizeof(link_check), &link_check));
130 }
131
132 #endif /* __ATHOS_API_H__ */
133