1c39f472eSBen Skeggs /*
2c39f472eSBen Skeggs * Copyright 2012 Red Hat Inc.
3c39f472eSBen Skeggs *
4c39f472eSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5c39f472eSBen Skeggs * copy of this software and associated documentation files (the "Software"),
6c39f472eSBen Skeggs * to deal in the Software without restriction, including without limitation
7c39f472eSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8c39f472eSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9c39f472eSBen Skeggs * Software is furnished to do so, subject to the following conditions:
10c39f472eSBen Skeggs *
11c39f472eSBen Skeggs * The above copyright notice and this permission notice shall be included in
12c39f472eSBen Skeggs * all copies or substantial portions of the Software.
13c39f472eSBen Skeggs *
14c39f472eSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c39f472eSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c39f472eSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17c39f472eSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18c39f472eSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19c39f472eSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20c39f472eSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21c39f472eSBen Skeggs *
22c39f472eSBen Skeggs */
23c39f472eSBen Skeggs #include "priv.h"
2425d29588SIlia Mirkin
254b9e78bdSDave Airlie #include <core/pci.h>
26d390b480SBen Skeggs
27c39f472eSBen Skeggs #if defined(__powerpc__)
28c39f472eSBen Skeggs struct priv {
29c39f472eSBen Skeggs const void __iomem *data;
30c39f472eSBen Skeggs int size;
31c39f472eSBen Skeggs };
32c39f472eSBen Skeggs
33c39f472eSBen Skeggs static u32
of_read(void * data,u32 offset,u32 length,struct nvkm_bios * bios)34d390b480SBen Skeggs of_read(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
35c39f472eSBen Skeggs {
36c39f472eSBen Skeggs struct priv *priv = data;
3725d29588SIlia Mirkin if (offset < priv->size) {
3825d29588SIlia Mirkin length = min_t(u32, length, priv->size - offset);
39c39f472eSBen Skeggs memcpy_fromio(bios->data + offset, priv->data + offset, length);
40c39f472eSBen Skeggs return length;
41c39f472eSBen Skeggs }
42c39f472eSBen Skeggs return 0;
43c39f472eSBen Skeggs }
44c39f472eSBen Skeggs
4525d29588SIlia Mirkin static u32
of_size(void * data)4625d29588SIlia Mirkin of_size(void *data)
4725d29588SIlia Mirkin {
4825d29588SIlia Mirkin struct priv *priv = data;
4925d29588SIlia Mirkin return priv->size;
5025d29588SIlia Mirkin }
5125d29588SIlia Mirkin
52c39f472eSBen Skeggs static void *
of_init(struct nvkm_bios * bios,const char * name)53d390b480SBen Skeggs of_init(struct nvkm_bios *bios, const char *name)
54c39f472eSBen Skeggs {
5525d29588SIlia Mirkin struct nvkm_device *device = bios->subdev.device;
5625d29588SIlia Mirkin struct pci_dev *pdev = device->func->pci(device)->pdev;
57c39f472eSBen Skeggs struct device_node *dn;
58c39f472eSBen Skeggs struct priv *priv;
59c39f472eSBen Skeggs if (!(dn = pci_device_to_OF_node(pdev)))
60c39f472eSBen Skeggs return ERR_PTR(-ENODEV);
61c39f472eSBen Skeggs if (!(priv = kzalloc(sizeof(*priv), GFP_KERNEL)))
62c39f472eSBen Skeggs return ERR_PTR(-ENOMEM);
63c39f472eSBen Skeggs if ((priv->data = of_get_property(dn, "NVDA,BMP", &priv->size)))
64c39f472eSBen Skeggs return priv;
65c39f472eSBen Skeggs kfree(priv);
66c39f472eSBen Skeggs return ERR_PTR(-EINVAL);
67c39f472eSBen Skeggs }
68c39f472eSBen Skeggs
of_fini(void * p)69*aebbe59bSArnd Bergmann static void of_fini(void *p)
70*aebbe59bSArnd Bergmann {
71*aebbe59bSArnd Bergmann kfree(p);
72*aebbe59bSArnd Bergmann }
73*aebbe59bSArnd Bergmann
74c39f472eSBen Skeggs const struct nvbios_source
75c39f472eSBen Skeggs nvbios_of = {
76c39f472eSBen Skeggs .name = "OpenFirmware",
77c39f472eSBen Skeggs .init = of_init,
78*aebbe59bSArnd Bergmann .fini = of_fini,
79c39f472eSBen Skeggs .read = of_read,
8025d29588SIlia Mirkin .size = of_size,
81c39f472eSBen Skeggs .rw = false,
8225d29588SIlia Mirkin .ignore_checksum = true,
8325d29588SIlia Mirkin .no_pcir = true,
84c39f472eSBen Skeggs };
85c39f472eSBen Skeggs #else
86c39f472eSBen Skeggs const struct nvbios_source
87c39f472eSBen Skeggs nvbios_of = {
88c39f472eSBen Skeggs };
89c39f472eSBen Skeggs #endif
90