; Copyright 2016 Castle Technology Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;     http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;

; Definitions for OS_DynamicArea, OS_Memory and other related SWIs

; OS_DynamicArea reason codes

DAReason_Create          *  0
DAReason_Remove          *  1
DAReason_GetInfo         *  2
DAReason_Enumerate       *  3
DAReason_Renumber        *  4
DAReason_ReturnFree      *  5
DAReason_GetChangeInfo   *  6   ; Internal use only (intended for TaskManager)
DAReason_EnumerateInfo   *  7   ; Internal use only (intended for TaskManager)
DAReason_SetClamps       *  8
DAReason_SparseClaim     *  9
DAReason_SparseRelease   * 10
                                ; Reasons 11-19 allocated to ROL
DAReason_LocateAddress   * 20
DAReason_PMP_PhysOp      * 21
DAReason_PMP_LogOp       * 22
DAReason_PMP_Resize      * 23
DAReason_PMP_GetInfo     * 24
DAReason_PMP_GetPages    * 25
DAReason_Limit           * 26   ;end of defined DA reasons

; Dynamic area / page flags

DynAreaFlags_APBits             * 15 :SHL:  0
DynAreaFlags_NotBufferable      *  1 :SHL:  4
DynAreaFlags_NotCacheable       *  1 :SHL:  5
DynAreaFlags_DoublyMapped       *  1 :SHL:  6
DynAreaFlags_NotUserDraggable   *  1 :SHL:  7
DynAreaFlags_NeedsSpecificPages *  1 :SHL:  8   ; whether area will ever require particular physical pages
DynAreaFlags_Shrinkable         *  1 :SHL:  9   ; whether area may be shrunk when need more space in free pool
DynAreaFlags_SparseMap          *  1 :SHL: 10   ; whether area may have non-contiguous mapping of pages (Holey dynamic areas Batman!)
DynAreaFlags_PiersBinding       *  1 :SHL: 11   ; whether area is bound to client application, and so may be swapped out with it (not implemented yet)
DynAreaFlags_CPBits             *  7 :SHL: 12   ; cache policy variant for NotBufferable and NotCacheable bits
DynAreaFlags_CPShift            *          12   ; shift amount for the above
DynAreaFlags_NeedsDMA           *  1 :SHL: 15   ; only allocate from DMAable memory
; Bits 16-19 are used by RISCOS Ltd. We can reuse them for internal flags, but
; should probably avoid allocating any public flags.
DynAreaFlags_PMP                *  1 :SHL: 20   ; DA is backed by PMP/page is member of PMP

; Cache policies
;
CP_NCNB_Default                 * 0             ; no policy variants

CP_NCB_Default                  * 0             ; OS decides buffer policy (currently always MergingIdempotent)
CP_NCB_NonMerging               * 1             ; Non-merging write buffer. If not available, unbuffered.
CP_NCB_Merging                  * 2             ; Merging write buffer. If not available, non-merging.
CP_NCB_MergingIdempotent        * 3             ; Merging write buffer with idempotent memory (i.e. VMSA "Normal" non-cacheable type). If not available, merging write buffer.

CP_CNB_Default                  * 0             ; OS decides cache policy (writethrough). NCNB if not available
CP_CNB_Writethrough             * 1             ; Writethrough cacheable, non-buffered. If not available, NCNB.
CP_CNB_Writeback                * 2             ; Writeback cacheable, non-buffered. If not available,CNB_Writethrough.

CP_CB_Default                   * 0             ; OS decides cache policy (WB if available, W alloc if HAL requests)
CP_CB_Writethrough              * 1             ; Writethrough cacheable, read allocate. If not available, NCB_Merging
CP_CB_WritebackReadAlloc        * 2             ; Writeback cacheable, read allocate. If not available, writethrough.
CP_CB_WritebackWriteAlloc       * 3             ; Writeback cacheable, write allocate. If not available, WB/R.
CP_CB_AlternativeDCache         * 4             ; Use XScale/SA11x0 mini-data cache. If not available, CB_Default. For ARMv6+, this selects inner write-through, outer write-back (write alloc).

;
; Public page flags (note - may overlap DA flags)
;
; APBits, NotBufferable, NotCacheable, DoublyMapped, CPBits and PMP are the
; DA flags which are also (public) page flags.
;
; N.B. not all public flags are writable.
;
PageFlags_Unavailable           *  1 :SHL: 15                      ; physical page has been claimed by someone for exclusive use (can't be requested by PreGrow handler or PMP PhysOp page list)


; Dynamic area handler reason codes

DAHandler_PreGrow       *       0
DAHandler_PostGrow      *       1
DAHandler_PreShrink     *       2
DAHandler_PostShrink    *       3
DAHandler_TestShrink    *       4       ; Shrinkable DAs: Find abount can shrink by
DAHandler_Abort         *       5       ; ROL abortable DAs
DAHandler_ResizePMP     *       6       ; PMP DAs: Called on OS_ChangeDynamicArea

; OS_Memory reason codes

OSMemReason_Convert                * 0  ; Convert PA <-> LA <-> PN, alter cacheability
OSMemReason_PhysSize               * 6  ; Return physical memory arrangement table info
OSMemReason_ReadPhys               * 7  ; Read physical memory arrangement table
OSMemReason_Amounts                * 8  ; Return amounts of various memory types
OSMemReason_IOSpace                * 9  ; Return controller presence/base address
OSMemReason_RecommendPage          * 12 ; Recommend contiguous pages for DA grow handler
OSMemReason_MapIOPermanent         * 13 ; Map in IO area
OSMemReason_AccessPhysAddr         * 14 ; Temporarily map in phys addr
OSMemReason_ReleasePhysAddr        * 15 ; Release the temp mapping
OSMemReason_MemoryAreaInfo         * 16 ; Return size & location of various non-DA areas
OSMemReason_MemoryAccessPrivileges * 17 ; Decode AP numbers into permission flags
OSMemReason_FindAccessPrivilege    * 18 ; Find best AP number from given permission flags
OSMemReason_Compatibility          * 20 ; Get/set compatibility settings
OSMemReason_CheckMemoryAccess      * 24 ; Return attributes/permissions for a logical address range

; OS_Memory 17/18 permission flags
MemPermission_UserX    * 1<<0 ; Executable in user mode
MemPermission_UserW    * 1<<1 ; Writable in user mode
MemPermission_UserR    * 1<<2 ; Readable in user mode
MemPermission_PrivX    * 1<<3 ; Executable in privileged modes
MemPermission_PrivW    * 1<<4 ; Writable in privileged modes
MemPermission_PrivR    * 1<<5 ; Readable in privileged modes

; OS_Memory 24 (CheckMemoryAccess) flags
CMA_Completely_UserR   * 1<<0  ; completely readable in user mode
CMA_Completely_UserW   * 1<<1  ; completely writable in user mode
CMA_Completely_PrivR   * 1<<2  ; completely readable in privileged modes
CMA_Completely_PrivW   * 1<<3  ; completely writable in privileged modes
CMA_Partially_UserR    * 1<<4  ; partially readable in user mode
CMA_Partially_UserW    * 1<<5  ; partially writable in user mode
CMA_Partially_PrivR    * 1<<6  ; partially readable in privileged modes
CMA_Partially_PrivW    * 1<<7  ; partially writable in privileged modes
CMA_Completely_Phys    * 1<<8  ; completely physically mapped (i.e. IO memory)
CMA_Completely_Abort   * 1<<9  ; completely abortable (i.e. custom data abort handler)
CMA_Completely_UserXN  * 1<<10 ; completely non-executable in user mode
CMA_Completely_PrivXN  * 1<<11 ; completely non-executable in privileged modes
CMA_Partially_Phys     * 1<<12 ; partially physically mapped
CMA_Partially_Abort    * 1<<13 ; partially abortable
CMA_Partially_UserXN   * 1<<14 ; partially non-executable in user mode
CMA_Partially_PrivXN   * 1<<15 ; partially non-executable in privileged modes

        END