PERFORCE change 189640 for review
John Baldwin
jhb at FreeBSD.org
Mon Mar 7 02:15:34 UTC 2011
http://p4web.freebsd.org/@@189640?ac=10
Change 189640 by jhb at jhb_fiver on 2011/03/07 02:14:38
More hacking. Still need to fix resume.
Affected files ...
.. //depot/projects/pci/sys/dev/pci/pci.c#4 edit
Differences ...
==== //depot/projects/pci/sys/dev/pci/pci.c#4 (text+ko) ====
@@ -2373,25 +2373,8 @@
return (pci_read_config(dev, PCIR_COMMAND, 2) & PCIM_CMD_MEMEN) != 0;
}
-static pci_addr_t
-pci_read_bar(device_t dev, int reg)
-{
- pci_addr_t map;
- int ln2range;
-
- /* The device ROM BAR is always a 32-bit memory BAR. */
- if (reg == PCIR_BIOS)
- return (pci_read_config(dev, PCIR_BIOS, 4));
-
- map = pci_read_config(dev, reg, 4);
- ln2range = pci_maprange(map);
- if (ln2range == 64)
- map |= (pci_addr_t)pci_read_config(dev, reg + 4, 4) << 32;
- return (map);
-}
-
static void
-pci_size_bar(device_t dev, int reg, pci_addr_t *mapp, pci_addr_t *testvalp)
+pci_read_bar(device_t dev, int reg, pci_addr_t *mapp, pci_addr_t *testvalp)
{
pci_addr_t map, testval;
int ln2range;
@@ -2455,19 +2438,19 @@
static void
pci_write_bar(device_t dev, struct pci_map *pm, pci_addr_t base)
{
- struct pci_map *pm;
- pci_addr_t map;
int ln2range;
- map = pci_read_config(dev, reg, 4);
-
- /* The device ROM BAR is always 32-bits. */
- if (reg == PCIR_BIOS)
- return;
- ln2range = pci_maprange(map);
- pci_write_config(dev, reg, base, 4);
+ /* The device ROM BAR is always a 32-bit memory BAR. */
+ if (pm->pm_reg == PCIR_BIOS)
+ ln2range = 32;
+ else
+ ln2range = pci_maprange(pm->pm_value);
+ pci_write_config(dev, pm->pm_reg, base, 4);
+ if (ln2range == 64)
+ pci_write_config(dev, pm->pm_reg + 4, base >> 32, 4);
+ pm->pm_value = pci_read_config(dev, pm->pm_reg, 4);
if (ln2range == 64)
- pci_write_config(dev, reg + 4, base >> 32, 4);
+ pm->pm_value |= (pci_addr_t)pci_read_config(dev, pm->pm_reg + 4, 4) << 32;
}
struct pci_map *
@@ -2489,11 +2472,17 @@
{
uint16_t cmd;
- if (pm->
+ if (pm->pm_reg == PCIR_BIOS && !(pm->pm_value & PCIM_BIOS_ENABLE))
+ return (0);
+ cmd = pci_read_config(dev, PCIR_COMMAND, 2);
+ if (pm->pm_reg == PCIR_BIOS || PCI_BAR_MEM(pm->pm_value))
+ return ((cmd & PCIM_CMD_MEMEN) != 0);
+ else
+ return ((cmd & PCIM_CMD_PORTEN) != 0);
}
struct pci_map *
-pci_add_bar(device_t dev, int reg)
+pci_add_bar(device_t dev, int reg, pci_addr_t value, pci_addr_t size)
{
struct pci_devinfo *dinfo;
struct pci_map *pm, *prev;
@@ -2501,6 +2490,8 @@
dinfo = device_get_ivars(dev);
pm = malloc(sizeof(*pm), M_DEVBUF, M_WAITOK | M_ZERO);
pm->pm_reg = reg;
+ pm->pm_value = value;
+ pm->pm_size = size;
STAILQ_FOREACH(prev, &dinfo->cfg.maps, pm_link) {
KASSERT(prev->pm_reg != pm->pm_reg, ("duplicate map %02x",
reg));
@@ -2530,7 +2521,7 @@
uint16_t cmd;
struct resource *res;
- pci_size_bar(dev, reg, &map, &testval);
+ pci_read_bar(dev, reg, &map, &testval);
if (PCI_BAR_MEM(map)) {
type = SYS_RES_MEMORY;
if (map & PCIM_BAR_MEM_PREFETCH)
@@ -2561,9 +2552,7 @@
return (barlen);
/* Save a record of this BAR. */
- pm = pci_add_bar(dev, reg);
- pm->pm_value = map;
- pm->pm_size = mapsize;
+ pm = pci_add_bar(dev, reg, map, mapsize);
if (bootverbose) {
printf("\tmap[%02x]: type %s, range %2d, base %#jx, size %2d",
reg, pci_maptype(map), maprange, (uintmax_t)base, mapsize);
@@ -2649,12 +2638,9 @@
*/
resource_list_delete(rl, type, reg);
start = 0;
- } else {
+ } else
start = rman_get_start(res);
- pm->pm_enabled = 1;
- }
- pci_write_bar(dev, reg, start);
- pm->pm_value = pm_read_bar(dev, reg);
+ pci_write_bar(dev, pm, start);
return (barlen);
}
@@ -3799,7 +3785,7 @@
if (pm != NULL) {
/* This is a BAR that we failed to allocate earlier. */
mapsize = pm->pm_size;
- map = pci_read_bar(child, *rid);
+ map = pm->pm_value;
} else {
/*
* Weed out the bogons, and figure out how large the
@@ -3809,7 +3795,7 @@
* have a atapci device in legacy mode and it fails
* here, that other code is broken.
*/
- pci_size_bar(child, *rid, &map, &testval);
+ pci_read_bar(child, *rid, &map, &testval);
/*
* Determine the size of the BAR and ignore BARs with a size
@@ -3821,9 +3807,7 @@
mapsize = pci_mapsize(testval);
if (mapsize == 0)
goto out;
- pm = pci_add_bar(child, *rid);
- pm->pm_value = map;
- pm->pm_size = mapsize;
+ pm = pci_add_bar(child, *rid, map, mapsize);
}
if (PCI_BAR_MEM(map) || *rid == PCIR_BIOS) {
@@ -3885,8 +3869,7 @@
"Lazy allocation of %#lx bytes rid %#x type %d at %#lx\n",
count, *rid, type, rman_get_start(res));
map = rman_get_start(res);
- pci_write_bar(child, *rid, map);
- pm->pm_value = pci_read_bar(child, *rid);
+ pci_write_bar(child, pm, map);
out:;
return (res);
}
@@ -3947,7 +3930,6 @@
pci_activate_resource(device_t dev, device_t child, int type, int rid,
struct resource *r)
{
- struct pci_map *pm;
int error;
error = bus_generic_activate_resource(dev, child, type, rid, r);
@@ -3957,12 +3939,9 @@
/* Enable decoding in the command register when activating BARs. */
if (device_get_parent(child) == dev) {
/* Device ROMs need their decoding explicitly enabled. */
- if (rid == PCIR_BIOS) {
- pm = pci_get_bar(child, PCIR_BIOS);
- pm->pm_enabled = 1;
- pci_write_config(child, PCIR_BIOS, rman_get_start(r) |
- PCIM_BIOS_ENABLE, 4);
- }
+ if (rid == PCIR_BIOS)
+ pci_write_bar(child, pci_get_bar(child, PCIR_BIOS),
+ rman_get_start(r) | PCIM_BIOS_ENABLE);
switch (type) {
case SYS_RES_IOPORT:
case SYS_RES_MEMORY:
@@ -3977,6 +3956,7 @@
pci_deactivate_resource(device_t dev, device_t child, int type,
int rid, struct resource *r)
{
+ struct pci_map *pm;
int error;
error = bus_generic_deactivate_resource(dev, child, type, rid, r);
@@ -3984,11 +3964,8 @@
return (error);
/* Disable decoding for device ROMs. */
- if (rid == PCIR_BIOS) {
- pci_write_config(child, PCIR_BIOS, rman_get_start(r), 4);
- pm = pci_read_bar(child, PCIR_BIOS);
- pm->pm_enabled = 0;
- }
+ if (rid == PCIR_BIOS)
+ pci_write_bar(child, pci_get_bar(child, PCIR_BIOS), rman_get_start(r));
return (0);
}
@@ -4066,7 +4043,7 @@
switch (type) {
case SYS_RES_IOPORT:
case SYS_RES_MEMORY:
- pci_write_bar(child, rid, 0);
+ pci_write_bar(child, pci_get_bar(child, rid), 0);
break;
}
#endif
More information about the p4-projects
mailing list