mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-07 09:00:28 +00:00
bea2bf458d
Do like bus_space(9) does. This fixes the build on platforms where
bus_addr_t and bus_size_t are different (like i386 PAE).
Reviewed by: jhibbits
Fixes: c2e9c5bbf0
tpm: Refactor TIS and add a SPI attachment
Differential Revision: https://reviews.freebsd.org/D45287
100 lines
2.8 KiB
C
100 lines
2.8 KiB
C
/*-
|
|
* Copyright (c) 2023 Juniper Networks, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#include <sys/cdefs.h>
|
|
#include <sys/types.h>
|
|
#include <sys/bus.h>
|
|
#include "tpm_if.h"
|
|
#include "tpm20.h"
|
|
|
|
/* Override accessors */
|
|
static uint8_t
|
|
tpm_read_1(device_t dev, bus_size_t off)
|
|
{
|
|
struct tpm_sc *sc = device_get_softc(dev);
|
|
|
|
return (bus_read_1(sc->mem_res, off));
|
|
}
|
|
|
|
static uint32_t
|
|
tpm_read_4(device_t dev, bus_size_t off)
|
|
{
|
|
struct tpm_sc *sc = device_get_softc(dev);
|
|
|
|
return (bus_read_4(sc->mem_res, off));
|
|
}
|
|
|
|
/*
|
|
* Only i386 is missing bus_space_read_8.
|
|
*/
|
|
#ifndef __i386__
|
|
static uint64_t
|
|
tpm_read_8(device_t dev, bus_size_t off)
|
|
{
|
|
struct tpm_sc *sc = device_get_softc(dev);
|
|
|
|
return (bus_read_8(sc->mem_res, off));
|
|
}
|
|
#endif
|
|
|
|
static void
|
|
tpm_write_1(device_t dev, bus_size_t off, uint8_t val)
|
|
{
|
|
struct tpm_sc *sc = device_get_softc(dev);
|
|
|
|
bus_write_1(sc->mem_res, off, val);
|
|
}
|
|
|
|
static void
|
|
tpm_write_4(device_t dev, bus_size_t off, uint32_t val)
|
|
{
|
|
struct tpm_sc *sc = device_get_softc(dev);
|
|
|
|
bus_write_4(sc->mem_res, off, val);
|
|
}
|
|
|
|
static void
|
|
tpm_write_barrier(device_t dev, bus_size_t off, bus_size_t length)
|
|
{
|
|
struct tpm_sc *sc = device_get_softc(dev);
|
|
|
|
bus_barrier(sc->mem_res, off, length, BUS_SPACE_BARRIER_WRITE);
|
|
}
|
|
|
|
static device_method_t tpm_bus_methods[] = {
|
|
DEVMETHOD(tpm_read_1, tpm_read_1),
|
|
DEVMETHOD(tpm_read_4, tpm_read_4),
|
|
#ifndef __i386__
|
|
DEVMETHOD(tpm_read_8, tpm_read_8),
|
|
#endif
|
|
DEVMETHOD(tpm_write_1, tpm_write_1),
|
|
DEVMETHOD(tpm_write_4, tpm_write_4),
|
|
DEVMETHOD(tpm_write_barrier, tpm_write_barrier),
|
|
DEVMETHOD_END
|
|
};
|
|
|
|
DEFINE_CLASS_0(tpm_lbc, tpm_bus_driver, tpm_bus_methods, sizeof(struct tpm_sc));
|