1    /*
     2     * Copyright (c) 2014 Texas Instruments Incorporated - https://www.ti.com
     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    /*
    34     *  ======== NotifyDriverMbx.xdc ================
    35     */
    36    package ti.sdo.ipc.family.vayu;
    37    
    38    import ti.sdo.utils.MultiProc;
    39    import ti.sdo.ipc.interfaces.INotifyDriver;
    40    import ti.sdo.ipc.Notify;
    41    
    42    import ti.sysbios.hal.Hwi;
    43    
    44    import xdc.runtime.Assert;
    45    import xdc.rov.ViewInfo;
    46    
    47    /*!
    48     *  ======== NotifyDriverMbx ========
    49     *  A notify driver based on hardware mailbox.
    50     *
    51     *  This notify driver uses hardware mailboxes to transmit notifications
    52     *  to remote processors. This driver implements the
    53     *  {@link ti.sdo.ipc.interfaces.INotifyDriver} interface.
    54     *
    55     *  Unlike the Notify drivers available in the {@link ti.sdo.ipc.notifyDrivers}
    56     *  package, this driver is not generic and will only work with the Vayu
    57     *  family of devices.
    58     *
    59     *  The driver does not use shared memory. The event IDs and payloads are
    60     *  transmitted via the hardware mailbox FIFO. The FIFO can hold up to 4
    61     *  mailbox messages. The number of notification that can be stored in the
    62     *  FIFO depends on the size of the payloads being sent via Notify_sendEvent.
    63     *  If the payload is less than 0x7FFFFFF, then a single message will be
    64     *  sent per notification. Otherwise, two mailbox messages are needed to
    65     *  send the notification.
    66     *
    67     *  The behavior of Notify_sendEvent when the FIFO is full depends on the
    68     *  value of the 'waitClear' argument to the function. If 'waitClear' is
    69     *  TRUE, then Notify_sendEvent will spin waiting for enough room in the
    70     *  FIFO. If 'waitClear' is FALSE, then Notify_sendEvent will return
    71     *  Notify_E_FAIL.
    72     *
    73     *  The Notify_enableEvent and Notify_disableEvent APIs are not supported
    74     *  by this driver.
    75     */
    76    @InstanceFinalize
    77    @ModuleStartup
    78    
    79    module NotifyDriverMbx inherits ti.sdo.ipc.interfaces.INotifyDriver
    80    {
    81        /*! @_nodoc */
    82        metaonly struct BasicView {
    83            String      remoteProc;
    84        }
    85    
    86        /*! @_nodoc */
    87        metaonly struct MailboxView {
    88            String      direction;
    89            String      mailboxAddr;
    90            Int         subMbxId;
    91            Int         msgCount;
    92            Int         mbxInterrupt;
    93        }
    94    
    95        /*!  @_nodoc */
    96        metaonly struct ModuleView {
    97            NotifyDriverMbx.Handle  drvHandles[NUM_CORES];
    98        }
    99    
   100        /*!
   101         *  ======== rovViewInfo ========
   102         */
   103        @Facet
   104        metaonly config ViewInfo.Instance rovViewInfo =
   105            ViewInfo.create({
   106                viewMap: [
   107                    ['Basic',
   108                        {
   109                            type: ViewInfo.INSTANCE,
   110                            viewInitFxn: 'viewInitBasic',
   111                            structName: 'BasicView'
   112                        }
   113                    ],
   114                    ['Mailbox',
   115                        {
   116                            type: ViewInfo.INSTANCE_DATA,
   117                            viewInitFxn: 'viewInitMailbox',
   118                            structName: 'MailboxView'
   119                        }
   120                    ]
   121    //              ['Module',
   122    //                  {
   123    //                      type: ViewInfo.MODULE,
   124    //                      viewInitFxn: 'viewInitModule',
   125    //                      structName: 'ModuleView'
   126    //                  }
   127    //              ]
   128                ]
   129            });
   130    
   131        /*!
   132         *  Assert raised when trying to use Notify_[enable/disable]Event with
   133         *  NotifyDriverMbx
   134         */
   135        config Assert.Id A_notSupported = {
   136            msg: "A_notSupported: [enable/disable]Event not supported"
   137        };
   138    
   139    instance:
   140    
   141        /*!
   142         *  ======== remoteProcId ========
   143         *  The MultiProc ID corresponding to the remote processor
   144         *
   145         *  This is a required parameter, it is not optional.
   146         */
   147        config UInt16 remoteProcId = MultiProc.INVALIDID;
   148    
   149        /*!
   150         *  ======== intVectorId ========
   151         *  Interrupt vector ID to be used by the driver.
   152         *
   153         *  This parameter is only used by C66 targets.
   154         *  This is a required parameter, it is not optional.
   155         */
   156        config UInt intVectorId = ~1u;
   157    
   158    internal:
   159        /* total number of cores on Vayu SoC */
   160        const UInt8 NUM_CORES = 11;
   161    
   162        /* number of cores in eve subsystem */
   163        const UInt8 NUM_EVES = 4;
   164    
   165        /* number of internal eve mailboxes */
   166        const UInt8 NUM_EVE_MBX = 12;
   167    
   168        /* number of system mailboxes (used by IPC) */
   169        const UInt8 NUM_SYS_MBX = 4;
   170    
   171        /*  Mailbox table for storing encoded base address, mailbox user ID,
   172         *  and sub-mailbox index.
   173         */
   174        config UInt32 mailboxTable[NUM_CORES * NUM_CORES];
   175    
   176        /* base address table for the mailbox subsystem */
   177        /* TODO use the table in NotifySetup module */
   178        config UInt32 mailboxBaseAddr[NUM_EVE_MBX + NUM_SYS_MBX];
   179    
   180        /* map MultiProc ID to virtual ID, virtId = procIdTable[procId] */
   181        config UInt32 procIdTable[NUM_CORES];
   182    
   183        /*! define MultiProcID for each core to avoid doing this at runtime */
   184        config UInt eve1ProcId     = MultiProc.INVALIDID;
   185        config UInt eve2ProcId     = MultiProc.INVALIDID;
   186        config UInt eve3ProcId     = MultiProc.INVALIDID;
   187        config UInt eve4ProcId     = MultiProc.INVALIDID;
   188        config UInt dsp1ProcId     = MultiProc.INVALIDID;
   189        config UInt dsp2ProcId     = MultiProc.INVALIDID;
   190        config UInt ipu1_0ProcId   = MultiProc.INVALIDID;
   191        config UInt ipu2_0ProcId   = MultiProc.INVALIDID;
   192        config UInt hostProcId     = MultiProc.INVALIDID;
   193        config UInt ipu1_1ProcId   = MultiProc.INVALIDID;
   194        config UInt ipu2_1ProcId   = MultiProc.INVALIDID;
   195    
   196        /* plugs the interrupt and executes the callback functions */
   197        Void isr(UInt16 idx);
   198    
   199        /*! instance state structure */
   200        struct Instance_State {
   201            Bits32          evtRegMask;     /* local event register mask        */
   202            Notify.Handle   notifyHandle;   /* handle to front-end object       */
   203            UInt16          remoteProcId;   /* remote processor ID              */
   204            UInt16          remoteVirtId;   /* remote processor virtual ID      */
   205            Int             cpuIntrNum;     /* cpu interrupt number             */
   206        }
   207    
   208        struct Module_State {
   209            /*  Used by the isr to retrieve the driver handle. This table is
   210             *  indexed by virtual processorID.
   211             */
   212            NotifyDriverMbx.Handle drvHandles[NUM_CORES];
   213        };
   214    }