cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

cudbg_common.c (1389B)


      1// SPDX-License-Identifier: GPL-2.0-only
      2/*
      3 *  Copyright (C) 2017 Chelsio Communications.  All rights reserved.
      4 */
      5
      6#include "cxgb4.h"
      7#include "cudbg_if.h"
      8#include "cudbg_lib_common.h"
      9
     10int cudbg_get_buff(struct cudbg_init *pdbg_init,
     11		   struct cudbg_buffer *pdbg_buff, u32 size,
     12		   struct cudbg_buffer *pin_buff)
     13{
     14	u32 offset;
     15
     16	offset = pdbg_buff->offset;
     17	if (offset + size > pdbg_buff->size)
     18		return CUDBG_STATUS_NO_MEM;
     19
     20	if (pdbg_init->compress_type != CUDBG_COMPRESSION_NONE) {
     21		if (size > pdbg_init->compress_buff_size)
     22			return CUDBG_STATUS_NO_MEM;
     23
     24		pin_buff->data = (char *)pdbg_init->compress_buff;
     25		pin_buff->offset = 0;
     26		pin_buff->size = size;
     27		return 0;
     28	}
     29
     30	pin_buff->data = (char *)pdbg_buff->data + offset;
     31	pin_buff->offset = offset;
     32	pin_buff->size = size;
     33	return 0;
     34}
     35
     36void cudbg_put_buff(struct cudbg_init *pdbg_init,
     37		    struct cudbg_buffer *pin_buff)
     38{
     39	/* Clear compression buffer for re-use */
     40	if (pdbg_init->compress_type != CUDBG_COMPRESSION_NONE)
     41		memset(pdbg_init->compress_buff, 0,
     42		       pdbg_init->compress_buff_size);
     43
     44	pin_buff->data = NULL;
     45	pin_buff->offset = 0;
     46	pin_buff->size = 0;
     47}
     48
     49void cudbg_update_buff(struct cudbg_buffer *pin_buff,
     50		       struct cudbg_buffer *pout_buff)
     51{
     52	/* We already write to buffer provided by ethool, so just
     53	 * increment offset to next free space.
     54	 */
     55	pout_buff->offset += pin_buff->size;
     56}