[patch 1/3] PCI support (abstract interface)

2006-05-16 Thread vincent guffens
Hello,

Here is a patch to add pci support to grub2.


2006-05-16  Vincent Guffens  [EMAIL PROTECTED]

* drivers/: New directory

* conf/i386-pc.rmk (pkgdata_MODULES): Added pci.mod
to the list of modules.
(DRIVERS_CFLAGS): Added.
(pci_mod_SOURCES): Likewise.
(pci_mod_CFLAGS): Likewise.
(pci_mod_LDFLAGS): Likewise.

* drivers/include/grub/pci.h: New file.
* drivers/include/grub/list.h: Likewise.
* drivers/pci/pci.c: Likewise.


diff -rNu grub2/ChangeLog grub2-pci/ChangeLog
--- grub2/ChangeLog 2006-05-14 22:16:16.0 +0100
+++ grub2-pci/ChangeLog 2006-05-16 21:51:22.0 +0100
@@ -1,3 +1,18 @@
+2006-05-16  Vincent Guffens  [EMAIL PROTECTED]
+
+   * drivers/: New directory.
+
+   * conf/i386-pc.rmk (pkgdata_MODULES): Added pci.mod
+   to the list of modules.
+   (DRIVERS_CFLAGS): Added.
+   (pci_mod_SOURCES): Likewise.
+   (pci_mod_CFLAGS): Likewise.
+   (pci_mod_LDFLAGS): Likewise.
+
+   * drivers/include/grub/pci.h: New file.
+   * drivers/include/grub/list.h: Likewise.
+   * drivers/pci/pci.c: Likewise.
+
 2006-05-14  Yoshinori K. Okuji  [EMAIL PROTECTED]

* kern/i386/pc/startup.S: Include grub/cpu/linux.h instead of
diff -rNu grub2/conf/i386-pc.rmk grub2-pci/conf/i386-pc.rmk
--- grub2/conf/i386-pc.rmk  2006-05-07 19:28:23.0 +0100
+++ grub2-pci/conf/i386-pc.rmk  2006-05-16 21:07:30.0 +0100
@@ -3,6 +3,7 @@
 COMMON_ASFLAGS = -nostdinc -fno-builtin
 COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32
 COMMON_LDFLAGS = -melf_i386 -nostdlib
+DRIVERS_CFLAGS = -Idrivers/include -fno-strict-aliasing

 # Images.
 pkgdata_IMAGES = boot.img diskboot.img kernel.img pxeboot.img
@@ -116,7 +117,7 @@
 pkgdata_MODULES = _chain.mod _linux.mod linux.mod normal.mod \
_multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod  \
vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \
-   videotest.mod play.mod
+   videotest.mod play.mod pci.mod

 # For _chain.mod.
 _chain_mod_SOURCES = loader/i386/pc/chainloader.c
@@ -209,4 +210,9 @@
 videotest_mod_CFLAGS = $(COMMON_CFLAGS)
 videotest_mod_LDFLAGS = $(COMMON_LDFLAGS)

+# For pci.mod
+pci_mod_SOURCES = drivers/pci/pci.c
+pci_mod_CFLAGS = $(COMMON_CFLAGS) $(DRIVERS_CFLAGS)
+pci_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 include $(srcdir)/conf/common.mk
diff -rNu grub2/drivers/include/grub/list.h
grub2-pci/drivers/include/grub/list.h
--- grub2/drivers/include/grub/list.h   1970-01-01 01:00:00.0 +0100
+++ grub2-pci/drivers/include/grub/list.h   2006-05-16 21:10:58.0
+0100
@@ -0,0 +1,86 @@
+/* list.h - A very simple list.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2006  Free Software Foundation, Inc.
+ *
+ *  GRUB 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
+ *  (at your option) 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 GRUB; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+
+/*
+  If you want a list of struct myitem
+  you do
+
+  struct myitem *item_list;
+
+  where myitem MUST have its next pointer as the FIRST field
+
+  and you can then add, delete the EL item,
+  grub_add_list (item_list, el);
+  grub_del_list (item_list, el);
+
+  or call HOOK(item) for each element of the list
+  grub_iterate_list (item_list, hook);
+
+  This brk version will point el to the list item for which
+  HOOK(EL) returns a non-null value
+  grub_iterate_list_brk (item_list, hook, el);
+ */
+
+struct obj {
+  struct obj *next; /* MUST BE FIRST */
+};
+
+#define grub_del_list(list, el) _grub_del_list((struct obj**) list,
(struct obj*) el)
+#define grub_add_list(list, el) _grub_add_list((struct obj**) list,
(struct obj*) el)
+#define grub_find_list(list, el) \
+  (typeof(list)) _grub_find_list((struct obj*) list, (struct obj*) el)
+#define grub_iterate_list(list, func) \
+  {typeof(list) el = list; while (el) {func(el); el=el-next;}}
+#define grub_iterate_list_brk(list, func, it) \
+  {typeof(list) el = list; it = 0; \
+while (el) {if (func(el)) {it = el; break;} el=el-next; }}
+
+static inline struct obj*  _grub_find_list (struct obj *list, struct
obj *el)
+{
+  struct obj *it = list;
+  for (it = list; it; it=it-next)
+  {
+if (it == el) return el;
+  }
+  return 0;
+};
+
+static inline void _grub_add_list (struct obj **list, struct obj *el)
+{
+  if ( (!el) || (_grub_find_list (*list, el)) )
+return;
+
+  el-next = *list;
+  *list = 

[patch 2/3] PCI support (implementation from etherboot)

2006-05-16 Thread vincent guffens
Some directories, other than drivers/include/etherboot/i386 might have
to be created by hand.

2006-05-16  Vincent Guffens  [EMAIL PROTECTED]

* drivers/include/etherboot/: New directory.
* drivers/pci/i386/: Likewise.

* configure.ac (AC_CONFIG_LINKS): Added drivers/include/etherboot/cpu
links.

* conf/i386-pc.rmk (pkgdata_MODULES): Added pci_etherboot.mod
to the list of modules.
(pci_etherboot_mod_SOURCES): Added.
(pci_etherboot_mod_CFLAGS): Likewise.
(pci_etherboot_mod_LDFLAGS): Likewise.

* drivers/include/etherboot/pci_ids.h: New file.
* drivers/include/etherboot/pci_defs.h: Likewise.
* drivers/include/etherboot/i386/io.h: Likewise.
* drivers/include/etherboot/i386/limits.h: Likewise.
* drivers/pci/pci_etherboot.c: Likewise.
* drivers/pci/i386/pci_io.c: Likewise.



diff -rNu grub2-pci/ChangeLog grub2-pci_etherboot/ChangeLog
--- grub2-pci/ChangeLog 2006-05-16 21:51:22.0 +0100
+++ grub2-pci_etherboot/ChangeLog   2006-05-16 21:51:44.0 +0100
@@ -1,5 +1,26 @@
 2006-05-16  Vincent Guffens  [EMAIL PROTECTED]

+   * drivers/include/etherboot/: New directory.
+   * drivers/pci/i386/: Likewise.
+
+   * configure.ac (AC_CONFIG_LINKS): Added drivers/include/etherboot/cpu
+   links.
+
+   * conf/i386-pc.rmk (pkgdata_MODULES): Added pci_etherboot.mod
+   to the list of modules.
+   (pci_etherboot_mod_SOURCES): Added.
+   (pci_etherboot_mod_CFLAGS): Likewise.
+   (pci_etherboot_mod_LDFLAGS): Likewise.
+
+   * drivers/include/etherboot/pci_ids.h: New file.
+   * drivers/include/etherboot/pci_defs.h: Likewise.
+   * drivers/include/etherboot/i386/io.h: Likewise.
+   * drivers/include/etherboot/i386/limits.h: Likewise.
+   * drivers/pci/pci_etherboot.c: Likewise.
+   * drivers/pci/i386/pci_io.c: Likewise.
+
+2006-05-16  Vincent Guffens  [EMAIL PROTECTED]
+
* drivers/: New directory.

* conf/i386-pc.rmk (pkgdata_MODULES): Added pci.mod
Binary files grub2-pci/.ChangeLog.swp and
grub2-pci_etherboot/.ChangeLog.swp differ
diff -rNu grub2-pci/conf/i386-pc.rmk grub2-pci_etherboot/conf/i386-pc.rmk
--- grub2-pci/conf/i386-pc.rmk  2006-05-16 21:07:30.0 +0100
+++ grub2-pci_etherboot/conf/i386-pc.rmk2006-05-16 21:27:03.0 
+0100
@@ -117,7 +117,7 @@
 pkgdata_MODULES = _chain.mod _linux.mod linux.mod normal.mod \
_multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod  \
vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \
-   videotest.mod play.mod pci.mod
+   videotest.mod play.mod pci.mod pci_etherboot.mod

 # For _chain.mod.
 _chain_mod_SOURCES = loader/i386/pc/chainloader.c
@@ -215,4 +215,9 @@
 pci_mod_CFLAGS = $(COMMON_CFLAGS) $(DRIVERS_CFLAGS)
 pci_mod_LDFLAGS = $(COMMON_LDFLAGS)

+# For pci_etherboot.mod
+pci_etherboot_mod_SOURCES = drivers/pci/pci_etherboot.c
drivers/pci/i386/pci_io.c
+pci_etherboot_mod_CFLAGS = $(COMMON_CFLAGS) $(DRIVERS_CFLAGS)
+pci_etherboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 include $(srcdir)/conf/common.mk
diff -rNu grub2-pci/configure.ac grub2-pci_etherboot/configure.ac
--- grub2-pci/configure.ac  2006-05-16 21:53:10.0 +0100
+++ grub2-pci_etherboot/configure.ac2006-05-16 21:53:29.0 +0100
@@ -208,6 +208,7 @@

 # Output files.
 AC_CONFIG_LINKS([include/grub/cpu:include/grub/$host_cpu
+drivers/include/etherboot/cpu:drivers/include/etherboot/$host_cpu
include/grub/machine:include/grub/$host_cpu/$platform])
 AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh])
 AC_CONFIG_FILES([stamp-h], [echo timestamp  stamp-h])
diff -rNu grub2-pci/drivers/include/etherboot/i386/io.h
grub2-pci_etherboot/drivers/include/etherboot/i386/io.h
--- grub2-pci/drivers/include/etherboot/i386/io.h   1970-01-01
01:00:00.0 +0100
+++ grub2-pci_etherboot/drivers/include/etherboot/i386/io.h 2006-05-16
21:31:31.0 +0100
@@ -0,0 +1,206 @@
+/* io.h - Architecture specific input/output functions  */
+/* Imported from Etherboot 5.4.1 */
+
+#ifndefETHERBOOT_IO_H
+#define ETHERBOOT_IO_H
+
+/*
+ * This file contains the definitions for the x86 IO instructions
+ * inb/inw/inl/outb/outw/outl and the string versions of the same
+ * (insb/insw/insl/outsb/outsw/outsl). You can also use pausing
+ * versions of the single-IO instructions (inb_p/inw_p/..).
+ *
+ * This file is not meant to be obfuscating: it's just complicated
+ * to (a) handle it all in a way that makes gcc able to optimize it
+ * as well as possible and (b) trying to avoid writing the same thing
+ * over and over again with slight variations and possibly making a
+ * mistake somewhere.
+ */
+
+/*
+ * Thanks to James van Artsdalen for a better timing-fix than
+ * the two short jumps: using outb's to a nonexistent port seems
+ * to guarantee better timings even on fast machines.
+ *
+ * On the other hand, I'd like to be sure of a 

[patch 3/3] PCI support (simple test driver)

2006-05-16 Thread vincent guffens
And here comes the last part, this test driver detects the ne2000 card
in qemu.



2006-05-16  Vincent Guffens  [EMAIL PROTECTED]

* drivers/net/: New directory.

* conf/i386-pc.rmk (pkgdata_MODULES): Added test_driver.mod
to the list of modules.
(test_driver_mod_SOURCES): Added.
(test_driver_mod_CFLAGS): Likewise.
(test_driver_mod_LDFLAGS): Likewise.

* driver/net/test_driver.c: New file.



diff -rNu grub2-pci_etherboot/ChangeLog grub2-pci_test_driver/ChangeLog
--- grub2-pci_etherboot/ChangeLog   2006-05-16 21:51:44.0 +0100
+++ grub2-pci_test_driver/ChangeLog 2006-05-16 21:52:08.0 +0100
@@ -1,5 +1,17 @@
 2006-05-16  Vincent Guffens  [EMAIL PROTECTED]

+   * drivers/net/: New directory.
+
+   * conf/i386-pc.rmk (pkgdata_MODULES): Added test_driver.mod
+   to the list of modules.
+   (test_driver_mod_SOURCES): Added.
+   (test_driver_mod_CFLAGS): Likewise.
+   (test_driver_mod_LDFLAGS): Likewise.
+
+   * driver/net/test_driver.c: New file.
+   
+2006-05-16  Vincent Guffens  [EMAIL PROTECTED]
+
* drivers/include/etherboot/: New directory.
* drivers/pci/i386/: Likewise.

diff -rNu grub2-pci_etherboot/conf/i386-pc.rmk
grub2-pci_test_driver/conf/i386-pc.rmk
--- grub2-pci_etherboot/conf/i386-pc.rmk2006-05-16 21:27:03.0 
+0100
+++ grub2-pci_test_driver/conf/i386-pc.rmk  2006-05-16 21:39:54.0
+0100
@@ -117,7 +117,8 @@
 pkgdata_MODULES = _chain.mod _linux.mod linux.mod normal.mod \
_multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod  \
vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \
-   videotest.mod play.mod pci.mod pci_etherboot.mod
+   videotest.mod play.mod pci.mod pci_etherboot.mod \
+test_driver.mod

 # For _chain.mod.
 _chain_mod_SOURCES = loader/i386/pc/chainloader.c
@@ -220,4 +221,9 @@
 pci_etherboot_mod_CFLAGS = $(COMMON_CFLAGS) $(DRIVERS_CFLAGS)
 pci_etherboot_mod_LDFLAGS = $(COMMON_LDFLAGS)

+# For test_driver.mod
+test_driver_mod_SOURCES = drivers/net/test_driver.c
+test_driver_mod_CFLAGS = $(COMMON_CFLAGS) $(DRIVERS_CFLAGS)
+test_driver_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 include $(srcdir)/conf/common.mk
diff -rNu grub2-pci_etherboot/drivers/net/test_driver.c
grub2-pci_test_driver/drivers/net/test_driver.c
--- grub2-pci_etherboot/drivers/net/test_driver.c   1970-01-01
01:00:00.0 +0100
+++ grub2-pci_test_driver/drivers/net/test_driver.c 2006-05-16
21:40:07.0 +0100
@@ -0,0 +1,40 @@
+#include grub/pci.h
+#include grub/dl.h
+#include grub/normal.h
+#include grub/err.h
+#include etherboot/pci_ids.h
+
+static grub_err_t
+test_driver_probe (grub_pci_device_t pdev __attribute__((unused)))
+{
+  /* Whah! if it was always so simple.  */
+  return GRUB_ERR_NONE;
+}
+
+static struct grub_pci_ids test_driver_ids[] =
+{
+  {0x10ec, 0x8029, realtek 8029 test},
+  {0x1186, 0x0300, dlink-528},
+};
+
+static struct grub_pci_driver test_driver =
+{
+  .next = 0,
+  .type = GRUB_NET_ETHERNET,
+  .name = Test driver,
+  .probe = test_driver_probe,
+  .ids = test_driver_ids,
+  .id_count = sizeof(test_driver_ids)/sizeof(test_driver_ids[0]),
+  .class = 0, /* could be PCI_CLASS_NETWORK_ETHERNET
+  for generic drivers */
+};
+
+GRUB_MOD_INIT(test_driver)
+{
+  grub_register_pci_driver (test_driver);
+}
+
+GRUB_MOD_FINI(test_driver)
+{
+  grub_unregister_pci_driver (test_driver);
+}


___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel