Changeset c1a7644 in libbsdport


Ignore:
Timestamp:
Apr 23, 2009, 4:29:43 AM (10 years ago)
Author:
Till Straumann <strauman@…>
Branches:
master
Children:
1f018e4
Parents:
acc2a64
Message:
  • added bus_alloc_resources()
  • added bus_release_resources()
  • added dummy handle for giant mutex.
  • added resource_int_value() stub (returns ENOENT).
  • added resource_long_value() stub (returns ENOENT).
  • added bus_read_1(), bus_read_2(), bus_read_4()

bus_write_1(), bus_write_2(), bus_write_4().

  • honour BUS_DMA_ZERO flag.
  • changed 'vaddr' arg from caddr_t to void*
Location:
bsd_eth_drivers/libbsdport
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bsd_eth_drivers/libbsdport/bus.h

    racc2a64 rc1a7644  
    1717
    1818struct resource;
     19
     20struct resource_spec {
     21        int type;
     22        int rid;
     23        int flags;
     24};
    1925
    2026typedef bus_addr_t bus_space_handle_t;
     
    141147#define RF_ACTIVE       (1<<1)
    142148#define RF_SHAREABLE    (1<<2)
     149#define RF_OPTIONAL     (1<<3)
    143150
    144151struct resource *
    145152bus_alloc_resource_any(device_t dev, int type, int *prid, unsigned flags);
     153
     154int
     155bus_alloc_resources(device_t dev, struct resource_spec *rs, struct resource **res);
     156
     157void
     158bus_release_resources(device_t dev, const struct resource_spec *rs, struct resource **res);
    146159
    147160#define FILTER_STRAY 1
     
    201214rman_get_bustag(struct resource *r);
    202215
     216/* Newer API (releng 7_1) */
     217static inline u_int8_t bus_read_1(struct resource *r, bus_size_t o)
     218{
     219        return bus_space_read_1(rman_get_bustag(r), rman_get_bushandle(r), o);
     220}
     221
     222static inline u_int16_t bus_read_2(struct resource *r, bus_size_t o)
     223{
     224        return bus_space_read_2(rman_get_bustag(r), rman_get_bushandle(r), o);
     225}
     226
     227static inline u_int32_t bus_read_4(struct resource *r, bus_size_t o)
     228{
     229        return bus_space_read_4(rman_get_bustag(r), rman_get_bushandle(r), o);
     230}
     231
     232static inline void bus_write_1(struct resource *r, bus_size_t o, u_int8_t v)
     233{
     234        bus_space_write_1(rman_get_bustag(r), rman_get_bushandle(r), o, v);
     235}
     236
     237static inline void bus_write_2(struct resource *r, bus_size_t o, u_int16_t v)
     238{
     239        bus_space_write_4(rman_get_bustag(r), rman_get_bushandle(r), o, v);
     240}
     241
     242static inline void bus_write_4(struct resource *r, bus_size_t o, u_int32_t v)
     243{
     244        bus_space_write_4(rman_get_bustag(r), rman_get_bushandle(r), o, v);
     245}
     246
    203247#ifndef BUS_DMA_NOWAIT 
    204248/* ignored anyways */
     
    224268/* ignored anyways */
    225269#define BUS_DMA_ALLOCNOW 0
     270#endif
     271
     272#ifndef BUS_DMA_ZERO
     273#define BUS_DMA_ZERO 1
    226274#endif
    227275
     
    256304int
    257305bus_dma_tag_create(void *parent, unsigned alignment, unsigned bounds, uint32_t lowadd, uint32_t hiaddr, void (*filter)(void*), void *filterarg, unsigned maxsize, int nsegs, unsigned maxsegsize, unsigned flags, void (*lockfunc)(void*), void *lockarg, bus_dma_tag_t *ptag);
     306
     307/* Dummy NULL fcn pointer */
     308#define busdma_lock_mutex 0
     309
     310extern uint32_t __busdma_dummy_Giant;
     311#define Giant __busdma_dummy_Giant
    258312
    259313void
     
    302356
    303357static inline int
    304 bus_dmamap_load(bus_dma_tag_t tag, bus_dmamap_t map, caddr_t vaddr, bus_size_t size, bus_dmamap_callback_t cb, void *arg, unsigned flags)
     358bus_dmamap_load(bus_dma_tag_t tag, bus_dmamap_t map, void *vaddr, bus_size_t size, bus_dmamap_callback_t cb, void *arg, unsigned flags)
    305359{
    306360bus_dma_segment_t segs[1];
     
    341395#define bus_dmamap_destroy(tag, map) do {} while (0)
    342396
    343 #endif
     397int
     398resource_int_value(const char *name, int unit, const char *resname, int *result);
     399int
     400resource_long_value(const char *name, int unit, const char *resname, long *result);
     401
     402#endif
  • bsd_eth_drivers/libbsdport/sysbus.c

    racc2a64 rc1a7644  
    9797}
    9898
     99int
     100bus_alloc_resources(device_t dev, struct resource_spec *rs,
     101    struct resource **res)
     102{
     103        int i;
     104
     105        for (i = 0; rs[i].type != -1; i++)
     106                res[i] = NULL;
     107        for (i = 0; rs[i].type != -1; i++) {
     108                res[i] = bus_alloc_resource_any(dev,
     109                    rs[i].type, &rs[i].rid, rs[i].flags);
     110                if (res[i] == NULL && !(rs[i].flags & RF_OPTIONAL)) {
     111                        bus_release_resources(dev, rs, res);
     112                        return (ENXIO);
     113                }
     114        }
     115        return (0);
     116}
     117
     118void
     119bus_release_resources(device_t dev, const struct resource_spec *rs,
     120    struct resource **res)
     121{
     122        int i;
     123
     124        for (i = 0; rs[i].type != -1; i++)
     125                if (res[i] != NULL) {
     126                        bus_release_resource(
     127                            dev, rs[i].type, rs[i].rid, res[i]);
     128                        res[i] = NULL;
     129                }
     130}
     131
     132
     133
    99134struct irq_cookie {
    100135        device_t        dev;
     
    143178int                rval;
    144179struct irq_cookie *info = 0;
    145 
    146 
    147180
    148181        if ( filter && handler ) {
     
    248281{
    249282uintptr_t a;
    250         if ( ! (*p_map = malloc(tag->maxsize + tag->alignment, M_DEVBUF, M_NOWAIT)) )
     283unsigned  sz = tag->maxsize + tag->alignment;
     284        if ( ! (*p_map = malloc(sz, M_DEVBUF, M_NOWAIT)) )
    251285                return ENOMEM;
    252286        a = ((uintptr_t)*p_map + tag->alignment - 1 ) & ~(tag->alignment - 1);
    253287        *p_vaddr = (void*)a;
     288        if ( (BUS_DMA_ZERO & flags) )
     289                memset(*p_map, 0, sz);
    254290        return 0;
    255291}
     
    260296        free(map, M_DEVBUF);
    261297}
     298
     299/* Dummy handle for Giant mutex */
     300uint32_t __busdma_dummy_Giant = 0;
     301
     302int
     303resource_int_value(const char *name, int unit, const char *resname, int *result)
     304{
     305        /* not implemented */
     306        return ENOENT;
     307}
     308int
     309resource_long_value(const char *name, int unit, const char *resname, long *result)
     310{
     311        /* not implemented */
     312        return ENOENT;
     313}
Note: See TracChangeset for help on using the changeset viewer.