summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2020-10-28 10:27:22 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2020-10-28 10:27:22 +0000
commit8c82e671ad4850987fa05ae5cf722f876b787809 (patch)
tree0c2d953b22af2ca0d933c3b9da1d05e416b13496
parent71489e6eaf3fa3d105804f36882a34e72ec59be3 (diff)
Use the function from <linux/io.h> for all "Memory Space" IO. This reduces
the diffs to Linux and makes sure we use memory barriers in the same way as Linux does. ok jsg@ (who added the doorbell changes)
-rw-r--r--sys/dev/pci/drm/radeon/cik.c4
-rw-r--r--sys/dev/pci/drm/radeon/r100.c12
-rw-r--r--sys/dev/pci/drm/radeon/radeon.h18
-rw-r--r--sys/dev/pci/drm/radeon/radeon_device.c4
-rw-r--r--sys/dev/pci/drm/radeon/radeon_kms.c7
5 files changed, 21 insertions, 24 deletions
diff --git a/sys/dev/pci/drm/radeon/cik.c b/sys/dev/pci/drm/radeon/cik.c
index 395583ca78b..91dda321cde 100644
--- a/sys/dev/pci/drm/radeon/cik.c
+++ b/sys/dev/pci/drm/radeon/cik.c
@@ -1737,7 +1737,7 @@ u32 cik_get_xclk(struct radeon_device *rdev)
u32 cik_mm_rdoorbell(struct radeon_device *rdev, u32 index)
{
if (index < rdev->doorbell.num_doorbells) {
- return bus_space_read_4(rdev->memt, rdev->doorbell.bsh, index * 4);
+ return readl(rdev->doorbell.ptr + index);
} else {
DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
return 0;
@@ -1757,7 +1757,7 @@ u32 cik_mm_rdoorbell(struct radeon_device *rdev, u32 index)
void cik_mm_wdoorbell(struct radeon_device *rdev, u32 index, u32 v)
{
if (index < rdev->doorbell.num_doorbells) {
- bus_space_write_4(rdev->memt, rdev->doorbell.bsh, index * 4, v);
+ writel(v, rdev->doorbell.ptr + index);
} else {
DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
}
diff --git a/sys/dev/pci/drm/radeon/r100.c b/sys/dev/pci/drm/radeon/r100.c
index 14c780ba740..3760c1f0de8 100644
--- a/sys/dev/pci/drm/radeon/r100.c
+++ b/sys/dev/pci/drm/radeon/r100.c
@@ -4117,10 +4117,8 @@ uint32_t r100_mm_rreg_slow(struct radeon_device *rdev, uint32_t reg)
uint32_t ret;
spin_lock_irqsave(&rdev->mmio_idx_lock, flags);
- bus_space_write_4(rdev->memt, rdev->rmmio_bsh,
- RADEON_MM_INDEX, reg);
- ret = bus_space_read_4(rdev->memt, rdev->rmmio_bsh,
- RADEON_MM_DATA);
+ writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
+ ret = readl(((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
spin_unlock_irqrestore(&rdev->mmio_idx_lock, flags);
return ret;
}
@@ -4130,10 +4128,8 @@ void r100_mm_wreg_slow(struct radeon_device *rdev, uint32_t reg, uint32_t v)
unsigned long flags;
spin_lock_irqsave(&rdev->mmio_idx_lock, flags);
- bus_space_write_4(rdev->memt, rdev->rmmio_bsh,
- RADEON_MM_INDEX, reg);
- bus_space_write_4(rdev->memt, rdev->rmmio_bsh,
- RADEON_MM_DATA, v);
+ writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
+ writel(v, ((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
spin_unlock_irqrestore(&rdev->mmio_idx_lock, flags);
}
diff --git a/sys/dev/pci/drm/radeon/radeon.h b/sys/dev/pci/drm/radeon/radeon.h
index a3914affc61..7290910f10e 100644
--- a/sys/dev/pci/drm/radeon/radeon.h
+++ b/sys/dev/pci/drm/radeon/radeon.h
@@ -737,6 +737,7 @@ struct radeon_doorbell {
/* doorbell mmio */
resource_size_t base;
resource_size_t size;
+ u32 __iomem *ptr;
bus_space_handle_t bsh;
u32 num_doorbells; /* Number of doorbells actually reserved for radeon. */
DECLARE_BITMAP(used, RADEON_MAX_DOORBELLS);
@@ -2399,6 +2400,7 @@ struct radeon_device {
/* protects concurrent ENDPOINT (audio) register access */
spinlock_t end_idx_lock;
bus_space_handle_t rmmio_bsh;
+ void __iomem *rmmio;
radeon_rreg_t mc_rreg;
radeon_wreg_t mc_wreg;
radeon_rreg_t pll_rreg;
@@ -2515,7 +2517,7 @@ static inline uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg,
{
/* The mmio size is 64kb at minimum. Allows the if to be optimized out. */
if ((reg < rdev->rmmio_size || reg < RADEON_MIN_MMIO_SIZE) && !always_indirect)
- return bus_space_read_4(rdev->memt, rdev->rmmio_bsh, reg);
+ return readl(((void __iomem *)rdev->rmmio) + reg);
else
return r100_mm_rreg_slow(rdev, reg);
}
@@ -2523,7 +2525,7 @@ static inline void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32
bool always_indirect)
{
if ((reg < rdev->rmmio_size || reg < RADEON_MIN_MMIO_SIZE) && !always_indirect)
- bus_space_write_4(rdev->memt, rdev->rmmio_bsh, reg, v);
+ writel(v, ((void __iomem *)rdev->rmmio) + reg);
else
r100_mm_wreg_slow(rdev, reg, v);
}
@@ -2552,14 +2554,10 @@ static inline struct radeon_fence *to_radeon_fence(struct dma_fence *f)
/*
* Registers read & write functions.
*/
-#define RREG8(reg) \
- bus_space_read_1(rdev->memt, rdev->rmmio_bsh, (reg))
-#define WREG8(reg, v) \
- bus_space_write_1(rdev->memt, rdev->rmmio_bsh, (reg), (v))
-#define RREG16(reg) \
- bus_space_read_2(rdev->memt, rdev->rmmio_bsh, (reg))
-#define WREG16(reg, v) \
- bus_space_write_2(rdev->memt, rdev->rmmio_bsh, (reg), (v))
+#define RREG8(reg) readb((rdev->rmmio) + (reg))
+#define WREG8(reg, v) writeb(v, (rdev->rmmio) + (reg))
+#define RREG16(reg) readw((rdev->rmmio) + (reg))
+#define WREG16(reg, v) writew(v, (rdev->rmmio) + (reg))
#define RREG32(reg) r100_mm_rreg(rdev, (reg), false)
#define RREG32_IDX(reg) r100_mm_rreg(rdev, (reg), true)
#define DREG32(reg) pr_info("REGISTER: " #reg " : 0x%08X\n", \
diff --git a/sys/dev/pci/drm/radeon/radeon_device.c b/sys/dev/pci/drm/radeon/radeon_device.c
index 6651a8f6fcd..7d5323ac506 100644
--- a/sys/dev/pci/drm/radeon/radeon_device.c
+++ b/sys/dev/pci/drm/radeon/radeon_device.c
@@ -371,13 +371,13 @@ static void radeon_doorbell_fini(struct radeon_device *rdev)
{
#ifdef __linux__
iounmap(rdev->doorbell.ptr);
- rdev->doorbell.ptr = NULL;
#else
if (rdev->doorbell.size > 0)
bus_space_unmap(rdev->memt, rdev->doorbell.bsh,
rdev->doorbell.size);
rdev->doorbell.size = 0;
#endif
+ rdev->doorbell.ptr = NULL;
}
/**
@@ -1561,7 +1561,6 @@ void radeon_device_fini(struct radeon_device *rdev)
pci_iounmap(rdev->pdev, rdev->rio_mem);
rdev->rio_mem = NULL;
iounmap(rdev->rmmio);
- rdev->rmmio = NULL;
#else
if (rdev->rio_mem_size > 0)
bus_space_unmap(rdev->iot, rdev->rio_mem, rdev->rio_mem_size);
@@ -1571,6 +1570,7 @@ void radeon_device_fini(struct radeon_device *rdev)
bus_space_unmap(rdev->memt, rdev->rmmio_bsh, rdev->rmmio_size);
rdev->rmmio_size = 0;
#endif
+ rdev->rmmio = NULL;
if (rdev->family >= CHIP_BONAIRE)
radeon_doorbell_fini(rdev);
}
diff --git a/sys/dev/pci/drm/radeon/radeon_kms.c b/sys/dev/pci/drm/radeon/radeon_kms.c
index eafc166ec9a..7d3569b1221 100644
--- a/sys/dev/pci/drm/radeon/radeon_kms.c
+++ b/sys/dev/pci/drm/radeon/radeon_kms.c
@@ -582,12 +582,14 @@ radeondrm_attach_kms(struct device *parent, struct device *self, void *aux)
if (rdev->family >= CHIP_BONAIRE) {
type = pci_mapreg_type(pa->pa_pc, pa->pa_tag, 0x18);
if (PCI_MAPREG_TYPE(type) != PCI_MAPREG_TYPE_MEM ||
- pci_mapreg_map(pa, 0x18, type, 0, NULL,
+ pci_mapreg_map(pa, 0x18, type, BUS_SPACE_MAP_LINEAR, NULL,
&rdev->doorbell.bsh, &rdev->doorbell.base,
&rdev->doorbell.size, 0)) {
printf(": can't map doorbell space\n");
return;
}
+ rdev->doorbell.ptr = bus_space_vaddr(rdev->memt,
+ rdev->doorbell.bsh);
}
if (rdev->family >= CHIP_BONAIRE)
@@ -597,11 +599,12 @@ radeondrm_attach_kms(struct device *parent, struct device *self, void *aux)
type = pci_mapreg_type(pa->pa_pc, pa->pa_tag, rmmio_bar);
if (PCI_MAPREG_TYPE(type) != PCI_MAPREG_TYPE_MEM ||
- pci_mapreg_map(pa, rmmio_bar, type, 0, NULL,
+ pci_mapreg_map(pa, rmmio_bar, type, BUS_SPACE_MAP_LINEAR, NULL,
&rdev->rmmio_bsh, &rdev->rmmio_base, &rdev->rmmio_size, 0)) {
printf(": can't map rmmio space\n");
return;
}
+ rdev->rmmio = bus_space_vaddr(rdev->memt, rdev->rmmio_bsh);
#if !defined(__sparc64__)
/*