hailfinger | 8a0f84b | 2010-05-21 22:28:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2009 Joerg Fischer <turboj@gmx.de> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
hailfinger | 324a9cc | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 21 | #if defined(__i386__) || defined(__x86_64__) |
| 22 | |
hailfinger | 8a0f84b | 2010-05-21 22:28:19 +0000 | [diff] [blame] | 23 | #include <stdlib.h> |
hailfinger | 8a0f84b | 2010-05-21 22:28:19 +0000 | [diff] [blame] | 24 | #include "flash.h" |
hailfinger | 428f685 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 25 | #include "programmer.h" |
hailfinger | 8a0f84b | 2010-05-21 22:28:19 +0000 | [diff] [blame] | 26 | |
| 27 | #define PCI_VENDOR_ID_REALTEK 0x10ec |
| 28 | #define PCI_VENDOR_ID_SMC1211 0x1113 |
| 29 | |
| 30 | #define BIOS_ROM_ADDR 0xD4 |
| 31 | #define BIOS_ROM_DATA 0xD7 |
| 32 | |
Patrick Georgi | 8ae1657 | 2017-03-09 15:59:25 +0100 | [diff] [blame] | 33 | const struct dev_entry nics_realtek[] = { |
uwe | ae6a69a | 2010-05-24 17:39:14 +0000 | [diff] [blame] | 34 | {0x10ec, 0x8139, OK, "Realtek", "RTL8139/8139C/8139C+"}, |
uwe | ae6a69a | 2010-05-24 17:39:14 +0000 | [diff] [blame] | 35 | {0x1113, 0x1211, OK, "SMC2", "1211TX"}, /* RTL8139 clone */ |
Patrick Georgi | 8ddfee9 | 2017-03-20 14:54:28 +0100 | [diff] [blame] | 36 | {0}, |
hailfinger | 8a0f84b | 2010-05-21 22:28:19 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
Patrick Georgi | d4caa6b | 2017-03-28 21:22:55 +0200 | [diff] [blame^] | 39 | static void nicrealtek_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr); |
| 40 | static uint8_t nicrealtek_chip_readb(const struct flashctx *flash, const chipaddr addr); |
Patrick Georgi | 0a9533a | 2017-02-03 19:28:38 +0100 | [diff] [blame] | 41 | static const struct par_master par_master_nicrealtek = { |
hailfinger | 76bb7e9 | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 42 | .chip_readb = nicrealtek_chip_readb, |
| 43 | .chip_readw = fallback_chip_readw, |
| 44 | .chip_readl = fallback_chip_readl, |
| 45 | .chip_readn = fallback_chip_readn, |
| 46 | .chip_writeb = nicrealtek_chip_writeb, |
| 47 | .chip_writew = fallback_chip_writew, |
| 48 | .chip_writel = fallback_chip_writel, |
| 49 | .chip_writen = fallback_chip_writen, |
| 50 | }; |
| 51 | |
David Hendricks | 93784b4 | 2016-08-09 17:00:38 -0700 | [diff] [blame] | 52 | static int nicrealtek_shutdown(void *data) |
dhendrix | 0ffc2eb | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 53 | { |
| 54 | /* FIXME: We forgot to disable software access again. */ |
dhendrix | 0ffc2eb | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 55 | return 0; |
| 56 | } |
| 57 | |
David Hendricks | ac1d25c | 2016-08-09 17:00:58 -0700 | [diff] [blame] | 58 | int nicrealtek_init(void) |
hailfinger | 8a0f84b | 2010-05-21 22:28:19 +0000 | [diff] [blame] | 59 | { |
Patrick Georgi | 2a2d67f | 2017-03-09 10:15:39 +0100 | [diff] [blame] | 60 | if (rget_io_perms()) |
| 61 | return 1; |
uwe | ae6a69a | 2010-05-24 17:39:14 +0000 | [diff] [blame] | 62 | |
hailfinger | 0d703d4 | 2011-03-07 01:08:09 +0000 | [diff] [blame] | 63 | io_base_addr = pcidev_init(PCI_BASE_ADDRESS_0, nics_realtek); |
uwe | ae6a69a | 2010-05-24 17:39:14 +0000 | [diff] [blame] | 64 | |
dhendrix | 0ffc2eb | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 65 | if (register_shutdown(nicrealtek_shutdown, NULL)) |
| 66 | return 1; |
hailfinger | 76bb7e9 | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 67 | |
Patrick Georgi | 0a9533a | 2017-02-03 19:28:38 +0100 | [diff] [blame] | 68 | register_par_master(&par_master_nicrealtek, BUS_PARALLEL); |
hailfinger | 76bb7e9 | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 69 | |
hailfinger | 8a0f84b | 2010-05-21 22:28:19 +0000 | [diff] [blame] | 70 | return 0; |
| 71 | } |
| 72 | |
Patrick Georgi | d4caa6b | 2017-03-28 21:22:55 +0200 | [diff] [blame^] | 73 | static void nicrealtek_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr) |
hailfinger | 8a0f84b | 2010-05-21 22:28:19 +0000 | [diff] [blame] | 74 | { |
hailfinger | 6ee8beb | 2010-06-14 14:18:37 +0000 | [diff] [blame] | 75 | /* Output addr and data, set WE to 0, set OE to 1, set CS to 0, |
| 76 | * enable software access. |
| 77 | */ |
uwe | ae6a69a | 2010-05-24 17:39:14 +0000 | [diff] [blame] | 78 | OUTL(((uint32_t)addr & 0x01FFFF) | 0x0A0000 | (val << 24), |
| 79 | io_base_addr + BIOS_ROM_ADDR); |
hailfinger | 6ee8beb | 2010-06-14 14:18:37 +0000 | [diff] [blame] | 80 | /* Output addr and data, set WE to 1, set OE to 1, set CS to 1, |
| 81 | * enable software access. |
| 82 | */ |
uwe | ae6a69a | 2010-05-24 17:39:14 +0000 | [diff] [blame] | 83 | OUTL(((uint32_t)addr & 0x01FFFF) | 0x1E0000 | (val << 24), |
| 84 | io_base_addr + BIOS_ROM_ADDR); |
hailfinger | 8a0f84b | 2010-05-21 22:28:19 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Patrick Georgi | d4caa6b | 2017-03-28 21:22:55 +0200 | [diff] [blame^] | 87 | static uint8_t nicrealtek_chip_readb(const struct flashctx *flash, const chipaddr addr) |
hailfinger | 8a0f84b | 2010-05-21 22:28:19 +0000 | [diff] [blame] | 88 | { |
uwe | ae6a69a | 2010-05-24 17:39:14 +0000 | [diff] [blame] | 89 | uint8_t val; |
hailfinger | 8a0f84b | 2010-05-21 22:28:19 +0000 | [diff] [blame] | 90 | |
hailfinger | 6ee8beb | 2010-06-14 14:18:37 +0000 | [diff] [blame] | 91 | /* FIXME: Can we skip reading the old data and simply use 0? */ |
| 92 | /* Read old data. */ |
uwe | ae6a69a | 2010-05-24 17:39:14 +0000 | [diff] [blame] | 93 | val = INB(io_base_addr + BIOS_ROM_DATA); |
hailfinger | 6ee8beb | 2010-06-14 14:18:37 +0000 | [diff] [blame] | 94 | /* Output new addr and old data, set WE to 1, set OE to 0, set CS to 0, |
| 95 | * enable software access. |
| 96 | */ |
uwe | ae6a69a | 2010-05-24 17:39:14 +0000 | [diff] [blame] | 97 | OUTL(((uint32_t)addr & 0x01FFFF) | 0x060000 | (val << 24), |
| 98 | io_base_addr + BIOS_ROM_ADDR); |
| 99 | |
hailfinger | 6ee8beb | 2010-06-14 14:18:37 +0000 | [diff] [blame] | 100 | /* Read new data. */ |
uwe | ae6a69a | 2010-05-24 17:39:14 +0000 | [diff] [blame] | 101 | val = INB(io_base_addr + BIOS_ROM_DATA); |
hailfinger | 6ee8beb | 2010-06-14 14:18:37 +0000 | [diff] [blame] | 102 | /* Output addr and new data, set WE to 1, set OE to 1, set CS to 1, |
| 103 | * enable software access. |
| 104 | */ |
uwe | ae6a69a | 2010-05-24 17:39:14 +0000 | [diff] [blame] | 105 | OUTL(((uint32_t)addr & 0x01FFFF) | 0x1E0000 | (val << 24), |
| 106 | io_base_addr + BIOS_ROM_ADDR); |
| 107 | |
| 108 | return val; |
hailfinger | 8a0f84b | 2010-05-21 22:28:19 +0000 | [diff] [blame] | 109 | } |
hailfinger | 324a9cc | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 110 | |
| 111 | #else |
| 112 | #error PCI port I/O access is not supported on this architecture yet. |
| 113 | #endif |