summaryrefslogtreecommitdiffstats
path: root/debian/grub-extras/disabled/gpxe/wrap
diff options
context:
space:
mode:
Diffstat (limited to 'debian/grub-extras/disabled/gpxe/wrap')
-rw-r--r--debian/grub-extras/disabled/gpxe/wrap/nic.c138
-rw-r--r--debian/grub-extras/disabled/gpxe/wrap/pci.c56
-rw-r--r--debian/grub-extras/disabled/gpxe/wrap/wrap.c75
3 files changed, 269 insertions, 0 deletions
diff --git a/debian/grub-extras/disabled/gpxe/wrap/nic.c b/debian/grub-extras/disabled/gpxe/wrap/nic.c
new file mode 100644
index 0000000..05a3b89
--- /dev/null
+++ b/debian/grub-extras/disabled/gpxe/wrap/nic.c
@@ -0,0 +1,138 @@
+/*
+ * Copyright © 2009 Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+FILE_LICENCE ( BSD2 );
+
+#include <gpxe/pci.h>
+#include <grub/misc.h>
+
+/* Helper for grub_gpxe_register_pci_nic. */
+static int
+grub_gpxe_pci_nic_init (grub_pci_device_t dev, grub_pci_id_t pciid, void *data)
+{
+ struct pci_driver *nic = data;
+ unsigned i;
+
+ for (i = 0; i < nic->id_count; i++)
+ {
+ int err;
+ if (nic->ids[i].devid == pciid)
+ {
+ struct pci_device *pci;
+ struct pci_device_id *id;
+ int reg;
+
+ grub_dprintf ("gpxe", "Attaching NIC %d:%d.%d\n",
+ grub_pci_get_bus (dev),
+ grub_pci_get_device (dev),
+ grub_pci_get_function (dev));
+ pci = grub_malloc (sizeof (*pci));
+ if (!pci)
+ {
+ grub_print_error ();
+ grub_errno = GRUB_ERR_NONE;
+ return 0;
+ }
+ id = grub_malloc (sizeof (*id));
+ if (!id)
+ {
+ grub_free (pci);
+ grub_print_error ();
+ grub_errno = GRUB_ERR_NONE;
+ return 0;
+ }
+ id->devid = pciid;
+ pci->dev.desc.bus_type = BUS_TYPE_PCI;
+ pci->dev.desc.bus = grub_pci_get_bus (dev);
+ pci->dev.desc.location = (grub_pci_get_device (dev) << 3)
+ | grub_pci_get_function (dev);
+ pci->dev.desc.vendor = pciid & 0xffff;
+ pci->dev.desc.device = pciid >> 16;
+ pci->vendor = pciid & 0xffff;
+ pci->device = pciid >> 16;
+ pci->dev.name = grub_xasprintf ("PCI:%02x:%02x.%x",
+ grub_pci_get_bus (dev),
+ grub_pci_get_device (dev),
+ grub_pci_get_function (dev));
+ pci->dev.pci_dev = dev;
+ pci->priv = 0;
+ pci->drvdata = 0;
+
+ reg = GRUB_PCI_REG_ADDRESSES;
+ while (reg < GRUB_PCI_REG_CIS_POINTER)
+ {
+ grub_uint64_t space;
+ grub_pci_address_t addr;
+
+ addr = grub_pci_make_address (dev, reg);
+ space = grub_pci_read (addr);
+
+ reg += sizeof (grub_uint32_t);
+
+ if (space == 0)
+ continue;
+
+ if ((space & GRUB_PCI_ADDR_SPACE_MASK)
+ == GRUB_PCI_ADDR_SPACE_IO)
+ {
+ pci->ioaddr = space & GRUB_PCI_ADDR_IO_MASK;
+ break;
+ }
+
+ if ((space & GRUB_PCI_ADDR_MEM_TYPE_MASK)
+ == GRUB_PCI_ADDR_MEM_TYPE_64)
+ reg += sizeof (grub_uint32_t);
+ }
+
+ /* No IRQ support yet. */
+ pci->irq = 0;
+ grub_dprintf ("gpxe", "Probing NIC %d:%d.%d\n",
+ grub_pci_get_bus (dev),
+ grub_pci_get_device (dev),
+ grub_pci_get_function (dev));
+ err = nic->probe (pci, id);
+ grub_dprintf ("gpxe", "Nic probe finished with status %d\n", err);
+ }
+ }
+ return 0;
+}
+
+void
+grub_gpxe_register_pci_nic (struct pci_driver *nic)
+{
+ grub_dprintf ("gpxe", "Registering nic\n");
+ grub_pci_iterate (grub_gpxe_pci_nic_init, nic);
+}
+
+/* FIXME: free all resources associated with driver and detach devices. */
+void
+grub_gpxe_unregister_pci_nic (struct pci_driver *nic __attribute__ ((unused)))
+{
+}
diff --git a/debian/grub-extras/disabled/gpxe/wrap/pci.c b/debian/grub-extras/disabled/gpxe/wrap/pci.c
new file mode 100644
index 0000000..90b26c5
--- /dev/null
+++ b/debian/grub-extras/disabled/gpxe/wrap/pci.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * Based in part on pci.c from Etherboot 5.4, by Ken Yap and David
+ * Munro, in turn based on the Linux kernel's PCI implementation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <gpxe/tables.h>
+#include <gpxe/device.h>
+#include <gpxe/pci.h>
+
+/**
+ * Enable PCI device
+ *
+ * @v pci PCI device
+ *
+ * Set device to be a busmaster in case BIOS neglected to do so. Also
+ * adjust PCI latency timer to a reasonable value, 32.
+ */
+void adjust_pci_device ( struct pci_device *pci ) {
+ unsigned short new_command, pci_command;
+ unsigned char pci_latency;
+
+ pci_read_config_word ( pci, PCI_COMMAND, &pci_command );
+ new_command = ( pci_command | PCI_COMMAND_MASTER |
+ PCI_COMMAND_MEM | PCI_COMMAND_IO );
+ if ( pci_command != new_command ) {
+ pci_write_config_word ( pci, PCI_COMMAND, new_command );
+ }
+
+ pci_read_config_byte ( pci, PCI_LATENCY_TIMER, &pci_latency);
+ if ( pci_latency < 32 ) {
+ pci_write_config_byte ( pci, PCI_LATENCY_TIMER, 32);
+ }
+}
diff --git a/debian/grub-extras/disabled/gpxe/wrap/wrap.c b/debian/grub-extras/disabled/gpxe/wrap/wrap.c
new file mode 100644
index 0000000..691e552
--- /dev/null
+++ b/debian/grub-extras/disabled/gpxe/wrap/wrap.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright © 2009 Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+FILE_LICENCE ( BSD2 );
+
+#include <gpxe/wrap.h>
+#include <gpxe/uaccess.h>
+
+void
+memcpy_user (userptr_t dest, off_t dest_off,
+ userptr_t src, off_t src_off, size_t len )
+{
+ grub_memcpy ((void *) dest+dest_off, (void *) src+src_off, len);
+}
+
+userptr_t
+virt_to_user (volatile const void *in)
+{
+ return in;
+}
+
+void
+free_memblock (void *ptr, size_t size __attribute__ ((unused)))
+{
+ grub_free (ptr);
+}
+
+void *
+memchr (void *s, grub_uint8_t c, grub_size_t size)
+{
+ for (;size && *(grub_uint8_t *)s != c; size--, s = (grub_uint8_t *)s + 1);
+ if (size)
+ return s;
+ return NULL;
+}
+
+grub_size_t
+strnlen (char *str, grub_size_t n)
+{
+ grub_size_t r = 0;
+ while (*str && n)
+ {
+ str++;
+ n--;
+ r++;
+ }
+ return r;
+}