jobslot.hh revision 10915
12810SN/A/*
212724Snikos.nikoleris@arm.com * Copyright (c) 2014-2015 ARM Limited
38856Sandreas.hansson@arm.com * All rights reserved
48856Sandreas.hansson@arm.com *
58856Sandreas.hansson@arm.com * Licensed under the Apache License, Version 2.0 (the "License");
68856Sandreas.hansson@arm.com * you may not use this file except in compliance with the License.
78856Sandreas.hansson@arm.com * You may obtain a copy of the License at
88856Sandreas.hansson@arm.com *
98856Sandreas.hansson@arm.com *     http://www.apache.org/licenses/LICENSE-2.0
108856Sandreas.hansson@arm.com *
118856Sandreas.hansson@arm.com * Unless required by applicable law or agreed to in writing, software
128856Sandreas.hansson@arm.com * distributed under the License is distributed on an "AS IS" BASIS,
138856Sandreas.hansson@arm.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
142810SN/A * See the License for the specific language governing permissions and
152810SN/A * limitations under the License.
162810SN/A *
172810SN/A * Authors: Andreas Sandberg
182810SN/A */
192810SN/A
202810SN/A#ifndef _LIBNOMALIMODEL_JOBSLOT_HH
212810SN/A#define _LIBNOMALIMODEL_JOBSLOT_HH
222810SN/A
232810SN/A#include <vector>
242810SN/A
252810SN/A#include "gpublock.hh"
262810SN/A#include "types.hh"
272810SN/A
282810SN/Anamespace NoMali {
292810SN/A
302810SN/Aclass GPU;
312810SN/A
322810SN/Aclass JobControl;
332810SN/A
342810SN/A/**
352810SN/A * Midgard job slot implementation.
362810SN/A *
372810SN/A * A job slot is a part of a JobControl block that controls the state
382810SN/A * of one out of 16 active jobs. Each slot can contain one running job
392810SN/A * and a pending job.
402810SN/A */
414458SN/Aclass JobSlot
424458SN/A    : public GPUBlock
4312724Snikos.nikoleris@arm.com{
4412724Snikos.nikoleris@arm.com  public:
452810SN/A    JobSlot(GPU &_gpu, JobControl &_jc, uint8_t slot_id);
462810SN/A    JobSlot(JobSlot &&rhs);
472810SN/A    virtual ~JobSlot();
482810SN/A
492810SN/A    void writeReg(RegAddr idx, uint32_t value) override;
502810SN/A
512810SN/A    /** Is there an active job in this job slot? */
5211051Sandreas.hansson@arm.com    bool active() const;
5311051Sandreas.hansson@arm.com    /** Is there a pending next job in this job slot? */
542810SN/A    bool activeNext() const;
5512724Snikos.nikoleris@arm.com
5612724Snikos.nikoleris@arm.com  protected:
577676Snate@binkert.org    /**
582810SN/A     * @{
5912724Snikos.nikoleris@arm.com     * @name Job Control
602810SN/A     */
612810SN/A
626215Snate@binkert.org    /**
638232Snate@binkert.org     * Try to start the next job in the slot.
648232Snate@binkert.org     *
6512724Snikos.nikoleris@arm.com     * Start the next job if the following conditions are true:
6613223Sodanrc@yahoo.com.br     * <ul>
6713945Sodanrc@yahoo.com.br     *   <li>There is no currently running job.
685338Sstever@gmail.com     *   <li>The pending command in the JSn_COMMAND_NEXT register is
6912724Snikos.nikoleris@arm.com     *       JSn_COMMAND_START.
7011375Sandreas.hansson@arm.com     * </ul>
7112724Snikos.nikoleris@arm.com     *
722810SN/A     * When the job is started, the registers describing the next job
7312724Snikos.nikoleris@arm.com     * chain are moved (resetting them to zero) into the register
748914Sandreas.hansson@arm.com     * block describing the currently running job. The job is then run
758229Snate@binkert.org     * by a call to runJob().
7613352Snikos.nikoleris@arm.com     */
7713892Sgabeblack@google.com    void tryStart();
782811SN/A
7913416Sjavier.bueno@metempsy.com    /**
8012724Snikos.nikoleris@arm.com     * Execute the job in described by the current job registers.
814626SN/A     */
828833Sdam.sunwoo@arm.com    void runJob();
832810SN/A
8412724Snikos.nikoleris@arm.com    /**
8512724Snikos.nikoleris@arm.com     * Report the exit status of an exiting job.
8612724Snikos.nikoleris@arm.com     *
8712724Snikos.nikoleris@arm.com     * @note The exit status must be of the class
8812724Snikos.nikoleris@arm.com     * Status::CLASS_NOFAULT or Status::CLASS_JOB.
8912724Snikos.nikoleris@arm.com     *
9012724Snikos.nikoleris@arm.com     * @note The fault address isn't always a fault address, it is
9112724Snikos.nikoleris@arm.com     * sometimes used to represent a TSC value. See the Midgard
922810SN/A     * architecture specification for details.
932810SN/A     *
942810SN/A     * @param status Job exit status.
9513892Sgabeblack@google.com     * @param fault_address Fault address to write into descriptor.
962810SN/A     */
9711375Sandreas.hansson@arm.com    void exitJob(Status status, uint64_t fault_address);
984628SN/A
994628SN/A    /** @} */
1004628SN/A
1014628SN/A    /**
1024628SN/A     * @{
1034628SN/A     * @name Job slot commands
1044628SN/A     */
1054628SN/A
1068737Skoansin.tan@gmail.com    /**
1074628SN/A     * Control command dispatcher.
1084628SN/A     *
1094628SN/A     * This method is called whenever there is a write to the
1104628SN/A     * JSn_COMMAND register. The method uses a lookup table to call
1114628SN/A     * the right command handling method.
1124628SN/A     *
1134628SN/A     * @param cmd Command number (see the Midgard architecture
1144628SN/A     * specification)
1154628SN/A     */
1164628SN/A    void jobCommand(uint32_t cmd);
1178737Skoansin.tan@gmail.com
1184628SN/A    /**
1198856Sandreas.hansson@arm.com     * Command handler for No-ops.
1208856Sandreas.hansson@arm.com     *
1218856Sandreas.hansson@arm.com     * @param cmd Command number (see the Midgard architecture
1228856Sandreas.hansson@arm.com     * specification)
1238856Sandreas.hansson@arm.com     */
12410942Sandreas.hansson@arm.com    void cmdNop(uint32_t cmd);
1258856Sandreas.hansson@arm.com    /**
1268856Sandreas.hansson@arm.com     * Command handler for job start commands.
1278856Sandreas.hansson@arm.com     *
1288922Swilliam.wang@arm.com     * @note This should <i>NEVER</i> be called as the start command
1292810SN/A     * should never be written to the JSn_COMMAND register. Jobs are
1308856Sandreas.hansson@arm.com     * normally started by tryStart() whenever the state of the
1312844SN/A     * currently running job changes or JSn_COMMAND_START is written
1328856Sandreas.hansson@arm.com     * to the JSn_COMMAND_NEXT register.
1338856Sandreas.hansson@arm.com     *
1348856Sandreas.hansson@arm.com     * @param cmd Command number (see the Midgard architecture
13510713Sandreas.hansson@arm.com     * specification)
1368856Sandreas.hansson@arm.com     */
13710942Sandreas.hansson@arm.com    void cmdStart(uint32_t cmd);
1388856Sandreas.hansson@arm.com    /**
13910942Sandreas.hansson@arm.com     * Gently stop the currently running job chain.
14010713Sandreas.hansson@arm.com     *
1418856Sandreas.hansson@arm.com     * @param cmd Command number (see the Midgard architecture
1428856Sandreas.hansson@arm.com     * specification)
1433738SN/A     */
1444458SN/A    void cmdSoftStop(uint32_t cmd);
1458856Sandreas.hansson@arm.com    /**
14610713Sandreas.hansson@arm.com     * Force a stop of the currently running job chain.
14710713Sandreas.hansson@arm.com     *
14810713Sandreas.hansson@arm.com     * @param cmd Command number (see the Midgard architecture
1498914Sandreas.hansson@arm.com     * specification)
1502810SN/A     */
1518856Sandreas.hansson@arm.com    void cmdHardStop(uint32_t cmd);
1528856Sandreas.hansson@arm.com    /**
1538856Sandreas.hansson@arm.com     * Soft stop the current job chain if the JOB_CHAIN_FLAG <i>IS
1548914Sandreas.hansson@arm.com     * NOT</i> set.
1558856Sandreas.hansson@arm.com     *
1568922Swilliam.wang@arm.com     * @param cmd Command number (see the Midgard architecture
1578856Sandreas.hansson@arm.com     * specification)
1583013SN/A     */
1598856Sandreas.hansson@arm.com    void cmdSoftStop0(uint32_t cmd);
16012724Snikos.nikoleris@arm.com    /**
16112724Snikos.nikoleris@arm.com     * Hard stop the current job chain if the JOB_CHAIN_FLAG <i>IS
16212724Snikos.nikoleris@arm.com     * NOT</i> set.
16312724Snikos.nikoleris@arm.com     *
16412724Snikos.nikoleris@arm.com     * @param cmd Command number (see the Midgard architecture
16512724Snikos.nikoleris@arm.com     * specification)
16612724Snikos.nikoleris@arm.com     */
16712724Snikos.nikoleris@arm.com    void cmdHardStop0(uint32_t cmd);
16812724Snikos.nikoleris@arm.com    /**
16912724Snikos.nikoleris@arm.com     * Soft stop the current job chain if the JOB_CHAIN_FLAG <i>IS</i>
17012724Snikos.nikoleris@arm.com     * set.
17112724Snikos.nikoleris@arm.com     *
17212724Snikos.nikoleris@arm.com     * @param cmd Command number (see the Midgard architecture
17312724Snikos.nikoleris@arm.com     * specification)
17412724Snikos.nikoleris@arm.com     */
17512724Snikos.nikoleris@arm.com    void cmdSoftStop1(uint32_t cmd);
17612724Snikos.nikoleris@arm.com    /**
17712724Snikos.nikoleris@arm.com     * Hard stop the current job chain if the JOB_CHAIN_FLAG <i>IS</i>
17812724Snikos.nikoleris@arm.com     * set.
17912724Snikos.nikoleris@arm.com     *
18012724Snikos.nikoleris@arm.com     * @param cmd Command number (see the Midgard architecture
18112724Snikos.nikoleris@arm.com     * specification)
18212724Snikos.nikoleris@arm.com     */
18312724Snikos.nikoleris@arm.com    void cmdHardStop1(uint32_t cmd);
18412724Snikos.nikoleris@arm.com
18512724Snikos.nikoleris@arm.com    /** @} */
18612724Snikos.nikoleris@arm.com
18712724Snikos.nikoleris@arm.com    /** Job slot ID */
18812724Snikos.nikoleris@arm.com    const uint8_t id;
18912724Snikos.nikoleris@arm.com
19012724Snikos.nikoleris@arm.com    /** Parent JobControl block */
19112724Snikos.nikoleris@arm.com    JobControl &jc;
19212724Snikos.nikoleris@arm.com
19313860Sodanrc@yahoo.com.br  private:
19413860Sodanrc@yahoo.com.br    typedef void (JobSlot::*cmd_t)(uint32_t);
19512724Snikos.nikoleris@arm.com
19613860Sodanrc@yahoo.com.br    /**
19712724Snikos.nikoleris@arm.com     * Mapping between command IDs and command handling methods.
19813860Sodanrc@yahoo.com.br     *
19912724Snikos.nikoleris@arm.com     * @note The order of this vector <i>MUST</i> correspond to the
20012724Snikos.nikoleris@arm.com     * job control command IDs in the Midgard architecture
20112724Snikos.nikoleris@arm.com     * specification.
20212724Snikos.nikoleris@arm.com     */
20312724Snikos.nikoleris@arm.com    static const std::vector<cmd_t> cmds;
20412724Snikos.nikoleris@arm.com};
20512724Snikos.nikoleris@arm.com
20612724Snikos.nikoleris@arm.com}
20712724Snikos.nikoleris@arm.com
20812724Snikos.nikoleris@arm.com#endif // _LIBNOMALIMODEL_JOBSLOT_HH
20912724Snikos.nikoleris@arm.com