1/*
2 * Copyright (c) 2014-2015 ARM Limited
3 * All rights reserved
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * Authors: Andreas Sandberg
18 */
19
20#ifndef _LIBNOMALIMODEL_JOBCONTROL_HH
21#define _LIBNOMALIMODEL_JOBCONTROL_HH
22
23#include <vector>
24
25#include "gpublock.hh"
26#include "jobslot.hh"
27#include "types.hh"
28
29namespace NoMali {
30
31class GPU;
32
33/**
34 * Minimal GPU job control implementation.
35 *
36 * This class implements the job control block of a Midgard style
37 * GPU. The job control block mainly coordinates interrupt delivery
38 * and register mappings for the different job slots within the
39 * block. The actual job slots are implemented by the JobSlot class.
40 *
41 * @see JobSlot
42 */
43class JobControl
44    : public GPUBlockInt
45{
46  public:
47    JobControl(GPU &_gpu);
48    virtual ~JobControl();
49
50    void reset() override;
51
52    uint32_t readReg(RegAddr idx)  override;
53    void writeReg(RegAddr idx, uint32_t value) override;
54
55    uint32_t readRegRaw(RegAddr idx)  override;
56    void writeRegRaw(RegAddr idx, uint32_t value) override;
57
58    /**
59     * Signal job done.
60     *
61     * Calling this method raises the job done interrupt for a
62     * specific job slot. This is typically called from the job slot
63     * running the job chain.
64     *
65     * @param slot Job slot number.
66     */
67    void jobDone(uint8_t slot);
68    /**
69     * Signal job failed.
70     *
71     * Calling this method raises the job failed interrupt for a
72     * specific job slot. This is typically called from the job slot
73     * running the job chain.
74     *
75     * @param slot Job slot number.
76     */
77    void jobFailed(uint8_t slot);
78
79  protected:
80    /**
81     * Update the state of the job slot state snapshot register.
82     *
83     * @param jobs Bit mask representing which job slots to update.
84     */
85    void updateJsState(uint16_t jobs);
86
87    void onInterrupt(int set) override;
88
89    /** Job slots belonging to this job control block */
90    std::vector<JobSlot> slots;
91};
92
93}
94
95#endif // _LIBNOMALIMODEL_JOBCONTROL_HH
96