Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2012 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  */
0023 #include "priv.h"
0024 
0025 #include <core/pci.h>
0026 
0027 #if defined(__powerpc__)
0028 struct priv {
0029     const void __iomem *data;
0030     int size;
0031 };
0032 
0033 static u32
0034 of_read(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
0035 {
0036     struct priv *priv = data;
0037     if (offset < priv->size) {
0038         length = min_t(u32, length, priv->size - offset);
0039         memcpy_fromio(bios->data + offset, priv->data + offset, length);
0040         return length;
0041     }
0042     return 0;
0043 }
0044 
0045 static u32
0046 of_size(void *data)
0047 {
0048     struct priv *priv = data;
0049     return priv->size;
0050 }
0051 
0052 static void *
0053 of_init(struct nvkm_bios *bios, const char *name)
0054 {
0055     struct nvkm_device *device = bios->subdev.device;
0056     struct pci_dev *pdev = device->func->pci(device)->pdev;
0057     struct device_node *dn;
0058     struct priv *priv;
0059     if (!(dn = pci_device_to_OF_node(pdev)))
0060         return ERR_PTR(-ENODEV);
0061     if (!(priv = kzalloc(sizeof(*priv), GFP_KERNEL)))
0062         return ERR_PTR(-ENOMEM);
0063     if ((priv->data = of_get_property(dn, "NVDA,BMP", &priv->size)))
0064         return priv;
0065     kfree(priv);
0066     return ERR_PTR(-EINVAL);
0067 }
0068 
0069 const struct nvbios_source
0070 nvbios_of = {
0071     .name = "OpenFirmware",
0072     .init = of_init,
0073     .fini = (void(*)(void *))kfree,
0074     .read = of_read,
0075     .size = of_size,
0076     .rw = false,
0077     .ignore_checksum = true,
0078     .no_pcir = true,
0079 };
0080 #else
0081 const struct nvbios_source
0082 nvbios_of = {
0083 };
0084 #endif