[OpenBIOS] [PATCH 3/6] pci: add basic support for Apple SunGEM

Mark Cave-Ayland mark.cave-ayland at ilande.co.uk
Wed Sep 6 21:21:38 CEST 2017


No driver, but we read the MAC address from the chip and write
it into the device-tree where Linux and MacOS look for it. We
also set the right compatible property for MacOS to pick it up.

Signed-off-by: Benjamin Herrenschmidt <benh at kernel.crashing.org>
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
 drivers/pci.c          |   29 +++++++++++++++++++++++++++++
 drivers/pci_database.c |    6 ++++++
 drivers/pci_database.h |    1 +
 include/drivers/pci.h  |    1 +
 4 files changed, 37 insertions(+)

diff --git a/drivers/pci.c b/drivers/pci.c
index e16ce3c..f45e743 100644
--- a/drivers/pci.c
+++ b/drivers/pci.c
@@ -685,6 +685,35 @@ int rtl8139_config_cb(const pci_config_t *config)
 	return eth_config_cb(config);
 }
 
+int sungem_config_cb (const pci_config_t *config)
+{
+	phandle_t ph = get_cur_dev();
+	uint32_t val, *mmio;
+	uint8_t mac[6];
+	ucell virt;
+
+#define MAC_ADDR0	(0x6080UL/4)	/* MAC Address 0 Register	*/
+#define MAC_ADDR1	(0x6084UL/4)	/* MAC Address 1 Register	*/
+#define MAC_ADDR2	(0x6088UL/4)	/* MAC Address 2 Register	*/
+
+	/* Map PCI memory BAR 0 to access the sungem registers */
+	virt = ob_pci_map(config->assigned[0], 0x8000);
+	mmio = (void *)(uintptr_t)virt;
+	
+	val = __le32_to_cpu(*(mmio + MAC_ADDR0));
+	mac[5] = val & 0xff;
+	mac[4] = (val >> 8) & 0xff;
+	val = __le32_to_cpu(*(mmio + MAC_ADDR1));
+	mac[3] = val & 0xff;
+	mac[2] = (val >> 8) & 0xff;
+	val = __le32_to_cpu(*(mmio + MAC_ADDR2));
+	mac[1] = val & 0xff;
+	mac[0] = (val >> 8) & 0xff;
+	set_property(ph, "local-mac-address", (char *)mac, 6);
+	
+	return 0;
+}
+
 /*
  * "Designing PCI Cards and Drivers for Power Macintosh Computers", p. 454
  *
diff --git a/drivers/pci_database.c b/drivers/pci_database.c
index 3155ee3..c685540 100644
--- a/drivers/pci_database.c
+++ b/drivers/pci_database.c
@@ -135,6 +135,12 @@ static const pci_dev_t eth_devices[] = {
         rtl8139_config_cb, "ethernet",
     },
     {
+        PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_GMAC,
+        NULL, "ethernet", NULL,  "gmac\0",
+        0, 0, 0,
+        sungem_config_cb, "ethernet",
+    },
+    {
         /* Virtio-network controller */
         PCI_VENDOR_ID_REDHAT_QUMRANET, PCI_DEVICE_ID_VIRTIO_NET,
         NULL, "virtio-net", NULL,
diff --git a/drivers/pci_database.h b/drivers/pci_database.h
index 241bac3..53eadbd 100644
--- a/drivers/pci_database.h
+++ b/drivers/pci_database.h
@@ -41,6 +41,7 @@ extern int ebus_config_cb(const pci_config_t *config);
 extern int i82378_config_cb(const pci_config_t *config);
 extern int usb_ohci_config_cb(const pci_config_t *config);
 extern int rtl8139_config_cb(const pci_config_t *config);
+extern int sungem_config_cb (const pci_config_t *config);
 
 static inline int pci_compat_len(const pci_dev_t *dev)
 {
diff --git a/include/drivers/pci.h b/include/drivers/pci.h
index e9f20a1..c03268c 100644
--- a/include/drivers/pci.h
+++ b/include/drivers/pci.h
@@ -202,6 +202,7 @@ extern const pci_arch_t *arch;
 #define PCI_DEVICE_ID_APPLE_UNI_N_I_PCI  0x001e
 #define PCI_DEVICE_ID_APPLE_UNI_N_PCI    0x001f
 #define PCI_DEVICE_ID_APPLE_UNI_N_AGP    0x0020
+#define PCI_DEVICE_ID_APPLE_UNI_N_GMAC   0x0021
 #define PCI_DEVICE_ID_APPLE_UNI_N_KEYL   0x0022
 #define PCI_DEVICE_ID_APPLE_KEYL_USB     0x003f
 #define PCI_DEVICE_ID_APPLE_U3_AGP       0x004b
-- 
1.7.10.4




More information about the OpenBIOS mailing list