blob: 1f6873a76e76c213105a90b521303a28fa5720c7 [file] [log] [blame]
Martin Peresa10220b2012-11-04 01:01:53 +01001/*
2 * Copyright 2012 Nouveau Community
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Martin Peres <martin.peres@labri.fr>
23 * Ben Skeggs
24 */
Ben Skeggs48ae0b32013-10-24 09:39:05 +100025#include "nv04.h"
Martin Peresa10220b2012-11-04 01:01:53 +010026
Marcin Slusarzcd897832013-01-27 15:01:55 +010027static void
Ben Skeggs5f8824d2015-01-14 14:40:22 +100028nv04_bus_intr(struct nvkm_subdev *subdev)
Martin Peresa10220b2012-11-04 01:01:53 +010029{
Ben Skeggs01d6b952015-08-20 14:54:06 +100030 struct nvkm_bus *bus = nvkm_bus(subdev);
Ben Skeggs14caba42015-08-20 14:54:08 +100031 struct nvkm_device *device = bus->subdev.device;
32 u32 stat = nvkm_rd32(device, 0x001100) & nvkm_rd32(device, 0x001140);
Martin Peresa10220b2012-11-04 01:01:53 +010033
34 if (stat & 0x00000001) {
Ben Skeggs01d6b952015-08-20 14:54:06 +100035 nv_error(bus, "BUS ERROR\n");
Martin Peresa10220b2012-11-04 01:01:53 +010036 stat &= ~0x00000001;
Ben Skeggs14caba42015-08-20 14:54:08 +100037 nvkm_wr32(device, 0x001100, 0x00000001);
Martin Peresa10220b2012-11-04 01:01:53 +010038 }
39
40 if (stat & 0x00000110) {
Ben Skeggs5f8824d2015-01-14 14:40:22 +100041 subdev = nvkm_subdev(subdev, NVDEV_SUBDEV_GPIO);
Martin Peresa10220b2012-11-04 01:01:53 +010042 if (subdev && subdev->intr)
43 subdev->intr(subdev);
44 stat &= ~0x00000110;
Ben Skeggs14caba42015-08-20 14:54:08 +100045 nvkm_wr32(device, 0x001100, 0x00000110);
Martin Peresa10220b2012-11-04 01:01:53 +010046 }
47
48 if (stat) {
Ben Skeggs01d6b952015-08-20 14:54:06 +100049 nv_error(bus, "unknown intr 0x%08x\n", stat);
Ben Skeggs14caba42015-08-20 14:54:08 +100050 nvkm_mask(device, 0x001140, stat, 0x00000000);
Martin Peresa10220b2012-11-04 01:01:53 +010051 }
52}
53
54static int
Ben Skeggs5f8824d2015-01-14 14:40:22 +100055nv04_bus_init(struct nvkm_object *object)
Martin Peresa10220b2012-11-04 01:01:53 +010056{
Ben Skeggs01d6b952015-08-20 14:54:06 +100057 struct nvkm_bus *bus = (void *)object;
Ben Skeggs14caba42015-08-20 14:54:08 +100058 struct nvkm_device *device = bus->subdev.device;
Martin Peresa10220b2012-11-04 01:01:53 +010059
Ben Skeggs14caba42015-08-20 14:54:08 +100060 nvkm_wr32(device, 0x001100, 0xffffffff);
61 nvkm_wr32(device, 0x001140, 0x00000111);
Martin Peresa10220b2012-11-04 01:01:53 +010062
Ben Skeggs01d6b952015-08-20 14:54:06 +100063 return nvkm_bus_init(bus);
Martin Peresa10220b2012-11-04 01:01:53 +010064}
65
Ben Skeggs48ae0b32013-10-24 09:39:05 +100066int
Ben Skeggs5f8824d2015-01-14 14:40:22 +100067nv04_bus_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
68 struct nvkm_oclass *oclass, void *data, u32 size,
69 struct nvkm_object **pobject)
Ben Skeggs48ae0b32013-10-24 09:39:05 +100070{
71 struct nv04_bus_impl *impl = (void *)oclass;
Ben Skeggs01d6b952015-08-20 14:54:06 +100072 struct nvkm_bus *bus;
Ben Skeggs48ae0b32013-10-24 09:39:05 +100073 int ret;
74
Ben Skeggs01d6b952015-08-20 14:54:06 +100075 ret = nvkm_bus_create(parent, engine, oclass, &bus);
76 *pobject = nv_object(bus);
Ben Skeggs48ae0b32013-10-24 09:39:05 +100077 if (ret)
78 return ret;
79
Ben Skeggs01d6b952015-08-20 14:54:06 +100080 nv_subdev(bus)->intr = impl->intr;
81 bus->hwsq_exec = impl->hwsq_exec;
82 bus->hwsq_size = impl->hwsq_size;
Ben Skeggs48ae0b32013-10-24 09:39:05 +100083 return 0;
84}
85
Ben Skeggs5f8824d2015-01-14 14:40:22 +100086struct nvkm_oclass *
Ben Skeggs48ae0b32013-10-24 09:39:05 +100087nv04_bus_oclass = &(struct nv04_bus_impl) {
88 .base.handle = NV_SUBDEV(BUS, 0x04),
Ben Skeggs5f8824d2015-01-14 14:40:22 +100089 .base.ofuncs = &(struct nvkm_ofuncs) {
Martin Peresa10220b2012-11-04 01:01:53 +010090 .ctor = nv04_bus_ctor,
Ben Skeggs5f8824d2015-01-14 14:40:22 +100091 .dtor = _nvkm_bus_dtor,
Martin Peresa10220b2012-11-04 01:01:53 +010092 .init = nv04_bus_init,
Ben Skeggs5f8824d2015-01-14 14:40:22 +100093 .fini = _nvkm_bus_fini,
Martin Peresa10220b2012-11-04 01:01:53 +010094 },
Ben Skeggs48ae0b32013-10-24 09:39:05 +100095 .intr = nv04_bus_intr,
96}.base;