1// Copyright 2018 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <ddk/debug.h>
6#include <ddk/protocol/platform-defs.h>
7#include <hw/reg.h>
8#include <soc/aml-s912/s912-hw.h>
9
10#include "vim.h"
11
12static const pbus_mmio_t mali_mmios[] = {
13    {
14        .base = S912_MALI_BASE,
15        .length = S912_MALI_LENGTH,
16    },
17    {
18        .base = S912_HIU_BASE,
19        .length = S912_HIU_LENGTH,
20    },
21    {
22        .base = S912_PRESET_BASE,
23        .length = S912_PRESET_LENGTH,
24    },
25};
26
27static const pbus_irq_t mali_irqs[] = {
28    {
29        .irq = S912_MALI_IRQ_PP,
30        .mode = ZX_INTERRUPT_MODE_LEVEL_HIGH,
31    },
32    {
33        .irq = S912_MALI_IRQ_GPMMU,
34        .mode = ZX_INTERRUPT_MODE_LEVEL_HIGH,
35    },
36    {
37        .irq = S912_MALI_IRQ_GP,
38        .mode = ZX_INTERRUPT_MODE_LEVEL_HIGH,
39    },
40};
41
42static pbus_bti_t mali_btis[] = {
43    {
44        .iommu_index = 0,
45        .bti_id = 0,
46    },
47};
48
49static const pbus_dev_t mali_dev = {
50    .name = "mali",
51    .vid = PDEV_VID_AMLOGIC,
52    .pid = PDEV_PID_AMLOGIC_S912,
53    .did = PDEV_DID_ARM_MALI_INIT,
54    .mmios = mali_mmios,
55    .mmio_count = countof(mali_mmios),
56    .irqs = mali_irqs,
57    .irq_count = countof(mali_irqs),
58    .btis = mali_btis,
59    .bti_count = countof(mali_btis),
60};
61
62zx_status_t vim_mali_init(vim_bus_t* bus, uint32_t bti_index) {
63
64    // Populate the BTI information
65    mali_btis[0].iommu_index = 0;
66    mali_btis[0].bti_id      = bti_index;
67
68    zx_status_t status = pbus_device_add(&bus->pbus, &mali_dev);
69    if (status != ZX_OK) {
70        zxlogf(ERROR, "vim_mali_init: pbus_device_add failed: %d\n", status);
71        return status;
72    }
73    return status;
74}
75