1    /* 
     2     * Copyright (c) 2012, Texas Instruments Incorporated
     3     * All rights reserved.
     4     *
     5     * Redistribution and use in source and binary forms, with or without
     6     * modification, are permitted provided that the following conditions
     7     * 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 distribution.
    15     *
    16     * *  Neither the name of Texas Instruments Incorporated nor the names of
    17     *    its contributors may be used to endorse or promote products derived
    18     *    from this software without specific prior written permission.
    19     *
    20     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    21     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    22     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    23     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    24     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    25     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    26     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    27     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    28     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    29     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    30     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    31     * */
    32    /*
    33     *  ======== Power.xdc ========
    34     *
    35     *
    36     */
    37    
    38    package ti.sysbios.family.c64p.tesla;
    39    
    40    /*!
    41     *  ======== Power ========
    42     *  Power Module
    43     *
    44     *  This module is used to reduce power consumption of the Tesla subsystem.  
    45     *  Three reduction techniques are supported:
    46     *
    47     *  Suspend/Resume with Retention: The Tesla subsystem is put into standby, 
    48     *  upon which PRCM will transition the power domain to closed-switch retention
    49     *  (CSWR).  Upon release from retention reset, the CPU will start executing 
    50     *  from reset; a reset hook function will hijack the boot process, restore CPU
    51     *  state to that before retention, and then return back into the 
    52     *  Power_suspend() API, which will return to its caller, to resume the 
    53     *  application.
    54     *
    55     *  Suspend/Resume with Hibernation: The Tesla subsystem context is saved to 
    56     *  external RAM, and GEM is put into standby.  Upon the standby transition, 
    57     *  PRCM will transition the power domain to off.  Upon release from reset, the
    58     *  CPU will start executing from reset; a reset hook function will hijack the 
    59     *  boot process, restore CPU state, return back into the Power_suspend() API, 
    60     *  which will restore the remaining Tesla subsystem context, and then return 
    61     *  to its caller, to resume the application.
    62     *
    63     *  Idling in the Idle loop:  A function will be inserted into the Idle loop, 
    64     *  which will automatically idle the CPU while waiting for the next interrupt.
    65     * 
    66     *  The application must explicitly call to Power_suspend() for Suspend/Resume
    67     *  functionality.  For idling functionality, this enabled statically, in the 
    68     *  application configuration, and the idling in the idle loop will happen 
    69     *  routinely upon execution of the Idle loop.
    70     *
    71     *  Suspend/Resume can be invoked from Task, Swi, or Idle loop context.  
    72     *  It cannot be invoked from Hwi context.
    73     */
    74    module Power
    75    {
    76        /*! Suspend Level. */
    77        enum  Suspend {
    78            Suspend_RETENTION,      /*! Suspend to RETENTION state */
    79            Suspend_HIBERNATE       /*! Suspend to HIBERNATE state */
    80        };
    81    
    82        /*! Base address of EDMA TPCC registers */
    83        config Ptr tpccRegs = 0x01C00000;
    84    
    85        /*! Base address of SYSC registers */
    86        config Ptr syscRegs = 0x01C20000;
    87    
    88        /*! Idle the CPU when threads blocked waiting for an interrupt? */
    89        config Bool idle = false;
    90    
    91        /*! Name of segment to load Power's reset code and saved context */
    92        metaonly config String loadSegment = "EXT_RAM";
    93    
    94        /*!
    95         *  ======== idleCPU ========
    96         *  Function used to automatically idle the CPU in the Idle loop.
    97         *
    98         *  When the 'idle' configuration flag is set: this function will
    99         *  be added to the list of Idle loop functions.  When called from the
   100         *  Idle loop, it will invoke the IDLE instruction, to idle the CPU until 
   101         *  the next interrupt occurs.  This function will idle the CPU, but will
   102         *  not put the whole megamodule (GEM) into standby.
   103         */
   104        @DirectCall
   105        Void idleCPU();
   106    
   107        /*!
   108         *  ======== suspend ========
   109         *  Function used for suspend/resume of the Tesla subsystem.
   110         *
   111         *  This function will save Tesla subsystem context and then put GEM into
   112         *  standby, as the final steps for a transition to either retention
   113         *  (CSWR), or hibernate (also referred to as off-mode).
   114         *
   115         *  Prior to invoking this function the application software must prepare
   116         *  for suspend, which includes: configuring PRCM for the appropriate 
   117         *  transition once GEM goes to standby; disabling unintended wakeup 
   118         *  interrupts, and configuring intended wakeups; taking care of any 
   119         *  required notifications to software components; and 'quieting' of the
   120         *  DSP application (e.g., ensuring that all in-progress EDMA activity 
   121         *  completes).
   122         */
   123        @DirectCall
   124        UInt suspend(Suspend level);
   125    
   126    internal:
   127    
   128        struct CpuSysRegs {
   129            UInt32  AMR;
   130            UInt32  CSR;
   131            UInt32  IER;
   132            UInt32  ISTP;
   133            UInt32  IRP;
   134            UInt32  SSR;
   135            UInt32  GPLYB;
   136            UInt32  GFPGFR;
   137            UInt32  TSR;
   138            UInt32  ITSR;
   139            UInt32  IERR;
   140        }
   141    
   142        struct IntcConfig {
   143            UInt32 EVTMASK0;
   144            UInt32 EVTMASK1;
   145            UInt32 EVTMASK2;
   146            UInt32 EVTMASK3;
   147            UInt32 EXPMASK0;
   148            UInt32 EXPMASK1;
   149            UInt32 EXPMASK2;
   150            UInt32 EXPMASK3;
   151            UInt32 INTMUX1;
   152            UInt32 INTMUX2;
   153            UInt32 INTMUX3;
   154            UInt32 AEGMUX0;
   155            UInt32 AEGMUX1;
   156            UInt32 INTDMASK;
   157        };
   158    
   159        struct SyscConfig {
   160            UInt32 SYSCONFIG;
   161            UInt32 VBUSM2OCP;
   162            UInt32 EDMA;
   163            UInt32 CORE;
   164            UInt32 IVA_ICTRL;
   165            UInt32 IDLEDLY;
   166        };
   167    
   168        struct UnicacheConfig {
   169            UInt32 CONFIG;
   170            UInt32 OCP;
   171        };
   172    
   173        struct AmmuConfig {
   174            UInt32 largeAddr[8];
   175            UInt32 largePolicy[8];
   176            UInt32 medAddr[7];
   177            UInt32 medPolicy[7];
   178            UInt32 smallAddr[3];
   179            UInt32 smallPolicy[3];
   180            UInt32 mmuConfig;
   181        };
   182    
   183        struct EdmaConfig {
   184            UInt32 CLKGDIS;
   185            UInt32 DCHMAP[64];
   186            UInt32 QCHMAP[8];
   187            UInt32 DMAQNUM[8];
   188            UInt32 QDMAQNUM;
   189            UInt32 QUETCMAP;
   190            UInt32 QUEPRI;
   191            UInt32 regionAccessBits[24];
   192            UInt32 QWMTHRA;
   193            UInt32 AETCTL;
   194            UInt32 IER;
   195            UInt32 IERH;
   196            UInt32 QEER;
   197            UInt32 PaRAMs[1024];
   198        };
   199    
   200        struct SubsystemContext {
   201            CpuSysRegs      cpuSysRegs;
   202            UnicacheConfig  configL1;
   203            UnicacheConfig  configL2;
   204            IntcConfig      configINTC;
   205            SyscConfig      configSYSC;
   206            AmmuConfig      configAMMU;
   207            EdmaConfig      configEDMA;
   208            Bool            tscRunning;
   209        };
   210    
   211        /*!
   212         *  ======== resetFxn ========
   213         *  Startup reset function that checks if coming out of a processor reset 
   214         *  due to Power_suspend().  If no, it will simply return.  If yes, it
   215         *  will restore CPU context, and return using a saved return pointer,
   216         *  warping back into the Power_suspend API.
   217         */
   218        Void resetFxn();
   219    
   220        /*!
   221         *  ======== standby ========
   222         *  Function used for final CPU register save and transition to standby.
   223         */
   224        UInt standby(UInt32 *cpuRegs);
   225    
   226    }
   227    
   228    /*
   229     *  @(#) ti.sysbios.family.c64p.tesla; 1, 0, 0, 0,296; 2-24-2012 11:40:12; /db/vtree/library/trees/avala/avala-q28x/src/ xlibrary
   230    
   231     */
   232