blob: 0ad9f25ea145901a67835f00ec2125206f3d69c0 [file] [log] [blame]
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2011 Carl-Daniel Hailfinger
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; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000014 */
15
16/* Datasheet: http://download.intel.com/design/network/datashts/82559_Fast_Ethernet_Multifunction_PCI_Cardbus_Controller_Datasheet.pdf */
17
18#include <stdlib.h>
19#include "flash.h"
20#include "programmer.h"
Patrick Georgi32508eb2012-07-20 20:35:14 +000021#include "hwaccess.h"
Thomas Heijligena0655202021-12-14 16:36:05 +010022#include "hwaccess_x86_io.h"
Thomas Heijligen74b4aa02021-12-14 17:52:30 +010023#include "hwaccess_physmap.h"
Thomas Heijligend96c97c2021-11-02 21:03:00 +010024#include "platform/pci.h"
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000025
Jacob Garberafc3ad62019-06-24 16:05:28 -060026static uint8_t *nicintel_bar;
27static uint8_t *nicintel_control_bar;
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000028
Thomas Heijligencc853d82021-05-04 15:32:17 +020029static const struct dev_entry nics_intel[] = {
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000030 {PCI_VENDOR_ID_INTEL, 0x1209, NT, "Intel", "8255xER/82551IT Fast Ethernet Controller"},
Sylvain "ythier" Hitier3093f8f2011-09-03 11:22:27 +000031 {PCI_VENDOR_ID_INTEL, 0x1229, OK, "Intel", "82557/8/9/0/1 Ethernet Pro 100"},
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000032
Carl-Daniel Hailfinger1c6d2ff2012-08-27 00:44:42 +000033 {0},
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000034};
35
36/* Arbitrary limit, taken from the datasheet I just had lying around.
37 * 128 kByte on the 82559 device. Or not. Depends on whom you ask.
38 */
39#define NICINTEL_MEMMAP_SIZE (128 * 1024)
40#define NICINTEL_MEMMAP_MASK (NICINTEL_MEMMAP_SIZE - 1)
41
Elyes HAOUAS124ef382018-03-27 12:15:09 +020042#define NICINTEL_CONTROL_MEMMAP_SIZE 0x10
David Hendricks8bb20212011-06-14 01:35:36 +000043
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000044#define CSR_FCR 0x0c
45
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000046static void nicintel_chip_writeb(const struct flashctx *flash, uint8_t val,
47 chipaddr addr);
48static uint8_t nicintel_chip_readb(const struct flashctx *flash,
49 const chipaddr addr);
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000050static const struct par_master par_master_nicintel = {
Thomas Heijligen43040f22022-06-23 14:38:35 +020051 .chip_readb = nicintel_chip_readb,
52 .chip_readw = fallback_chip_readw,
53 .chip_readl = fallback_chip_readl,
54 .chip_readn = fallback_chip_readn,
55 .chip_writeb = nicintel_chip_writeb,
56 .chip_writew = fallback_chip_writew,
57 .chip_writel = fallback_chip_writel,
58 .chip_writen = fallback_chip_writen,
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +000059};
60
Thomas Heijligencc853d82021-05-04 15:32:17 +020061static int nicintel_init(void)
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000062{
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +000063 struct pci_dev *dev = NULL;
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000064 uintptr_t addr;
65
66 /* Needed only for PCI accesses on some platforms.
Carl-Daniel Hailfingerd6bb8282012-07-21 17:27:08 +000067 * FIXME: Refactor that into get_mem_perms/rget_io_perms/get_pci_perms?
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000068 */
Carl-Daniel Hailfingerd6bb8282012-07-21 17:27:08 +000069 if (rget_io_perms())
70 return 1;
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000071
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +000072 /* FIXME: BAR2 is not available if the device uses the CardBus function. */
73 dev = pcidev_init(nics_intel, PCI_BASE_ADDRESS_2);
74 if (!dev)
75 return 1;
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000076
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +000077 addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_2);
Niklas Söderlund89edf362013-08-23 23:29:23 +000078 if (!addr)
79 return 1;
80
Stefan Tauner7fb5aa02013-08-14 15:48:44 +000081 nicintel_bar = rphysmap("Intel NIC flash", addr, NICINTEL_MEMMAP_SIZE);
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000082 if (nicintel_bar == ERROR_PTR)
Stefan Tauner7fb5aa02013-08-14 15:48:44 +000083 return 1;
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000084
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +000085 addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_0);
Niklas Söderlund89edf362013-08-23 23:29:23 +000086 if (!addr)
87 return 1;
88
Stefan Tauner7fb5aa02013-08-14 15:48:44 +000089 nicintel_control_bar = rphysmap("Intel NIC control/status reg", addr, NICINTEL_CONTROL_MEMMAP_SIZE);
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000090 if (nicintel_control_bar == ERROR_PTR)
David Hendricks8bb20212011-06-14 01:35:36 +000091 return 1;
92
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000093 /* FIXME: This register is pretty undocumented in all publicly available
94 * documentation from Intel. Let me quote the complete info we have:
95 * "Flash Control Register: The Flash Control register allows the CPU to
96 * enable writes to an external Flash. The Flash Control Register is a
97 * 32-bit field that allows access to an external Flash device."
98 * Ah yes, we also know where it is, but we have absolutely _no_ idea
99 * what we should do with it. Write 0x0001 because we have nothing
100 * better to do with our time.
101 */
102 pci_rmmio_writew(0x0001, nicintel_control_bar + CSR_FCR);
103
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000104 max_rom_decode.parallel = NICINTEL_MEMMAP_SIZE;
Anastasia Klimchukc1f2a472021-08-27 15:47:46 +1000105 return register_par_master(&par_master_nicintel, BUS_PARALLEL, NULL);
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000106}
107
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000108static void nicintel_chip_writeb(const struct flashctx *flash, uint8_t val,
109 chipaddr addr)
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000110{
111 pci_mmio_writeb(val, nicintel_bar + (addr & NICINTEL_MEMMAP_MASK));
112}
113
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000114static uint8_t nicintel_chip_readb(const struct flashctx *flash,
115 const chipaddr addr)
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000116{
117 return pci_mmio_readb(nicintel_bar + (addr & NICINTEL_MEMMAP_MASK));
118}
Thomas Heijligencc853d82021-05-04 15:32:17 +0200119
120const struct programmer_entry programmer_nicintel = {
121 .name = "nicintel",
122 .type = PCI,
123 .devs.dev = nics_intel,
124 .init = nicintel_init,
125 .map_flash_region = fallback_map,
126 .unmap_flash_region = fallback_unmap,
127 .delay = internal_delay,
128};