blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
4
721
content_id
stringlengths
40
40
detected_licenses
listlengths
0
57
license_type
stringclasses
2 values
repo_name
stringlengths
5
91
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringclasses
321 values
visit_date
timestamp[ns]date
2016-08-12 09:31:09
2023-09-06 10:45:07
revision_date
timestamp[ns]date
2010-09-28 14:01:40
2023-09-06 06:22:19
committer_date
timestamp[ns]date
2010-09-28 14:01:40
2023-09-06 06:22:19
github_id
int64
426
681M
star_events_count
int64
101
243k
fork_events_count
int64
0
110k
gha_license_id
stringclasses
23 values
gha_event_created_at
timestamp[ns]date
2012-06-28 18:51:49
2023-09-14 21:59:16
gha_created_at
timestamp[ns]date
2008-02-11 22:55:26
2023-08-10 11:14:58
gha_language
stringclasses
147 values
src_encoding
stringclasses
26 values
language
stringclasses
2 values
is_vendor
bool
2 classes
is_generated
bool
2 classes
length_bytes
int64
6
10.2M
extension
stringclasses
115 values
filename
stringlengths
3
113
content
stringlengths
6
10.2M
b00e2ea7824be251c7ab0c3e519c7f8ee6e41269
6d088ec295b33db11e378212d42d40d5a190c54c
/contrib/mul/ipts/ipts_corner_pyramid.h
32041960f9b5b854a2424630adbee96295f0676d
[ "LicenseRef-scancode-warranty-disclaimer" ]
no_license
vxl/vxl
29dffd5011f21a67e14c1bcbd5388fdbbc101b29
594ebed3d5fb6d0930d5758630113e044fee00bc
refs/heads/master
2023-08-31T03:56:24.286486
2023-08-29T17:53:12
2023-08-29T17:53:12
9,819,799
224
126
null
2023-09-14T15:52:32
2013-05-02T18:32:27
C++
UTF-8
C
false
false
1,115
h
ipts_corner_pyramid.h
// This is mul/ipts/ipts_corner_pyramid.h #ifndef ipts_corner_pyramid_h_ #define ipts_corner_pyramid_h_ //: // \file // \brief Compute corner strength at each level of a scale space pyramid // \author Tim Cootes #include <vimt/vimt_image_2d_of.h> #include <vimt/vimt_image_pyramid.h> //: Compute corner strength at each level of a scale space pyramid // Build smooth gaussian pyramid from the image, then compute corners at each level. // Use ipts_scale_space_peaks() to get the position and scale of likely corners void ipts_corner_pyramid(const vimt_image_2d_of<float>& image, vimt_image_pyramid& corner_pyramid, vimt_image_pyramid& smooth_pyramid, double scale_step); //: Compute corner strength at each level of a scale space pyramid. // smooth_pyramid assumed to be of type float. // Use ipts_scale_space_peaks() to get the position and scale of // likely corners void ipts_corner_pyramid(const vimt_image_pyramid& smooth_pyramid, vimt_image_pyramid& corner_pyramid); #endif // ipts_corner_pyramid_h_
eedef8f582d9755fa4d2644a627cd2c54daa3230
6832a9c81b16ead373325f70fb97753d6a211539
/src/wrapped/wrappedlibxcbshape_private.h
daf0fa9a4507c7750057ecb16b7e80d499295eb3
[ "MIT" ]
permissive
ptitSeb/box86
2d3a0c4574905ff8d9dc7b5afb5444a273832bd6
ad934455c1b40feeebe5e6bd09b9063519102859
refs/heads/master
2023-08-22T05:30:54.331500
2023-08-20T13:01:58
2023-08-20T13:01:58
164,844,546
2,877
294
MIT
2023-07-27T11:19:10
2019-01-09T10:49:32
C
UTF-8
C
false
false
1,382
h
wrappedlibxcbshape_private.h
#if !(defined(GO) && defined(GOM) && defined(GO2) && defined(DATA)) #error meh! #endif //%S x my_xcb_cookie_t u //GOS(xcb_shape_combine, //GOS(xcb_shape_combine_checked, //GOS(xcb_shape_get_rectangles, //GOS(xcb_shape_get_rectangles_rectangles, //GOS(xcb_shape_get_rectangles_rectangles_iterator, //GOS(xcb_shape_get_rectangles_rectangles_length, //GOS(xcb_shape_get_rectangles_reply, //GOS(xcb_shape_get_rectangles_sizeof, //GOS(xcb_shape_get_rectangles_unchecked, DATA(xcb_shape_id, 8) //GOS(xcb_shape_input_selected, //GOS(xcb_shape_input_selected_reply, //GOS(xcb_shape_input_selected_unchecked, //GOS(xcb_shape_kind_end, //GOS(xcb_shape_kind_next, GOS(xcb_shape_mask, xFEpuuuwwu) GOS(xcb_shape_mask_checked, xFEpuuuwwu) //GOS(xcb_shape_offset, //GOS(xcb_shape_offset_checked, //GOS(xcb_shape_op_end, //GOS(xcb_shape_op_next, //GOS(xcb_shape_query_extents, //GOS(xcb_shape_query_extents_reply, //GOS(xcb_shape_query_extents_unchecked, //GOS(xcb_shape_query_version, //GOS(xcb_shape_query_version_reply, //GOS(xcb_shape_query_version_unchecked, //GOS(xcb_shape_rectangles, //GOS(xcb_shape_rectangles_checked, //GOS(xcb_shape_rectangles_rectangles, //GOS(xcb_shape_rectangles_rectangles_iterator, //GOS(xcb_shape_rectangles_rectangles_length, //GOS(xcb_shape_rectangles_sizeof, //GOS(xcb_shape_select_input, //GOS(xcb_shape_select_input_checked,
1744670a391a34c10f768df14d33711ff4af3242
fce81b804cae23f525a5ad4370b684bf0dc531a5
/numpy/core/src/multiarray/multiarraymodule.h
df505733bc6349d7febfbcc22accdae660a7525b
[ "Zlib", "BSD-3-Clause", "MIT", "Apache-2.0" ]
permissive
numpy/numpy
ba2abcc1d2d46affbb6aabe5aed6407b4b57507e
dc2ff125493777a1084044e6cd6857a42ee323d4
refs/heads/main
2023-09-05T10:10:52.767363
2023-09-04T18:03:29
2023-09-04T18:03:29
908,607
25,725
11,968
BSD-3-Clause
2023-09-14T21:26:09
2010-09-13T23:02:39
Python
UTF-8
C
false
false
1,051
h
multiarraymodule.h
#ifndef NUMPY_CORE_SRC_MULTIARRAY_MULTIARRAYMODULE_H_ #define NUMPY_CORE_SRC_MULTIARRAY_MULTIARRAYMODULE_H_ NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_current_allocator; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_function; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_struct; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_priority; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_interface; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_wrap; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_finalize; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_implementation; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_axis1; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_axis2; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_like; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_numpy; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_where; #endif /* NUMPY_CORE_SRC_MULTIARRAY_MULTIARRAYMODULE_H_ */
11794c97839781410e39936ed27b29e82bed6705
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/arch/arm/mach-shmobile/include/mach/common.h
4634a5d4b63f8645d84cad4f122061f46642515f
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
1,161
h
common.h
#ifndef __ARCH_MACH_COMMON_H #define __ARCH_MACH_COMMON_H extern void shmobile_earlytimer_init(void); extern void shmobile_timer_init(void); extern void shmobile_setup_delay(unsigned int max_cpu_core_mhz, unsigned int mult, unsigned int div); struct twd_local_timer; extern void shmobile_setup_console(void); extern void shmobile_secondary_vector(void); extern void shmobile_secondary_vector_scu(void); struct clk; extern int shmobile_clk_init(void); extern void shmobile_handle_irq_intc(struct pt_regs *); extern struct platform_suspend_ops shmobile_suspend_ops; struct cpuidle_driver; extern void shmobile_cpuidle_set_driver(struct cpuidle_driver *drv); #ifdef CONFIG_SUSPEND int shmobile_suspend_init(void); #else static inline int shmobile_suspend_init(void) { return 0; } #endif #ifdef CONFIG_CPU_IDLE int shmobile_cpuidle_init(void); #else static inline int shmobile_cpuidle_init(void) { return 0; } #endif extern void __iomem *shmobile_scu_base; extern void shmobile_smp_init_cpus(unsigned int ncores); static inline void __init shmobile_init_late(void) { shmobile_suspend_init(); shmobile_cpuidle_init(); } #endif /* __ARCH_MACH_COMMON_H */
850c8267af0be1958c3c06e7257996a91d91d23d
1d16873bf69158e5a2b168eb3d7857455709e71b
/src/pa_ringbuffer.c
93b3e430a51064a313799b301e0134769df1086d
[ "MIT" ]
permissive
mofarrell/p2pvc
a8a26aa3363b4b136d14503eff9f165355430551
12a5269ce4709eb335d6e4232d3be14f61fac16b
refs/heads/master
2023-03-11T07:46:09.615602
2022-02-15T22:22:23
2022-02-15T22:22:23
30,442,211
3,298
320
MIT
2022-02-15T22:22:24
2015-02-07T02:24:58
C
UTF-8
C
false
false
9,403
c
pa_ringbuffer.c
/* * $Id$ * Portable Audio I/O Library * Ring Buffer utility. * * Author: Phil Burk, http://www.softsynth.com * modified for SMP safety on Mac OS X by Bjorn Roche * modified for SMP safety on Linux by Leland Lucius * also, allowed for const where possible * modified for multiple-byte-sized data elements by Sven Fischer * * Note that this is safe only for a single-thread reader and a * single-thread writer. * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com * Copyright (c) 1999-2000 Ross Bencina and Phil Burk * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files * (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, * publish, distribute, sublicense, and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * The text above constitutes the entire PortAudio license; however, * the PortAudio community also makes the following non-binding requests: * * Any person wishing to distribute modifications to the Software is * requested to send the modifications to the original developer so that * they can be incorporated into the canonical version. It is also * requested that these non-binding requests be included along with the * license above. */ /** @file @ingroup common_src */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include "pa_ringbuffer.h" #include <string.h> #include "pa_memorybarrier.h" /*************************************************************************** * Initialize FIFO. * elementCount must be power of 2, returns -1 if not. */ ring_buffer_size_t PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementSizeBytes, ring_buffer_size_t elementCount, void *dataPtr ) { if( ((elementCount-1) & elementCount) != 0) return -1; /* Not Power of two. */ rbuf->bufferSize = elementCount; rbuf->buffer = (char *)dataPtr; PaUtil_FlushRingBuffer( rbuf ); rbuf->bigMask = (elementCount*2)-1; rbuf->smallMask = (elementCount)-1; rbuf->elementSizeBytes = elementSizeBytes; return 0; } /*************************************************************************** ** Return number of elements available for reading. */ ring_buffer_size_t PaUtil_GetRingBufferReadAvailable( const PaUtilRingBuffer *rbuf ) { return ( (rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask ); } /*************************************************************************** ** Return number of elements available for writing. */ ring_buffer_size_t PaUtil_GetRingBufferWriteAvailable( const PaUtilRingBuffer *rbuf ) { return ( rbuf->bufferSize - PaUtil_GetRingBufferReadAvailable(rbuf)); } /*************************************************************************** ** Clear buffer. Should only be called when buffer is NOT being read or written. */ void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf ) { rbuf->writeIndex = rbuf->readIndex = 0; } /*************************************************************************** ** Get address of region(s) to which we can write data. ** If the region is contiguous, size2 will be zero. ** If non-contiguous, size2 will be the size of second region. ** Returns room available to be written or elementCount, whichever is smaller. */ ring_buffer_size_t PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount, void **dataPtr1, ring_buffer_size_t *sizePtr1, void **dataPtr2, ring_buffer_size_t *sizePtr2 ) { ring_buffer_size_t index; ring_buffer_size_t available = PaUtil_GetRingBufferWriteAvailable( rbuf ); if( elementCount > available ) elementCount = available; /* Check to see if write is not contiguous. */ index = rbuf->writeIndex & rbuf->smallMask; if( (index + elementCount) > rbuf->bufferSize ) { /* Write data in two blocks that wrap the buffer. */ ring_buffer_size_t firstHalf = rbuf->bufferSize - index; *dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes]; *sizePtr1 = firstHalf; *dataPtr2 = &rbuf->buffer[0]; *sizePtr2 = elementCount - firstHalf; } else { *dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes]; *sizePtr1 = elementCount; *dataPtr2 = NULL; *sizePtr2 = 0; } if( available ) PaUtil_FullMemoryBarrier(); /* (write-after-read) => full barrier */ return elementCount; } /*************************************************************************** */ ring_buffer_size_t PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount ) { /* ensure that previous writes are seen before we update the write index (write after write) */ PaUtil_WriteMemoryBarrier(); return rbuf->writeIndex = (rbuf->writeIndex + elementCount) & rbuf->bigMask; } /*************************************************************************** ** Get address of region(s) from which we can read data. ** If the region is contiguous, size2 will be zero. ** If non-contiguous, size2 will be the size of second region. ** Returns room available to be read or elementCount, whichever is smaller. */ ring_buffer_size_t PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount, void **dataPtr1, ring_buffer_size_t *sizePtr1, void **dataPtr2, ring_buffer_size_t *sizePtr2 ) { ring_buffer_size_t index; ring_buffer_size_t available = PaUtil_GetRingBufferReadAvailable( rbuf ); /* doesn't use memory barrier */ if( elementCount > available ) elementCount = available; /* Check to see if read is not contiguous. */ index = rbuf->readIndex & rbuf->smallMask; if( (index + elementCount) > rbuf->bufferSize ) { /* Write data in two blocks that wrap the buffer. */ ring_buffer_size_t firstHalf = rbuf->bufferSize - index; *dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes]; *sizePtr1 = firstHalf; *dataPtr2 = &rbuf->buffer[0]; *sizePtr2 = elementCount - firstHalf; } else { *dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes]; *sizePtr1 = elementCount; *dataPtr2 = NULL; *sizePtr2 = 0; } if( available ) PaUtil_ReadMemoryBarrier(); /* (read-after-read) => read barrier */ return elementCount; } /*************************************************************************** */ ring_buffer_size_t PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount ) { /* ensure that previous reads (copies out of the ring buffer) are always completed before updating (writing) the read index. (write-after-read) => full barrier */ PaUtil_FullMemoryBarrier(); return rbuf->readIndex = (rbuf->readIndex + elementCount) & rbuf->bigMask; } /*************************************************************************** ** Return elements written. */ ring_buffer_size_t PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, ring_buffer_size_t elementCount ) { ring_buffer_size_t size1, size2, numWritten; void *data1, *data2; numWritten = PaUtil_GetRingBufferWriteRegions( rbuf, elementCount, &data1, &size1, &data2, &size2 ); if( size2 > 0 ) { memcpy( data1, data, size1*rbuf->elementSizeBytes ); data = ((char *)data) + size1*rbuf->elementSizeBytes; memcpy( data2, data, size2*rbuf->elementSizeBytes ); } else { memcpy( data1, data, size1*rbuf->elementSizeBytes ); } PaUtil_AdvanceRingBufferWriteIndex( rbuf, numWritten ); return numWritten; } /*************************************************************************** ** Return elements read. */ ring_buffer_size_t PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, ring_buffer_size_t elementCount ) { ring_buffer_size_t size1, size2, numRead; void *data1, *data2; numRead = PaUtil_GetRingBufferReadRegions( rbuf, elementCount, &data1, &size1, &data2, &size2 ); if( size2 > 0 ) { memcpy( data, data1, size1*rbuf->elementSizeBytes ); data = ((char *)data) + size1*rbuf->elementSizeBytes; memcpy( data, data2, size2*rbuf->elementSizeBytes ); } else { memcpy( data, data1, size1*rbuf->elementSizeBytes ); } PaUtil_AdvanceRingBufferReadIndex( rbuf, numRead ); return numRead; }
cb8fd3c4e2964fca8f2d6ff612b1aa6645e2758b
89db60818afeb3dc7c3b7abe9ceae155f074f7f2
/src/cmd/astro/venus.c
7ee1146dc29f534e056bdea4e77de2b8e92c77ce
[ "bzip2-1.0.6", "LPL-1.02", "MIT" ]
permissive
9fans/plan9port
63c3d01928c6f8a8617d3ea6ecc05bac72391132
65c090346a38a8c30cb242d345aa71060116340c
refs/heads/master
2023-08-25T17:14:26.233105
2023-08-23T13:21:37
2023-08-23T18:47:08
26,095,474
1,645
468
NOASSERTION
2023-09-05T16:55:41
2014-11-02T22:40:13
C
UTF-8
C
false
false
2,417
c
venus.c
#include "astro.h" void venus(void) { double pturbl, pturbb, pturbr; double lograd; double dele, enom, vnom, nd, sl; double v0, t0, m0, j0, s0; double lsun, elong, ci, dlong; /* * here are the mean orbital elements */ ecc = .00682069 - .00004774*capt + 0.091e-6*capt2; incl = 3.393631 + .0010058*capt - 0.97e-6*capt2; node = 75.779647 + .89985*capt + .00041*capt2; argp = 130.163833 + 1.408036*capt - .0009763*capt2; mrad = .7233316; anom = 212.603219 + 1.6021301540*eday + .00128605*capt2; motion = 1.6021687039; /* * mean anomalies of perturbing planets */ v0 = 212.60 + 1.602130154*eday; t0 = 358.63 + .985608747*eday; m0 = 319.74 + 0.524032490*eday; j0 = 225.43 + .083090842*eday; s0 = 175.8 + .033459258*eday; v0 *= radian; t0 *= radian; m0 *= radian; j0 *= radian; s0 *= radian; incl *= radian; node *= radian; argp *= radian; anom = fmod(anom, 360.)*radian; /* * computation of long period terms affecting the mean anomaly */ anom += (2.761-0.022*capt)*radsec*sin( 13.*t0 - 8.*v0 + 43.83*radian + 4.52*radian*capt) + 0.268*radsec*cos(4.*m0 - 7.*t0 + 3.*v0) + 0.019*radsec*sin(4.*m0 - 7.*t0 + 3.*v0) - 0.208*radsec*sin(s0 + 1.4*radian*capt); /* * computation of elliptic orbit */ enom = anom + ecc*sin(anom); do { dele = (anom - enom + ecc * sin(enom)) / (1 - ecc*cos(enom)); enom += dele; } while(fabs(dele) > converge); vnom = 2*atan2(sqrt((1+ecc)/(1-ecc))*sin(enom/2), cos(enom/2)); rad = mrad*(1 - ecc*cos(enom)); lambda = vnom + argp; /* * perturbations in longitude */ icosadd(venfp, vencp); pturbl = cosadd(4, v0, t0, m0, j0); pturbl *= radsec; /* * perturbations in latidude */ pturbb = cosadd(3, v0, t0, j0); pturbb *= radsec; /* * perturbations in log radius vector */ pturbr = cosadd(4, v0, t0, m0, j0); /* * reduction to the ecliptic */ lambda += pturbl; nd = lambda - node; lambda = node + atan2(sin(nd)*cos(incl),cos(nd)); sl = sin(incl)*sin(nd); beta = atan2(sl, pyth(sl)) + pturbb; lograd = pturbr*2.30258509; rad *= 1 + lograd; motion *= radian*mrad*mrad/(rad*rad); /* * computation of magnitude */ lsun = 99.696678 + 0.9856473354*eday; lsun *= radian; elong = lambda - lsun; ci = (rad - cos(elong))/sqrt(1 + rad*rad - 2*rad*cos(elong)); dlong = atan2(pyth(ci), ci)/radian; mag = -4 + .01322*dlong + .0000004247*dlong*dlong*dlong; semi = 8.41; helio(); geo(); }
cd115083ed713cb4ccd6035737cc6b330aaaa4c9
d134ae730638c9f26155017cf83b27399f69e4a5
/3rd_party/nek5000/core/crs_amg_io.h
dea3a872aee4d21d8909487b5370817df6667d29
[ "BSD-3-Clause" ]
permissive
Nek5000/nekRS
24e485ba046030fd06755acae44d63ecc1188333
4f87e0e2ec0492e2a3edf27791252d6886814d00
refs/heads/master
2023-08-26T21:41:41.026390
2023-05-30T07:36:13
2023-05-30T07:36:13
200,469,913
220
72
NOASSERTION
2023-09-08T17:18:24
2019-08-04T08:45:08
C++
UTF-8
C
false
false
5,287
h
crs_amg_io.h
/*========================================================================== File I/O for AMG small wrappers to read/write files consisting of doubles ==========================================================================*/ #ifndef MPI #undef USEMPIIO #endif #ifdef NOMPIIO #undef USEMPIIO #endif /* reverse the byte order of the given double portable up to 129-byte doubles, standards conforming */ #define N sizeof(double) static double byteswap(double x) { char t, buf[N]; memcpy(buf,&x,N); #define SWAP1(i) if(N>2*(i)+1) t=buf[i],buf[i]=buf[N-1-(i)],buf[N-1-(i)]=t #define SWAP2(i) SWAP1(i); SWAP1((i)+0x01); SWAP1((i)+0x02); SWAP1((i)+0x03) #define SWAP3(i) SWAP2(i); SWAP2((i)+0x04); SWAP2((i)+0x08); SWAP2((i)+0x0c) #define SWAP4(i) SWAP3(i); SWAP3((i)+0x10); SWAP3((i)+0x20); SWAP3((i)+0x30) SWAP4(0); #undef SWAP1 #undef SWAP2 #undef SWAP3 #undef SWAP4 memcpy(&x,buf,N); return x; } #undef N struct file { FILE *fptr; int swap; }; #ifdef USEMPIIO struct sfile { MPI_File fh; int swap; }; #endif static int rfread(void *ptr, size_t n, FILE *const fptr) { size_t na; char *p=ptr; while(n && (na=fread (p,1,n,fptr))) n-=na, p+=na; return n!=0; } static int rfwrite(FILE *const fptr, const void *ptr, size_t n) { size_t na; const char *p=ptr; while(n && (na=fwrite(p,1,n,fptr))) n-=na, p+=na; return n!=0; } static struct file dopen(const char *filename, const char mode,int *code) { const double magic = 3.14159; double t; struct file f; f.fptr = fopen(filename,mode=='r'?"r":"w"); f.swap = 0; if(f.fptr==0) { diagnostic("ERROR ",__FILE__,__LINE__, "AMG: could not open %s for %s", filename,mode=='r'?"reading":"writing"); *code=1; return f; } if(mode=='r') { if(rfread(&t,sizeof(double), f.fptr)){ diagnostic("ERROR ",__FILE__,__LINE__, "AMG: could not read from %s",filename); *code=1; return f; } if(fabs(t-magic)>0.000001) { t=byteswap(t); if(fabs(t-magic)>0.000001) { diagnostic("ERROR ",__FILE__,__LINE__, "AMG: magic number for endian test not found in %s", filename); *code=1; return f; } f.swap = 1; } } else { if(rfwrite(f.fptr, &magic,sizeof(double))){ diagnostic("ERROR ",__FILE__,__LINE__, "AMG: could not write to %s",filename); *code=1; return f; } } return f; } static void dread(double *p, size_t n, const struct file f,int *code) { if(rfread(p,n*sizeof(double),f.fptr)) { diagnostic("ERROR ",__FILE__,__LINE__, "AMG: failed reading %u doubles from disk",(unsigned)n); *code=1; return; } if(f.swap) while(n) *p=byteswap(*p), ++p, --n; } static void dwrite(const struct file f, const double *p, size_t n,int *code) { if(rfwrite(f.fptr, p,n*sizeof(double))) { diagnostic("ERROR ",__FILE__,__LINE__, "AMG: failed writing %u doubles to disk",(unsigned)n); *code=1; } } static void dclose(const struct file f) { fclose(f.fptr); } #ifdef USEMPIIO static void dread_mpi(double *buf, uint n, const struct sfile f,int *code) { MPI_File fh=f.fh; MPI_Status status; int count=n; if(MPI_File_read_all(fh,buf,count,MPI_DOUBLE,&status)) { diagnostic("ERROR ",__FILE__,__LINE__, "AMG: failed reading %u doubles from disk",(unsigned)count); *code=1; return; } if(f.swap) while(count) *buf=byteswap(*buf), ++buf, --count; } static struct sfile dopen_mpi(const char *filename, const char mode, const struct comm *c,int *code) { const double magic = 3.14159; double t; struct sfile f={0,0}; MPI_File fh; int amode = mode=='r' ? MPI_MODE_RDONLY : MPI_MODE_CREATE|MPI_MODE_WRONLY; MPI_File_open(c->c,filename,amode,MPI_INFO_NULL,&fh); f.fh = fh; if(f.fh==0) { diagnostic("ERROR ",__FILE__,__LINE__, "AMG: could not open %s for %s", filename,mode=='r'?"reading":"writing"); *code=1; return f; } if(mode=='r') { dread_mpi(&t, 1, f, code); if(*code!=0) { diagnostic("ERROR ",__FILE__,__LINE__, "AMG: could not read from %s",filename); return f; } if(fabs(t-magic)>0.000001) { t=byteswap(t); if(fabs(t-magic)>0.000001) { diagnostic("ERROR ",__FILE__,__LINE__, "AMG: magic number for endian test not found in %s", filename); *code=1; return f; } f.swap = 1; } } else { /* dwrite_mpi(&t, 1, f.fh, code); */ if(*code!=0) { diagnostic("ERROR ",__FILE__,__LINE__, "AMG: could not write to %s",filename); return f; } } return f; } static void dview_mpi(ulong n, const struct sfile f, int *code) { MPI_File fh=f.fh; MPI_Info info; MPI_Offset disp=n*sizeof(double); if(MPI_File_set_view(fh,disp,MPI_DOUBLE,MPI_DOUBLE,"native",MPI_INFO_NULL)) { diagnostic("ERROR ",__FILE__,__LINE__, "AMG: failed chaning view to %u doubles",(unsigned)n); *code=1; return; } } static void dclose_mpi(const struct sfile f) { MPI_File fh=f.fh; MPI_File_close(&fh); } #endif
cd9d1a32778f02efbb8397c976e18891603cc8a1
99bdb3251fecee538e0630f15f6574054dfc1468
/bsp/renesas/ra6m3-hmi-board/ra/fsp/src/bsp/mcu/all/bsp_security.c
62d9fe81f64c712fc8d993016460da8f05fb3f84
[ "Zlib", "LicenseRef-scancode-proprietary-license", "MIT", "BSD-3-Clause", "X11", "BSD-4-Clause-UC", "LicenseRef-scancode-unknown-license-reference", "Apache-2.0" ]
permissive
RT-Thread/rt-thread
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
3602f891211904a27dcbd51e5ba72fefce7326b2
refs/heads/master
2023-09-01T04:10:20.295801
2023-08-31T16:20:55
2023-08-31T16:20:55
7,408,108
9,599
5,805
Apache-2.0
2023-09-14T13:37:26
2013-01-02T14:49:21
C
UTF-8
C
false
false
19,003
c
bsp_security.c
/*********************************************************************************************************************** * Copyright [2020-2021] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. * * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. **********************************************************************************************************************/ /*********************************************************************************************************************** * Includes <System Includes> , "Project Includes" **********************************************************************************************************************/ #include "bsp_api.h" #if BSP_FEATURE_TZ_HAS_TRUSTZONE /*********************************************************************************************************************** * Macro definitions **********************************************************************************************************************/ #define BSP_PRV_TZ_REG_KEY (0xA500U) #define BSP_PRV_AIRCR_VECTKEY (0x05FA0000U) #define RA_NOT_DEFINED (0) /*********************************************************************************************************************** * Typedef definitions **********************************************************************************************************************/ /*********************************************************************************************************************** * Exported global variables (to be accessed by other files) **********************************************************************************************************************/ void R_BSP_SecurityInit(void); void R_BSP_PinCfgSecurityInit(void); void R_BSP_ElcCfgSecurityInit(void); /*********************************************************************************************************************** * External symbols **********************************************************************************************************************/ extern const fsp_vector_t g_vector_table[BSP_ICU_VECTOR_MAX_ENTRIES]; #if defined(__ARMCC_VERSION) || defined(__ICCARM__) typedef void (BSP_CMSE_NONSECURE_CALL * bsp_nonsecure_func_t)(void); #elif defined(__GNUC__) typedef BSP_CMSE_NONSECURE_CALL void (*volatile bsp_nonsecure_func_t)(void); #endif #if defined(__IAR_SYSTEMS_ICC__) && BSP_TZ_SECURE_BUILD #pragma section=".tz_flash_nsc_start" #pragma section=".tz_flash_ns_start" #pragma section=".tz_ram_nsc_start" #pragma section=".tz_ram_ns_start" #pragma section=".tz_data_flash_ns_start" #pragma section=".tz_sdram_ns_start" #pragma section=".tz_qspi_flash_ns_start" #pragma section=".tz_ospi_device_0_ns_start" #pragma section=".tz_ospi_device_1_ns_start" /* &__tz_<REGION>_C is the address of the non-secure callable section. Must assign value to this variable or * linker will give error. */ /* &__tz_<REGION>_N is the start address of the non-secure region. */ BSP_DONT_REMOVE void const * const __tz_FLASH_C BSP_ALIGN_VARIABLE(1024) @".tz_flash_nsc_start" = 0; BSP_DONT_REMOVE void const * const __tz_FLASH_N BSP_ALIGN_VARIABLE(32768) @".tz_flash_ns_start" = 0; BSP_DONT_REMOVE void * __tz_RAM_C BSP_ALIGN_VARIABLE(1024) @".tz_ram_nsc_start"; BSP_DONT_REMOVE void * __tz_RAM_N BSP_ALIGN_VARIABLE(8192) @".tz_ram_ns_start"; BSP_DONT_REMOVE void * __tz_DATA_FLASH_N BSP_ALIGN_VARIABLE(1024) @".tz_data_flash_ns_start"; #if BSP_FEATURE_SDRAM_START_ADDRESS BSP_DONT_REMOVE void * __tz_SDRAM_N @".tz_sdram_ns_start"; #endif BSP_DONT_REMOVE void * __tz_QSPI_FLASH_N @".tz_qspi_flash_ns_start"; #if BSP_FEATURE_OSPI_DEVICE_0_START_ADDRESS BSP_DONT_REMOVE void * __tz_OSPI_DEVICE_0_N @".tz_ospi_device_0_ns_start"; #endif #if BSP_FEATURE_OSPI_DEVICE_1_START_ADDRESS BSP_DONT_REMOVE void * __tz_OSPI_DEVICE_1_N @".tz_ospi_device_1_ns_start"; #endif BSP_DONT_REMOVE uint32_t const * const gp_start_of_nonsecure_flash = (uint32_t *) &__tz_FLASH_N; #elif defined(__ARMCC_VERSION) extern const uint32_t Image$$__tz_FLASH_N$$Base; extern const uint32_t Image$$__tz_FLASH_C$$Base; extern const uint32_t Image$$__tz_FLASH_S$$Base; extern const uint32_t Image$$__tz_RAM_N$$Base; extern const uint32_t Image$$__tz_RAM_C$$Base; extern const uint32_t Image$$__tz_RAM_S$$Base; extern const uint32_t Image$$__tz_DATA_FLASH_N$$Base; extern const uint32_t Image$$__tz_DATA_FLASH_S$$Base; extern const uint32_t Image$$__tz_QSPI_FLASH_N$$Base; extern const uint32_t Image$$__tz_QSPI_FLASH_S$$Base; extern const uint32_t Image$$__tz_SDRAM_N$$Base; extern const uint32_t Image$$__tz_SDRAM_S$$Base; extern const uint32_t Image$$__tz_OSPI_DEVICE_0_N$$Base; extern const uint32_t Image$$__tz_OSPI_DEVICE_0_S$$Base; extern const uint32_t Image$$__tz_OSPI_DEVICE_1_N$$Base; extern const uint32_t Image$$__tz_OSPI_DEVICE_1_S$$Base; extern const uint32_t Image$$__tz_OPTION_SETTING_N$$Base; extern const uint32_t Image$$__tz_OPTION_SETTING_S$$Base; extern const uint32_t Image$$__tz_OPTION_SETTING_S_N$$Base; extern const uint32_t Image$$__tz_OPTION_SETTING_S_S$$Base; extern const uint32_t Image$$__tz_ID_CODE_N$$Base; extern const uint32_t Image$$__tz_ID_CODE_S$$Base; #define __tz_FLASH_N Image$$__tz_FLASH_N$$Base #define __tz_FLASH_C Image$$__tz_FLASH_C$$Base #define __tz_FLASH_S Image$$__tz_FLASH_S$$Base #define __tz_RAM_N Image$$__tz_RAM_N$$Base #define __tz_RAM_C Image$$__tz_RAM_C$$Base #define __tz_RAM_S Image$$__tz_RAM_S$$Base #define __tz_DATA_FLASH_N Image$$__tz_DATA_FLASH_N$$Base #define __tz_DATA_FLASH_S Image$$__tz_DATA_FLASH_S$$Base #define __tz_QSPI_FLASH_N Image$$__tz_QSPI_FLASH_N$$Base #define __tz_QSPI_FLASH_S Image$$__tz_QSPI_FLASH_S$$Base #define __tz_SDRAM_N Image$$__tz_SDRAM_N$$Base #define __tz_SDRAM_S Image$$__tz_SDRAM_S$$Base #define __tz_OSPI_DEVICE_0_N Image$$__tz_OSPI_DEVICE_0_N$$Base #define __tz_OSPI_DEVICE_0_S Image$$__tz_OSPI_DEVICE_0_S$$Base #define __tz_OSPI_DEVICE_1_N Image$$__tz_OSPI_DEVICE_1_N$$Base #define __tz_OSPI_DEVICE_1_S Image$$__tz_OSPI_DEVICE_1_S$$Base #define __tz_OPTION_SETTING_N Image$$__tz_OPTION_SETTING_N$$Base #define __tz_OPTION_SETTING_S Image$$__tz_OPTION_SETTING_S$$Base #define __tz_OPTION_SETTING_S_N Image$$__tz_OPTION_SETTING_S_N$$Base #define __tz_OPTION_SETTING_S_S Image$$__tz_OPTION_SETTING_S_S$$Base #define __tz_ID_CODE_N Image$$__tz_ID_CODE_N$$Base #define __tz_ID_CODE_S Image$$__tz_ID_CODE_S$$Base /* Assign region addresses to pointers so that AC6 includes symbols that can be used to determine the * start addresses of Secure, Non-secure and Non-secure Callable regions. */ BSP_DONT_REMOVE uint32_t const * const gp_start_of_nonsecure_flash = &__tz_FLASH_N; BSP_DONT_REMOVE uint32_t const * const gp_start_of_nonsecure_callable_flash = &__tz_FLASH_C; BSP_DONT_REMOVE uint32_t const * const gp_start_of_secure_flash = &__tz_FLASH_S; BSP_DONT_REMOVE uint32_t const * const gp_start_of_nonsecure_ram = &__tz_RAM_N; BSP_DONT_REMOVE uint32_t const * const gp_start_of_nonsecure_callable_ram = &__tz_RAM_C; BSP_DONT_REMOVE uint32_t const * const gp_start_of_secure_ram = &__tz_RAM_S; BSP_DONT_REMOVE uint32_t const * const gp_start_of_nonsecure_data_flash = &__tz_DATA_FLASH_N; BSP_DONT_REMOVE uint32_t const * const gp_start_of_secure_data_flash = &__tz_DATA_FLASH_S; #if BSP_TZ_SECURE_BUILD BSP_DONT_REMOVE uint32_t const * const gp_start_of_nonsecure_qspi_flash = &__tz_QSPI_FLASH_N; BSP_DONT_REMOVE uint32_t const * const gp_start_of_secure_qspi_flash = &__tz_QSPI_FLASH_S; BSP_DONT_REMOVE uint32_t const * const gp_start_of_nonsecure_sdram = &__tz_SDRAM_N; BSP_DONT_REMOVE uint32_t const * const gp_start_of_secure_sdram = &__tz_SDRAM_S; BSP_DONT_REMOVE uint32_t const * const gp_start_of_nonsecure_ospi_device_0 = &__tz_OSPI_DEVICE_0_N; BSP_DONT_REMOVE uint32_t const * const gp_start_of_secure_ospi_device_0 = &__tz_OSPI_DEVICE_0_S; BSP_DONT_REMOVE uint32_t const * const gp_start_of_nonsecure_ospi_device_1 = &__tz_OSPI_DEVICE_1_N; BSP_DONT_REMOVE uint32_t const * const gp_start_of_secure_ospi_device_1 = &__tz_OSPI_DEVICE_1_S; BSP_DONT_REMOVE uint32_t const * const gp_start_of_nonsecure_option_setting = &__tz_OPTION_SETTING_N; BSP_DONT_REMOVE uint32_t const * const gp_start_of_secure_option_setting = &__tz_OPTION_SETTING_S; BSP_DONT_REMOVE uint32_t const * const gp_start_of_nonsecure_option_setting_s = &__tz_OPTION_SETTING_S_N; BSP_DONT_REMOVE uint32_t const * const gp_start_of_secure_option_setting_s = &__tz_OPTION_SETTING_S_S; BSP_DONT_REMOVE uint32_t const * const gp_start_of_nonsecure_id_code = &__tz_ID_CODE_N; BSP_DONT_REMOVE uint32_t const * const gp_start_of_secure_id_code = &__tz_ID_CODE_S; #endif #elif defined(__GNUC__) extern const uint32_t FLASH_NS_IMAGE_START; BSP_DONT_REMOVE uint32_t const * const gp_start_of_nonsecure_flash = &FLASH_NS_IMAGE_START; #endif #if BSP_TZ_SECURE_BUILD /*******************************************************************************************************************//** * @addtogroup BSP_MCU * @{ **********************************************************************************************************************/ /*******************************************************************************************************************//** * Enter the non-secure code environment. * * This function configures the non-secure MSP and vector table then jumps to the non-secure project's Reset_Handler. * * @note This function (and therefore the non-secure code) should not return. **********************************************************************************************************************/ void R_BSP_NonSecureEnter (void) { /* The NS vector table is at the start of the NS section in flash */ uint32_t const * p_ns_vector_table = gp_start_of_nonsecure_flash; /* Set up the NS Reset_Handler to be called */ uint32_t const * p_ns_reset_address = (uint32_t const *) ((uint32_t) p_ns_vector_table + sizeof(uint32_t)); bsp_nonsecure_func_t p_ns_reset = (bsp_nonsecure_func_t) (*p_ns_reset_address); /* Set the NS vector table address */ SCB_NS->VTOR = (uint32_t) p_ns_vector_table; /* Set the NS stack pointer to the first entry in the NS vector table */ __TZ_set_MSP_NS(p_ns_vector_table[0]); /* Jump to the NS Reset_Handler */ p_ns_reset(); } /** @} (end addtogroup BSP_MCU) */ /*******************************************************************************************************************//** * Initialize security features for TrustZone. * * This function initializes ARM security register and Renesas SAR registers for secure projects. * * @note IDAU settings must be configured to match project settings with a separate configuration tool. **********************************************************************************************************************/ void R_BSP_SecurityInit (void) { /* Setting SAU_CTRL.ALLNS to 1 allows the security attribution of all addresses to be set by the IDAU in the * system. */ SAU->CTRL = SAU_CTRL_ALLNS_Msk; /* The following section of code to configure SCB->AIRCR, SCB->NSACR, and FPU->FPCCR is taken from * system_ARMCM33.c in the CMSIS_5 repository. SCB->SCR SLEEPDEEPS bit is not configured because the * SCB->SCR SLEEPDEEP bit is ignored on RA MCUs. */ #if defined(SCB_CSR_AIRCR_INIT) && (SCB_CSR_AIRCR_INIT == 1U) /* Configure whether non-secure projects have access to system reset, whether bus fault, hard fault, and NMI target * secure or non-secure, and whether non-secure interrupt priorities are reduced to the lowest 8 priority levels. */ SCB->AIRCR = (SCB->AIRCR & ~(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_SYSRESETREQS_Msk | SCB_AIRCR_BFHFNMINS_Msk | SCB_AIRCR_PRIS_Msk)) | BSP_PRV_AIRCR_VECTKEY | ((SCB_AIRCR_SYSRESETREQS_VAL << SCB_AIRCR_SYSRESETREQS_Pos) & SCB_AIRCR_SYSRESETREQS_Msk) | ((SCB_AIRCR_PRIS_VAL << SCB_AIRCR_PRIS_Pos) & SCB_AIRCR_PRIS_Msk) | ((SCB_AIRCR_BFHFNMINS_VAL << SCB_AIRCR_BFHFNMINS_Pos) & SCB_AIRCR_BFHFNMINS_Msk); #endif #if defined(__FPU_USED) && (__FPU_USED == 1U) && \ defined(TZ_FPU_NS_USAGE) && (TZ_FPU_NS_USAGE == 1U) /* Configure whether the FPU can be accessed in the non-secure project. */ SCB->NSACR = (SCB->NSACR & ~(SCB_NSACR_CP10_Msk | SCB_NSACR_CP11_Msk)) | ((SCB_NSACR_CP10_11_VAL << SCB_NSACR_CP10_Pos) & (SCB_NSACR_CP10_Msk | SCB_NSACR_CP11_Msk)); /* Configure whether FPU registers are always treated as non-secure (and therefore not preserved on the stack when * switching from secure to non-secure), and whether the FPU registers should be cleared on exception return. */ FPU->FPCCR = (FPU->FPCCR & ~(FPU_FPCCR_TS_Msk | FPU_FPCCR_CLRONRETS_Msk | FPU_FPCCR_CLRONRET_Msk)) | ((FPU_FPCCR_TS_VAL << FPU_FPCCR_TS_Pos) & FPU_FPCCR_TS_Msk) | ((FPU_FPCCR_CLRONRETS_VAL << FPU_FPCCR_CLRONRETS_Pos) & FPU_FPCCR_CLRONRETS_Msk) | ((FPU_FPCCR_CLRONRET_VAL << FPU_FPCCR_CLRONRET_Pos) & FPU_FPCCR_CLRONRET_Msk); #endif /* Disable PRCR for SARs. */ R_BSP_RegisterProtectDisable(BSP_REG_PROTECT_SAR); /* Set TrustZone filter to Secure. */ R_TZF->TZFSAR = ~R_TZF_TZFSAR_TZFSA0_Msk; /* Set TrustZone filter exception response. */ R_TZF->TZFPT = BSP_PRV_TZ_REG_KEY + 1U; R_TZF->TZFOAD = BSP_PRV_TZ_REG_KEY + BSP_TZ_CFG_EXCEPTION_RESPONSE; R_TZF->TZFPT = BSP_PRV_TZ_REG_KEY + 0U; /* Initialize PSARs. */ R_PSCU->PSARB = BSP_TZ_CFG_PSARB; R_PSCU->PSARC = BSP_TZ_CFG_PSARC; R_PSCU->PSARD = BSP_TZ_CFG_PSARD; R_PSCU->PSARE = BSP_TZ_CFG_PSARE; R_PSCU->MSSAR = BSP_TZ_CFG_MSSAR; /* Initialize Type 2 SARs. */ R_CPSCU->CSAR = BSP_TZ_CFG_CSAR; /* Cache Security Attribution. */ R_SYSTEM->RSTSAR = BSP_TZ_CFG_RSTSAR; /* RSTSRn Security Attribution. */ R_SYSTEM->LVDSAR = BSP_TZ_CFG_LVDSAR; /* LVD Security Attribution. */ R_SYSTEM->CGFSAR = BSP_TZ_CFG_CGFSAR; /* CGC Security Attribution. */ R_SYSTEM->LPMSAR = BSP_TZ_CFG_LPMSAR; /* LPM Security Attribution. */ R_SYSTEM->DPFSAR = BSP_TZ_CFG_DPFSAR; /* Deep Standby Interrupt Factor Security Attribution. */ #ifdef BSP_TZ_CFG_BBFSAR R_SYSTEM->BBFSAR = BSP_TZ_CFG_BBFSAR; /* Battery Backup Security Attribution. */ #endif R_CPSCU->ICUSARA = BSP_TZ_CFG_ICUSARA; /* External IRQ Security Attribution. */ R_CPSCU->ICUSARB = BSP_TZ_CFG_ICUSARB; /* NMI Security Attribution. */ R_CPSCU->ICUSARC = BSP_TZ_CFG_ICUSARC; /* DMAC Channel Security Attribution. */ R_CPSCU->ICUSARD = BSP_TZ_CFG_ICUSARD; /* SELSR0 Security Attribution. */ R_CPSCU->ICUSARE = BSP_TZ_CFG_ICUSARE; /* WUPEN0 Security Attribution. */ #ifdef BSP_TZ_CFG_ICUSARF R_CPSCU->ICUSARF = BSP_TZ_CFG_ICUSARF; /* WUPEN1 Security Attribution. */ #endif R_FCACHE->FSAR = BSP_TZ_CFG_FSAR; /* FLWT and FCKMHZ Security Attribution. */ R_CPSCU->SRAMSAR = BSP_TZ_CFG_SRAMSAR; /* SRAM Security Attribution. */ R_CPSCU->STBRAMSAR = BSP_TZ_CFG_STBRAMSAR; /* Standby RAM Security Attribution. */ R_CPSCU->MMPUSARA = BSP_TZ_CFG_MMPUSARA; /* Security Attribution for the DMAC Bus Master MPU. */ R_CPSCU->BUSSARA = BSP_TZ_CFG_BUSSARA; /* Security Attribution Register A for the BUS Control Registers. */ R_CPSCU->BUSSARB = BSP_TZ_CFG_BUSSARB; /* Security Attribution Register B for the BUS Control Registers. */ #if BSP_TZ_CFG_ICUSARC != UINT32_MAX R_BSP_MODULE_START(FSP_IP_DMAC, 0); /* If any DMAC channels are required by secure program, disable nonsecure write access to DMAST * in order to prevent the nonsecure program from disabling all DMAC channels. */ R_CPSCU->DMACSAR = ~1U; /* Protect DMAST from nonsecure write access. */ /* Ensure that DMAST is set so that the nonsecure program can use DMA. */ R_DMA->DMAST = 1U; #endif #if BSP_TZ_CFG_DTC_USED R_BSP_MODULE_START(FSP_IP_DTC, 0); /* If the DTC is used by the secure program, disable nonsecure write access to DTCST * in order to prevent the nonsecure program from disabling all DTC transfers. */ R_CPSCU->DTCSAR = ~1U; /* Ensure that DTCST is set so that the nonsecure program can use DTC. */ R_DTC->DTCST = 1U; #endif /* Initialize security attribution registers for Pins. */ R_BSP_PinCfgSecurityInit(); /* Initialize security attribution registers for ELC. */ R_BSP_ElcCfgSecurityInit(); /* Reenable PRCR for SARs. */ R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_SAR); } /* This function is overridden by tooling. */ BSP_WEAK_REFERENCE void R_BSP_PinCfgSecurityInit (void) { } /* This function is overridden by tooling. */ BSP_WEAK_REFERENCE void R_BSP_ElcCfgSecurityInit (void) { } #endif #endif
34b7cbce2feb37f726b4e6b48ff89cc16e145ba1
de21f9075f55640514c29ef0f1fe3f0690845764
/regression/cbmc-library/isnan-01/main.c
5f7de7da15fa634faf859576465d8d62efd662c1
[ "BSD-2-Clause", "LicenseRef-scancode-unknown-license-reference", "BSD-4-Clause" ]
permissive
diffblue/cbmc
975a074ac445febb3b5715f8792beb545522dc18
decd2839c2f51a54b2ad0f3e89fdc1b4bf78cd16
refs/heads/develop
2023-08-31T05:52:05.342195
2023-08-30T13:31:51
2023-08-30T13:31:51
51,877,056
589
309
NOASSERTION
2023-09-14T18:49:17
2016-02-16T23:03:52
C++
UTF-8
C
false
false
298
c
main.c
#include <assert.h> #include <math.h> #if defined(_WIN32) && !defined(__CYGWIN__) # include <float.h> # define isnan _isnan #endif float nondet_float(); int main() { float f = nondet_float(); double d = (double)f; float ff = (float)d; assert((f == ff) || (isnan(f) && isnan(ff))); }
8c8cbfa90830d83faf6767adcc172ac5a1e2f147
ef83d6a92b241e61334b815d956c266d813884e6
/src/PAL3Apatch/src/patch_reduceinputlatency.c
82cdf580410c3f7e1198f5f9647c15a9d27e5988
[]
no_license
zhangboyang/PAL3patch
29e569d2f052a280aae4e20024793657f6e7f8bb
976570626603cb35a113bba51bde872167f914d7
refs/heads/master
2023-08-14T02:24:00.159326
2023-08-03T15:20:01
2023-08-03T15:20:01
63,072,244
176
26
null
null
null
null
UTF-8
C
false
false
3,513
c
patch_reduceinputlatency.c
#include "common.h" // method1: reduce latency by doing event query after presenting each frame static void method1_hook() { IDirect3DQuery9 *pQuery; if (IDirect3DDevice9_CreateQuery(GB_GfxMgr->m_pd3dDevice, D3DQUERYTYPE_EVENT, &pQuery) == D3D_OK) { if (pQuery) { IDirect3DQuery9_Issue(pQuery, D3DISSUE_END); while (IDirect3DQuery9_GetData(pQuery, NULL, 0, D3DGETDATA_FLUSH) == S_FALSE); // busy wait IDirect3DQuery9_Release(pQuery); } } } static void method1_init() { add_postpresent_hook(method1_hook); } // method2: lock backbuffer before endscene, force flush command buffer static IDirect3DSurface9 *method2_pRenderTarget = NULL; static void method2_release_rendertarget() { if (method2_pRenderTarget) { IDirect3DSurface9_Release(method2_pRenderTarget); method2_pRenderTarget = NULL; } } static void method2_create_rendertarget() { assert(method2_pRenderTarget == NULL); // get backbuffer format D3DSURFACE_DESC desc; IDirect3DSurface9 *pBackBuffer = NULL; if (FAILED(IDirect3DDevice9_GetBackBuffer(GB_GfxMgr->m_pd3dDevice, 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer))) { pBackBuffer = NULL; goto done; } if (FAILED(IDirect3DSurface9_GetDesc(pBackBuffer, &desc))) { goto done; } if (FAILED(IDirect3DDevice9_CreateRenderTarget(GB_GfxMgr->m_pd3dDevice, desc.Width, desc.Height, desc.Format, D3DMULTISAMPLE_NONE, 0, TRUE, &method2_pRenderTarget, NULL))) { method2_pRenderTarget = NULL; goto done; } done: if (pBackBuffer) IDirect3DSurface9_Release(pBackBuffer); } static void method2_onlostdevice() { method2_release_rendertarget(); } static void method2_onresetdevice() { method2_create_rendertarget(); } static void method2_postd3dcreate_hook() { method2_create_rendertarget(); } static void method2_preendscene_hook() { if (!method2_pRenderTarget) return; IDirect3DSurface9 *pBackBuffer = NULL; // get back buffer if (FAILED(IDirect3DDevice9_GetBackBuffer(GB_GfxMgr->m_pd3dDevice, 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer))) { warning("can't get back buffer."); pBackBuffer = NULL; goto done; } // copy backbuffer to render target if (FAILED(IDirect3DDevice9_StretchRect(GB_GfxMgr->m_pd3dDevice, pBackBuffer, NULL, method2_pRenderTarget, NULL, D3DTEXF_POINT))) { warning("can't stretch rect."); goto done; } // lock the render target D3DLOCKED_RECT lrect; if (FAILED(IDirect3DSurface9_LockRect(method2_pRenderTarget, &lrect, NULL, 0))) { warning("can't lock rect."); goto done; } // FIXME: should we touch the memory at lrect.pBits // unlock the render target IDirect3DSurface9_UnlockRect(method2_pRenderTarget); done: if (pBackBuffer) IDirect3DSurface9_Release(pBackBuffer); } static void method2_init() { add_postd3dcreate_hook(method2_postd3dcreate_hook); add_preendscene_hook(method2_preendscene_hook); add_onlostdevice_hook(method2_onlostdevice); add_onresetdevice_hook(method2_onresetdevice); } MAKE_PATCHSET(reduceinputlatency) { switch (flag) { case 1: method1_init(); break; case 2: method2_init(); break; default: fail("invalid reduce input latency configuration %d.", flag); } }
c231b3b3211db6475fd5ba010df374f153989a6b
67305fcba68fdf469862aed2959ad1dd5b22a536
/examples/29_iot_web_server/packages/webnet-v2.0.1/src/wn_module.c
0b9af0f07353bf0ea38e31fa80ce25c693c696c7
[ "Apache-2.0", "GPL-2.0-only", "GPL-2.0-or-later", "GPL-1.0-or-later" ]
permissive
RT-Thread/IoT_Board
cdabf100a8d515fbcaa65ab0b72ec67acb0d2c9a
2d218a4e06f06dbb356ec00767904f91d00db7cc
refs/heads/master
2023-09-04T16:51:34.485240
2022-01-19T01:26:16
2022-01-19T01:26:16
161,133,933
344
238
Apache-2.0
2023-06-06T04:10:57
2018-12-10T07:21:46
C
UTF-8
C
false
false
15,621
c
wn_module.c
/* * File : wn_module.c * This file is part of RT-Thread RTOS * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team * * This software is dual-licensed: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. For the terms of this * license, see <http://www.gnu.org/licenses/>. * * You are free to use this software under the terms of the GNU General * Public License, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * Alternatively for commercial application, you can contact us * by email <business@rt-thread.com> for commercial license. * * Change Logs: * Date Author Notes * 2011-08-02 Bernard the first version * 2012-06-25 Bernard add SSI and Upload module */ #include <stdio.h> #include <string.h> #include <time.h> #include <webnet.h> #include <wn_module.h> #include <wn_utils.h> #ifdef RT_USING_DFS #include <dfs_posix.h> #endif static int _webnet_module_system_init(struct webnet_session *session, int event) { #ifdef WEBNET_USING_LOG webnet_module_log(session, event); #endif #ifdef WEBNET_USING_SSL webnet_module_ssl(session, event); #endif #ifdef WEBNET_USING_CGI webnet_module_cgi(session, event); #endif #ifdef WEBNET_USING_DMR webnet_module_dmr(session, event); #endif return WEBNET_MODULE_CONTINUE; } static int _webnet_module_system_uri_physical(struct webnet_session *session, int event) { int result; result = WEBNET_MODULE_CONTINUE; #ifdef WEBNET_USING_LOG webnet_module_log(session, event); #endif #ifdef WEBNET_USING_ALIAS result = webnet_module_alias(session, event); if (result == WEBNET_MODULE_FINISHED) return result; #endif #ifdef WEBNET_USING_AUTH result = webnet_module_auth(session, event); if (result == WEBNET_MODULE_FINISHED) return result; #endif #ifdef WEBNET_USING_CGI result = webnet_module_cgi(session, event); if (result == WEBNET_MODULE_FINISHED) return result; #endif #ifdef WEBNET_USING_DMR result = webnet_module_dmr(session, event); if (result == WEBNET_MODULE_FINISHED) return result; #endif #ifdef WEBNET_USING_UPLOAD result = webnet_module_upload(session, event); if (result == WEBNET_MODULE_FINISHED) return result; #endif return result; } static void _webnet_dofile_handle(struct webnet_session *session, int event) { int fd = session->user_data; if (event & WEBNET_EVENT_WRITE) { rt_size_t readbytes; rt_size_t length = RT_ALIGN_DOWN(WEBNET_SESSION_BUFSZ, 4); #ifdef WEBNET_USING_RANGE if(session->request->Range) { length = session->request->pos_end - session->request->pos_start; if(length == 0) { goto __exit; } if(length > WEBNET_SESSION_BUFSZ) { length = WEBNET_SESSION_BUFSZ; } lseek(fd, session->request->pos_start, SEEK_SET); session->request->pos_start += length; } #endif readbytes = read(fd, session->buffer, length); if (readbytes <= 0) /* end of file */ goto __exit; if (webnet_session_write(session, session->buffer, readbytes) == 0) goto __exit; return; } __exit: close(fd); session->user_data = 0; session->session_event_mask = 0; /* clean event */ /* destroy session */ session->session_phase = WEB_PHASE_CLOSE; return; } static const struct webnet_session_ops _dofile_ops = { _webnet_dofile_handle, RT_NULL }; /* send a file to http client */ int webnet_module_system_dofile(struct webnet_session *session) { int fd = -1; /* file descriptor */ struct stat file_stat; const char *mimetype; rt_size_t file_length; struct webnet_request *request; #if WEBNET_CACHE_LEVEL > 0 char ctime_str[32]; int stat_result = -1; #endif /* WEBNET_CACHE_LEVEL */ RT_ASSERT(session != RT_NULL); request = session->request; RT_ASSERT(request != RT_NULL); #if WEBNET_CACHE_LEVEL > 0 #ifdef WEBNET_USING_GZIP /* get .gz Last-Modified. */ if (request->support_gzip) { struct stat file_stat; char *path_gz = wn_malloc(strlen(request->path) + 4); /* ".gz\0" */ if (path_gz != RT_NULL) { sprintf(path_gz, "%s.gz", request->path); stat_result = stat(request->path, &file_stat); wn_free(path_gz); } if (stat_result == 0) { rt_enter_critical(); strcpy(ctime_str, ctime((time_t *)&file_stat.st_mtime)); rt_exit_critical(); ctime_str[strlen(ctime_str) - 1] = '\0'; /* clear the end \n */ if ((request->modified != RT_NULL) && (strcmp(request->modified, ctime_str) == 0)) { request->result_code = 304; return WEBNET_MODULE_FINISHED; } } } /* .gz not exist, use raw. */ #endif /* WEBNET_USING_GZIP */ /* get Last-Modified. */ if (stat_result != 0) { struct stat file_stat; stat_result = stat(request->path, &file_stat); if (stat_result == 0) { rt_enter_critical(); strcpy(ctime_str, ctime((time_t *)&file_stat.st_mtime)); rt_exit_critical(); ctime_str[strlen(ctime_str) - 1] = '\0'; /* clear the end \n */ if ((request->modified != RT_NULL) && (strcmp(request->modified, ctime_str) == 0)) { request->result_code = 304; return WEBNET_MODULE_FINISHED; } } } #endif /* WEBNET_CACHE_LEVEL > 0 */ /* get mime type */ mimetype = mime_get_type(request->path); #ifdef WEBNET_USING_GZIP if (request->support_gzip) { char *path_gz = wn_malloc(strlen(request->path) + 4); /* ".gz\0" */ if (path_gz != RT_NULL) { sprintf(path_gz, "%s.gz", request->path); fd = open(path_gz, O_RDONLY, 0); wn_free(path_gz); if (fd < 0) { /* .gz not exist, use raw. */ request->support_gzip = RT_FALSE; } } } /* .gz not exist, use raw. */ #endif /* WEBNET_USING_GZIP */ if (fd < 0 && stat(request->path, &file_stat) >= 0 && !S_ISDIR(file_stat.st_mode)) { fd = open(request->path, O_RDONLY, 0); } if (fd < 0) { request->result_code = 404; return WEBNET_MODULE_FINISHED; } /* get file size */ file_length = lseek(fd, 0, SEEK_END); /* seek to beginning of file */ lseek(fd, 0, SEEK_SET); /*************todo**********************/ #ifdef WEBNET_USING_RANGE if (request->Range) { char *range_start, *range_end; int32_t pos_start = 0; uint32_t pos_end = file_length - 1; range_start = strstr(request->Range, "bytes="); if (range_start) { range_start += 6; range_end = strstr(range_start, "-"); if (range_start == range_end) pos_start = 0; else pos_start = atoi(range_start); /* send file to remote */ if ((!range_end) || (strstr(range_start, ","))) { request->result_code = 400; goto _error_exit; } if (range_end) { *range_end = '\0'; range_end += 1; pos_end = atoi(range_end); } } #ifdef WEBNET_USING_GZIP if (request->support_gzip) { pos_start = 0; /* */ } #endif /* WEBNET_USING_GZIP */ if ((pos_start >= file_length) || (pos_end >= file_length)) { request->result_code = 416; webnet_session_set_header_status_line(session, request->result_code, "Requested Range Not Satisfiable"); goto _error_exit; } if (lseek(fd, pos_start, SEEK_SET) != pos_start) { request->result_code = 500; goto _error_exit; } if (pos_end == 0) { pos_end = file_length - 1; } file_length = pos_end - pos_start + 1; request->result_code = 216; request->pos_start = pos_start; request->pos_end = pos_end; webnet_session_set_header_status_line(session, request->result_code, "Partial Content"); webnet_session_printf(session, "Content-Range: %d-%d/%d\r\n", pos_start, pos_end, file_length); }else #endif /* WEBNET_USING_RANGE */ /*************todo**********************/ { /* send file to remote */ request->result_code = 200; webnet_session_set_header_status_line(session, request->result_code, "OK"); } #if WEBNET_CACHE_LEVEL > 0 /* send Last-Modified. */ webnet_session_printf(session, "Last-Modified: %s\r\n", ctime_str); #endif /* WEBNET_CACHE_LEVEL > 0 */ #if WEBNET_CACHE_LEVEL > 1 /* Cache-Control. */ webnet_session_printf(session, "Cache-Control: max-age=%d\r\n", WEBNET_CACHE_MAX_AGE); #endif /* WEBNET_CACHE_LEVEL > 1 */ /* send Content-Type. */ webnet_session_printf(session, "Content-Type: %s\r\n", mimetype); /* send Content-Length. */ webnet_session_printf(session, "Content-Length: %ld\r\n", file_length); #ifdef WEBNET_USING_KEEPALIVE if(session->request->connection == WEBNET_CONN_KEEPALIVE) { webnet_session_printf(session, "Connection: %s\r\n", "Keep-Alive"); } else { webnet_session_printf(session, "Connection: %s\r\n", "close"); } #else webnet_session_printf(session, "Connection: %s\r\n", "close"); #endif #ifdef WEBNET_USING_GZIP if (request->support_gzip) { /* gzip deflate. */ webnet_session_printf(session, "Content-Encoding: gzip\r\n"); } #endif /* WEBNET_USING_GZIP */ /* send Access-Control-Allow-Origin. */ webnet_session_printf(session, "Access-Control-Allow-Origin:*\r\n"); /* send http header end. */ webnet_session_printf(session, "\r\n"); if (file_length <= 0) { close(fd); return WEBNET_MODULE_FINISHED; } /* * set session write context */ if (request->method != WEBNET_HEADER) { /* set dofile session ops */ session->session_event_mask = WEBNET_EVENT_WRITE; session->user_data = (rt_uint32_t)fd; session->session_ops = &_dofile_ops; } return WEBNET_MODULE_FINISHED; _error_exit: if (fd >= 0) { close(fd); } return WEBNET_MODULE_FINISHED; } static int _webnet_module_system_uri_post(struct webnet_session *session, int event) { int result; result = WEBNET_MODULE_CONTINUE; #ifdef WEBNET_USING_LOG webnet_module_log(session, event); #endif #ifdef WEBNET_USING_LUA result = webnet_module_lua(session, event); if (result == WEBNET_MODULE_FINISHED) return result; #endif #ifdef WEBNET_USING_ASP result = webnet_module_asp(session, event); if (result == WEBNET_MODULE_FINISHED) return result; #endif #ifdef WEBNET_USING_SSI result = webnet_module_ssi(session, event); if (result == WEBNET_MODULE_FINISHED) return result; #endif #ifdef WEBNET_USING_DAV result = webnet_module_dav(session, event); if (result == WEBNET_MODULE_FINISHED) return result; #endif #ifdef WEBNET_USING_INDEX result = webnet_module_dirindex(session, event); if (result == WEBNET_MODULE_FINISHED) return result; #endif /* always module finished in dofile */ result = webnet_module_system_dofile(session); if (result == WEBNET_MODULE_FINISHED) return result; return WEBNET_MODULE_CONTINUE; } static int _webnet_module_system_response_header(struct webnet_session *session, int event) { int result; result = WEBNET_MODULE_CONTINUE; return result; } static int _webnet_module_system_response_file(struct webnet_session *session, int event) { int result; result = WEBNET_MODULE_CONTINUE; return result; } int webnet_module_handle_event(struct webnet_session *session, int event) { switch (event) { case WEBNET_EVENT_INIT: return _webnet_module_system_init(session, event); case WEBNET_EVENT_URI_PHYSICAL: return _webnet_module_system_uri_physical(session, event); case WEBNET_EVENT_URI_POST: return _webnet_module_system_uri_post(session, event); case WEBNET_EVENT_RSP_HEADER: return _webnet_module_system_response_header(session, event); case WEBNET_EVENT_RSP_FILE: return _webnet_module_system_response_file(session, event); default: RT_ASSERT(0); break; } return WEBNET_MODULE_CONTINUE; } /* default index file */ static const char *default_files[] = { "", "/index.html", "/index.htm", RT_NULL }; /** * handle uri * there are two phases on uri handling: * - map url to physical * - url handling */ int webnet_module_handle_uri(struct webnet_session *session) { int result, fd; char *full_path; rt_uint32_t index; struct webnet_request *request; RT_ASSERT(session != RT_NULL); /* get request */ request = session->request; RT_ASSERT(request != RT_NULL); /* map uri to physical */ result = webnet_module_handle_event(session, WEBNET_EVENT_URI_PHYSICAL); if (result == WEBNET_MODULE_FINISHED) return result; /* made a full physical path */ full_path = (char *) wn_malloc(WEBNET_PATH_MAX); RT_ASSERT(full_path != RT_NULL); /* only GET or POST need try default page. */ if ((session->request->method != WEBNET_GET) && (session->request->method != WEBNET_POST)) { index = sizeof(default_files) / sizeof(default_files[0]); index -= 1; goto _end_default_files; } index = 0; while (default_files[index] != RT_NULL) { struct stat file_stat; /* made a full path */ rt_snprintf(full_path, WEBNET_PATH_MAX, "%s/%s%s", webnet_get_root(), request->path, default_files[index]); /* normalize path */ str_normalize_path(full_path); if (stat(full_path, &file_stat) >= 0 && !S_ISDIR(file_stat.st_mode)) { break; } index ++; } _end_default_files: /* no this file */ if (default_files[index] == RT_NULL) { /* use old full path */ rt_snprintf(full_path, WEBNET_PATH_MAX, "%s/%s", webnet_get_root(), request->path); /* normalize path */ str_normalize_path(full_path); } /* mark path as full physical path */ wn_free(request->path); request->path = full_path; /* check uri valid */ if (!str_begin_with(request->path, webnet_get_root())) { /* not found */ request->result_code = 404; return WEBNET_MODULE_FINISHED; } /* uri post handle */ return webnet_module_handle_event(session, WEBNET_EVENT_URI_POST); }
31fb7f290e5638599b32da1939c2c76765c973b9
3f55217e912141e04815bc8bcb6fbd5638d0896e
/src/rt/pmapdiag.h
4c561d0665378a471456619f0b09872f5cc62afb
[ "BSD-2-Clause" ]
permissive
NREL/Radiance
bfbb93c99d86368ad0f27052a2a5504aeced47f8
2fcca99ace2f2435f32a09525ad31f2b3be3c1bc
refs/heads/master
2021-12-26T12:42:04.586614
2021-12-18T00:43:56
2021-12-18T00:43:56
8,210,805
164
68
NOASSERTION
2019-06-06T19:57:11
2013-02-15T00:47:56
C
UTF-8
C
false
false
1,679
h
pmapdiag.h
/* RCSid $Id: pmapdiag.h,v 2.7 2016/05/17 17:39:47 rschregle Exp $ */ /* ================================================================== Photon map diagnostic output and progress reports Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) (c) Fraunhofer Institute for Solar Energy Systems, (c) Lucerne University of Applied Sciences and Arts, supported by the Swiss National Science Foundation (SNSF, #147053) ================================================================== $Id: pmapdiag.h,v 2.7 2016/05/17 17:39:47 rschregle Exp $ */ #ifndef PMAPDIAG_H #define PMAPDIAG_H #include "platform.h" #ifdef NON_POSIX #ifdef MINGW #include <sys/time.h> #endif #else #ifdef BSD #include <sys/time.h> #include <sys/resource.h> #else #include <sys/times.h> #include <unistd.h> #endif #endif #include <time.h> #include <signal.h> /* Time at start & last report */ extern time_t repStartTime, repLastTime; /* Report progress & completion counters */ extern unsigned long repProgress, repComplete, repEmitted; void pmapDistribReport (); /* Report photon distribution progress */ void pmapPreCompReport (); /* Report global photon precomputation progress */ void pmapBiasCompReport (char *stats); /* Append full bias compensation statistics to stats; interface to * rpict's report() */ #ifdef PMAP_OOC void pmapOOCCacheReport (char *stats); /* Append full OOC I/O cache statistics to stats; interface to rpict's * report() */ #endif #endif
bdb617d988c6136de8f2b2901d88cbe1d5217189
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/sound/pci/hda/patch_cmedia.c
9c6ce73b03c5585994ee4099106a70dbe7cca51c
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
19,772
c
patch_cmedia.c
/* * Universal Interface for Intel High Definition Audio Codec * * HD audio interface patch for C-Media CMI9880 * * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de> * * * This driver is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This driver is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/init.h> #include <linux/slab.h> #include <linux/pci.h> #include <linux/module.h> #include <sound/core.h> #include "hda_codec.h" #include "hda_local.h" #include "hda_auto_parser.h" #include "hda_jack.h" #include "hda_generic.h" #define NUM_PINS 11 /* board config type */ enum { CMI_MINIMAL, /* back 3-jack */ CMI_MIN_FP, /* back 3-jack + front-panel 2-jack */ CMI_FULL, /* back 6-jack + front-panel 2-jack */ CMI_FULL_DIG, /* back 6-jack + front-panel 2-jack + digital I/O */ CMI_ALLOUT, /* back 5-jack + front-panel 2-jack + digital out */ CMI_AUTO, /* let driver guess it */ CMI_MODELS }; struct cmi_spec { struct hda_gen_spec gen; /* below are only for static models */ int board_config; unsigned int no_line_in: 1; /* no line-in (5-jack) */ unsigned int front_panel: 1; /* has front-panel 2-jack */ /* playback */ struct hda_multi_out multiout; hda_nid_t dac_nids[AUTO_CFG_MAX_OUTS]; /* NID for each DAC */ int num_dacs; /* capture */ const hda_nid_t *adc_nids; hda_nid_t dig_in_nid; /* capture source */ const struct hda_input_mux *input_mux; unsigned int cur_mux[2]; /* channel mode */ int num_channel_modes; const struct hda_channel_mode *channel_modes; struct hda_pcm pcm_rec[2]; /* PCM information */ /* pin default configuration */ hda_nid_t pin_nid[NUM_PINS]; unsigned int def_conf[NUM_PINS]; unsigned int pin_def_confs; /* multichannel pins */ struct hda_verb multi_init[9]; /* 2 verbs for each pin + terminator */ }; /* * input MUX */ static int cmi_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct cmi_spec *spec = codec->spec; return snd_hda_input_mux_info(spec->input_mux, uinfo); } static int cmi_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct cmi_spec *spec = codec->spec; unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; return 0; } static int cmi_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct cmi_spec *spec = codec->spec; unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]); } /* * shared line-in, mic for surrounds */ /* 3-stack / 2 channel */ static const struct hda_verb cmi9880_ch2_init[] = { /* set line-in PIN for input */ { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* set mic PIN for input, also enable vref */ { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* route front PCM (DAC1) to HP */ { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 }, {} }; /* 3-stack / 6 channel */ static const struct hda_verb cmi9880_ch6_init[] = { /* set line-in PIN for output */ { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* set mic PIN for output */ { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* route front PCM (DAC1) to HP */ { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 }, {} }; /* 3-stack+front / 8 channel */ static const struct hda_verb cmi9880_ch8_init[] = { /* set line-in PIN for output */ { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* set mic PIN for output */ { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* route rear-surround PCM (DAC4) to HP */ { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x03 }, {} }; static const struct hda_channel_mode cmi9880_channel_modes[3] = { { 2, cmi9880_ch2_init }, { 6, cmi9880_ch6_init }, { 8, cmi9880_ch8_init }, }; static int cmi_ch_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct cmi_spec *spec = codec->spec; return snd_hda_ch_mode_info(codec, uinfo, spec->channel_modes, spec->num_channel_modes); } static int cmi_ch_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct cmi_spec *spec = codec->spec; return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_modes, spec->num_channel_modes, spec->multiout.max_channels); } static int cmi_ch_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct cmi_spec *spec = codec->spec; return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_modes, spec->num_channel_modes, &spec->multiout.max_channels); } /* */ static const struct snd_kcontrol_new cmi9880_basic_mixer[] = { /* CMI9880 has no playback volumes! */ HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT), /* front */ HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0x0, HDA_OUTPUT), HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT), HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT), HDA_CODEC_MUTE("Side Playback Switch", 0x06, 0x0, HDA_OUTPUT), { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, /* The multiple "Capture Source" controls confuse alsamixer * So call somewhat different.. */ /* .name = "Capture Source", */ .name = "Input Source", .count = 2, .info = cmi_mux_enum_info, .get = cmi_mux_enum_get, .put = cmi_mux_enum_put, }, HDA_CODEC_VOLUME("Capture Volume", 0x08, 0, HDA_INPUT), HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0, HDA_INPUT), HDA_CODEC_MUTE("Capture Switch", 0x08, 0, HDA_INPUT), HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0, HDA_INPUT), HDA_CODEC_VOLUME("Beep Playback Volume", 0x23, 0, HDA_OUTPUT), HDA_CODEC_MUTE("Beep Playback Switch", 0x23, 0, HDA_OUTPUT), { } /* end */ }; /* * shared I/O pins */ static const struct snd_kcontrol_new cmi9880_ch_mode_mixer[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Channel Mode", .info = cmi_ch_mode_info, .get = cmi_ch_mode_get, .put = cmi_ch_mode_put, }, { } /* end */ }; /* AUD-in selections: * 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x1f 0x20 */ static const struct hda_input_mux cmi9880_basic_mux = { .num_items = 4, .items = { { "Front Mic", 0x5 }, { "Rear Mic", 0x2 }, { "Line", 0x1 }, { "CD", 0x7 }, } }; static const struct hda_input_mux cmi9880_no_line_mux = { .num_items = 3, .items = { { "Front Mic", 0x5 }, { "Rear Mic", 0x2 }, { "CD", 0x7 }, } }; /* front, rear, clfe, rear_surr */ static const hda_nid_t cmi9880_dac_nids[4] = { 0x03, 0x04, 0x05, 0x06 }; /* ADC0, ADC1 */ static const hda_nid_t cmi9880_adc_nids[2] = { 0x08, 0x09 }; #define CMI_DIG_OUT_NID 0x07 #define CMI_DIG_IN_NID 0x0a /* */ static const struct hda_verb cmi9880_basic_init[] = { /* port-D for line out (rear panel) */ { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* port-E for HP out (front panel) */ { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* route front PCM to HP */ { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 }, /* port-A for surround (rear panel) */ { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* port-G for CLFE (rear panel) */ { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x02 }, /* port-H for side (rear panel) */ { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, { 0x20, AC_VERB_SET_CONNECT_SEL, 0x01 }, /* port-C for line-in (rear panel) */ { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* port-B for mic-in (rear panel) with vref */ { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* port-F for mic-in (front panel) with vref */ { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* CD-in */ { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* route front mic to ADC1/2 */ { 0x08, AC_VERB_SET_CONNECT_SEL, 0x05 }, { 0x09, AC_VERB_SET_CONNECT_SEL, 0x05 }, {} /* terminator */ }; static const struct hda_verb cmi9880_allout_init[] = { /* port-D for line out (rear panel) */ { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* port-E for HP out (front panel) */ { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* route front PCM to HP */ { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 }, /* port-A for side (rear panel) */ { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* port-G for CLFE (rear panel) */ { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x02 }, /* port-H for side (rear panel) */ { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, { 0x20, AC_VERB_SET_CONNECT_SEL, 0x01 }, /* port-C for surround (rear panel) */ { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* port-B for mic-in (rear panel) with vref */ { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* port-F for mic-in (front panel) with vref */ { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* CD-in */ { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* route front mic to ADC1/2 */ { 0x08, AC_VERB_SET_CONNECT_SEL, 0x05 }, { 0x09, AC_VERB_SET_CONNECT_SEL, 0x05 }, {} /* terminator */ }; /* */ static int cmi9880_build_controls(struct hda_codec *codec) { struct cmi_spec *spec = codec->spec; struct snd_kcontrol *kctl; int i, err; err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer); if (err < 0) return err; if (spec->channel_modes) { err = snd_hda_add_new_ctls(codec, cmi9880_ch_mode_mixer); if (err < 0) return err; } if (spec->multiout.dig_out_nid) { err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid, spec->multiout.dig_out_nid); if (err < 0) return err; err = snd_hda_create_spdif_share_sw(codec, &spec->multiout); if (err < 0) return err; spec->multiout.share_spdif = 1; } if (spec->dig_in_nid) { err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); if (err < 0) return err; } /* assign Capture Source enums to NID */ kctl = snd_hda_find_mixer_ctl(codec, "Capture Source"); for (i = 0; kctl && i < kctl->count; i++) { err = snd_hda_add_nid(codec, kctl, i, spec->adc_nids[i]); if (err < 0) return err; } return 0; } static int cmi9880_init(struct hda_codec *codec) { struct cmi_spec *spec = codec->spec; if (spec->board_config == CMI_ALLOUT) snd_hda_sequence_write(codec, cmi9880_allout_init); else snd_hda_sequence_write(codec, cmi9880_basic_init); if (spec->board_config == CMI_AUTO) snd_hda_sequence_write(codec, spec->multi_init); return 0; } /* * Analog playback callbacks */ static int cmi9880_playback_pcm_open(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct cmi_spec *spec = codec->spec; return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, hinfo); } static int cmi9880_playback_pcm_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream) { struct cmi_spec *spec = codec->spec; return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream); } static int cmi9880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct cmi_spec *spec = codec->spec; return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); } /* * Digital out */ static int cmi9880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct cmi_spec *spec = codec->spec; return snd_hda_multi_out_dig_open(codec, &spec->multiout); } static int cmi9880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct cmi_spec *spec = codec->spec; return snd_hda_multi_out_dig_close(codec, &spec->multiout); } static int cmi9880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream) { struct cmi_spec *spec = codec->spec; return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag, format, substream); } /* * Analog capture */ static int cmi9880_capture_pcm_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream) { struct cmi_spec *spec = codec->spec; snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], stream_tag, 0, format); return 0; } static int cmi9880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct cmi_spec *spec = codec->spec; snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); return 0; } /* */ static const struct hda_pcm_stream cmi9880_pcm_analog_playback = { .substreams = 1, .channels_min = 2, .channels_max = 8, .nid = 0x03, /* NID to query formats and rates */ .ops = { .open = cmi9880_playback_pcm_open, .prepare = cmi9880_playback_pcm_prepare, .cleanup = cmi9880_playback_pcm_cleanup }, }; static const struct hda_pcm_stream cmi9880_pcm_analog_capture = { .substreams = 2, .channels_min = 2, .channels_max = 2, .nid = 0x08, /* NID to query formats and rates */ .ops = { .prepare = cmi9880_capture_pcm_prepare, .cleanup = cmi9880_capture_pcm_cleanup }, }; static const struct hda_pcm_stream cmi9880_pcm_digital_playback = { .substreams = 1, .channels_min = 2, .channels_max = 2, /* NID is set in cmi9880_build_pcms */ .ops = { .open = cmi9880_dig_playback_pcm_open, .close = cmi9880_dig_playback_pcm_close, .prepare = cmi9880_dig_playback_pcm_prepare }, }; static const struct hda_pcm_stream cmi9880_pcm_digital_capture = { .substreams = 1, .channels_min = 2, .channels_max = 2, /* NID is set in cmi9880_build_pcms */ }; static int cmi9880_build_pcms(struct hda_codec *codec) { struct cmi_spec *spec = codec->spec; struct hda_pcm *info = spec->pcm_rec; codec->num_pcms = 1; codec->pcm_info = info; info->name = "CMI9880"; info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_analog_playback; info->stream[SNDRV_PCM_STREAM_CAPTURE] = cmi9880_pcm_analog_capture; if (spec->multiout.dig_out_nid || spec->dig_in_nid) { codec->num_pcms++; info++; info->name = "CMI9880 Digital"; info->pcm_type = HDA_PCM_TYPE_SPDIF; if (spec->multiout.dig_out_nid) { info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_digital_playback; info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; } if (spec->dig_in_nid) { info->stream[SNDRV_PCM_STREAM_CAPTURE] = cmi9880_pcm_digital_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; } } return 0; } static void cmi9880_free(struct hda_codec *codec) { kfree(codec->spec); } /* */ static const char * const cmi9880_models[CMI_MODELS] = { [CMI_MINIMAL] = "minimal", [CMI_MIN_FP] = "min_fp", [CMI_FULL] = "full", [CMI_FULL_DIG] = "full_dig", [CMI_ALLOUT] = "allout", [CMI_AUTO] = "auto", }; static const struct snd_pci_quirk cmi9880_cfg_tbl[] = { SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", CMI_FULL_DIG), SND_PCI_QUIRK(0x1854, 0x002b, "LG LS75", CMI_MINIMAL), SND_PCI_QUIRK(0x1854, 0x0032, "LG", CMI_FULL_DIG), {} /* terminator */ }; static const struct hda_codec_ops cmi9880_patch_ops = { .build_controls = cmi9880_build_controls, .build_pcms = cmi9880_build_pcms, .init = cmi9880_init, .free = cmi9880_free, }; /* * stuff for auto-parser */ static const struct hda_codec_ops cmi_auto_patch_ops = { .build_controls = snd_hda_gen_build_controls, .build_pcms = snd_hda_gen_build_pcms, .init = snd_hda_gen_init, .free = snd_hda_gen_free, .unsol_event = snd_hda_jack_unsol_event, }; static int cmi_parse_auto_config(struct hda_codec *codec) { struct cmi_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->gen.autocfg; int err; snd_hda_gen_spec_init(&spec->gen); err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0); if (err < 0) return err; err = snd_hda_gen_parse_auto_config(codec, cfg); if (err < 0) return err; codec->patch_ops = cmi_auto_patch_ops; return 0; } static int patch_cmi9880(struct hda_codec *codec) { struct cmi_spec *spec; spec = kzalloc(sizeof(*spec), GFP_KERNEL); if (spec == NULL) return -ENOMEM; codec->spec = spec; spec->board_config = snd_hda_check_board_config(codec, CMI_MODELS, cmi9880_models, cmi9880_cfg_tbl); if (spec->board_config < 0) { snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", codec->chip_name); spec->board_config = CMI_AUTO; /* try everything */ } if (spec->board_config == CMI_AUTO) { int err = cmi_parse_auto_config(codec); if (err < 0) { snd_hda_gen_free(codec); return err; } return 0; } /* copy default DAC NIDs */ memcpy(spec->dac_nids, cmi9880_dac_nids, sizeof(spec->dac_nids)); spec->num_dacs = 4; switch (spec->board_config) { case CMI_MINIMAL: case CMI_MIN_FP: spec->channel_modes = cmi9880_channel_modes; if (spec->board_config == CMI_MINIMAL) spec->num_channel_modes = 2; else { spec->front_panel = 1; spec->num_channel_modes = 3; } spec->multiout.max_channels = cmi9880_channel_modes[0].channels; spec->input_mux = &cmi9880_basic_mux; break; case CMI_FULL: case CMI_FULL_DIG: spec->front_panel = 1; spec->multiout.max_channels = 8; spec->input_mux = &cmi9880_basic_mux; if (spec->board_config == CMI_FULL_DIG) { spec->multiout.dig_out_nid = CMI_DIG_OUT_NID; spec->dig_in_nid = CMI_DIG_IN_NID; } break; case CMI_ALLOUT: default: spec->front_panel = 1; spec->multiout.max_channels = 8; spec->no_line_in = 1; spec->input_mux = &cmi9880_no_line_mux; spec->multiout.dig_out_nid = CMI_DIG_OUT_NID; break; } spec->multiout.num_dacs = spec->num_dacs; spec->multiout.dac_nids = spec->dac_nids; spec->adc_nids = cmi9880_adc_nids; codec->patch_ops = cmi9880_patch_ops; return 0; } /* * patch entries */ static const struct hda_codec_preset snd_hda_preset_cmedia[] = { { .id = 0x13f69880, .name = "CMI9880", .patch = patch_cmi9880 }, { .id = 0x434d4980, .name = "CMI9880", .patch = patch_cmi9880 }, {} /* terminator */ }; MODULE_ALIAS("snd-hda-codec-id:13f69880"); MODULE_ALIAS("snd-hda-codec-id:434d4980"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("C-Media HD-audio codec"); static struct hda_codec_preset_list cmedia_list = { .preset = snd_hda_preset_cmedia, .owner = THIS_MODULE, }; static int __init patch_cmedia_init(void) { return snd_hda_add_codec_preset(&cmedia_list); } static void __exit patch_cmedia_exit(void) { snd_hda_delete_codec_preset(&cmedia_list); } module_init(patch_cmedia_init) module_exit(patch_cmedia_exit)
10f2babbbab2865f782ccdd02e89b6ddad54600a
9de0cec678bc4a3bec2b4adabef9f39ff5b4afac
/PWGLF/SPECTRA/Spherocity/macros/AddTaskS0.C
035fbc3ff18e421e6dd349037533b9af007a4881
[]
permissive
alisw/AliPhysics
91bf1bd01ab2af656a25ff10b25e618a63667d3e
5df28b2b415e78e81273b0d9bf5c1b99feda3348
refs/heads/master
2023-08-31T20:41:44.927176
2023-08-31T14:51:12
2023-08-31T14:51:12
61,661,378
129
1,150
BSD-3-Clause
2023-09-14T18:48:45
2016-06-21T19:31:29
C++
UTF-8
C
false
false
1,823
c
AddTaskS0.C
AliAnalysisTaskS0* AddTaskS0( Bool_t AnalysisMC = kFALSE, const Char_t* taskname = "Spherocity" ) { // Get the pointer to the existing analysis manager via the static //access method //========================================================================= AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); if (!mgr) { Error("AddTaskESA", "No analysis manager to connect to."); return NULL; } // Check the analysis type using the event handlers connected to the // analysis manager The availability of MC handler can also be // checked here. // ========================================================================= if (!mgr->GetInputEventHandler()) { Error("AddTaskESA", "This task requires an input event handler"); return NULL; } // Create spherocity percentile binning //======================================================================== const Int_t nSobins = 10; Float_t percSpheroBins[nSobins+1]={ 0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0 }; TH1D * hSpheroDef = new TH1D("hHelper","",nSobins,percSpheroBins); // Create the task and configure it //======================================================================== AliAnalysisTaskS0* taskESA = new AliAnalysisTaskS0("SpherocityTask"); TString type = mgr->GetInputEventHandler()->GetDataType(); // can be "ESD" or "AOD" taskESA->SetAnalysisType(type); taskESA->SetAnalysisMC(AnalysisMC); taskESA->SetDebugLevel(0); // taskESA->SetHisto(hSpheroDef); mgr->AddTask(taskESA); mgr->ConnectInput(taskESA,0,mgr->GetCommonInputContainer()); // same for the output mgr->ConnectOutput(taskESA,1,mgr->CreateContainer(Form("cList%s",taskname), TList::Class(), AliAnalysisManager::kOutputContainer, Form("%s:%s", AliAnalysisManager::GetCommonFileName(),taskname))); return taskESA; }
0abcf35042eb87858b1bf5052e3b6df835c16eb0
6d54a7b26d0eb82152a549a6a9dfde656687752c
/src/platform/mt793x/BLEGattProfile.c
a8f2ebf9c1ace07e5a15986ee1835fe5a3f5dee4
[ "Apache-2.0", "LicenseRef-scancode-warranty-disclaimer" ]
permissive
project-chip/connectedhomeip
81a123d675cf527773f70047d1ed1c43be5ffe6d
ea3970a7f11cd227ac55917edaa835a2a9bc4fc8
refs/heads/master
2023-09-01T11:43:37.546040
2023-09-01T08:01:32
2023-09-01T08:01:32
244,694,174
6,409
1,789
Apache-2.0
2023-09-14T20:56:31
2020-03-03T17:05:10
C++
UTF-8
C
false
false
4,758
c
BLEGattProfile.c
/* * Copyright (c) 2020-2021 Project CHIP Authors * Copyright (c) 2019 Nest Labs, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @file * Provides an implementation of the BLEManager singleton object * for the MediaTek Genio platforms. */ #include "BLEManagerImpl.h" #include "bt_gap_le.h" #include "bt_gatts.h" #include "bt_uuid.h" #define CHIPOBLEPROFILE_SERVICE_UUID_16 (0xFFF6) #define CHIPOBLEPROFILE_CHAR_UUID_RX \ { \ 0x11, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18 \ } #define CHIPOBLEPROFILE_CHAR_UUID_TX \ { \ 0x12, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18 \ } const bt_uuid_t CHIPOBLEPROFILE_CHAR_SERVER_TX_UUID128 = { CHIPOBLEPROFILE_CHAR_UUID_TX }; const bt_uuid_t CHIPOBLEPROFILE_CHAR_SERVER_RX_UUID128 = { CHIPOBLEPROFILE_CHAR_UUID_RX }; CHIPoBLECharCallback CHIPoBLEProfile_read_callback = NULL; CHIPoBLECharCallback CHIPoBLEProfile_write_callback = NULL; CHIPoBLECharCallback CHIPoBLEProfile_ccc_callback = NULL; uint32_t ble_tx_charc_value_callback(const uint8_t rw, uint16_t handle, void * data, uint16_t size, uint16_t offset) { printf("ble_tx_charc_value_callback: %d %d %p %d %d\n", rw, handle, data, size, offset); if (CHIPoBLEProfile_read_callback) { CHIPoBLEProfile_read_callback(handle, data, size); } return size; } uint32_t ble_rx_charc_callback(const uint8_t rw, uint16_t handle, void * data, uint16_t size, uint16_t offset) { printf("ble_rx_charc_callback: %d %d %p %d %d\n", rw, handle, data, size, offset); if (CHIPoBLEProfile_write_callback) { CHIPoBLEProfile_write_callback(handle, data, size); } return size; } uint32_t ble_tx_ccc_callback(const uint8_t rw, uint16_t handle, void * data, uint16_t size, uint16_t offset) { printf("ble_tx_ccc_callback: %d %d %p %d %d\n", rw, handle, data, size, offset); if (CHIPoBLEProfile_ccc_callback) { CHIPoBLEProfile_ccc_callback(handle, data, size); } return size; } BT_GATTS_NEW_PRIMARY_SERVICE_16(chipOBle_primary_service, CHIPOBLEPROFILE_SERVICE_UUID_16); BT_GATTS_NEW_CHARC_128(chipOBle_profile_rx_char, BT_GATT_CHARC_PROP_WRITE, 0x0016, CHIPOBLEPROFILE_CHAR_UUID_RX); BT_GATTS_NEW_CHARC_VALUE_CALLBACK(chipOBle_profile_rx_value, CHIPOBLEPROFILE_CHAR_SERVER_RX_UUID128, BT_GATTS_REC_PERM_READABLE | BT_GATTS_REC_PERM_WRITABLE, ble_rx_charc_callback); BT_GATTS_NEW_CHARC_128(chipOBle_profile_tx_char, BT_GATT_CHARC_PROP_READ | BT_GATT_CHARC_PROP_INDICATE, 0x0018, CHIPOBLEPROFILE_CHAR_UUID_TX); BT_GATTS_NEW_CHARC_VALUE_CALLBACK(chipOBle_profile_tx_value, CHIPOBLEPROFILE_CHAR_SERVER_TX_UUID128, BT_GATTS_REC_PERM_READABLE | BT_GATTS_REC_PERM_WRITABLE, ble_tx_charc_value_callback); BT_GATTS_NEW_CLIENT_CHARC_CONFIG(chipOBle_profile_tx_config, BT_GATTS_REC_PERM_READABLE | BT_GATTS_REC_PERM_WRITABLE, ble_tx_ccc_callback); static const bt_gatts_service_rec_t * chipOBle_service_rec[] = { (const bt_gatts_service_rec_t *) &chipOBle_primary_service, (const bt_gatts_service_rec_t *) &chipOBle_profile_rx_char, (const bt_gatts_service_rec_t *) &chipOBle_profile_rx_value, (const bt_gatts_service_rec_t *) &chipOBle_profile_tx_char, (const bt_gatts_service_rec_t *) &chipOBle_profile_tx_value, (const bt_gatts_service_rec_t *) &chipOBle_profile_tx_config, }; const bt_gatts_service_t chipOBle_gatts_service = { .starting_handle = 0x0014, .ending_handle = 0x0019, .required_encryption_key_size = 0, .records = chipOBle_service_rec };
d2c65fe5c529c3e371898bbcc0e5f8ce2f9c9d62
e65a4dbfbfb0e54e59787ba7741efee12f7687f3
/devel/gdb/files/kgdb/aarch64-fbsd-kern.c
f2d8f6511ff7b92e0fe64a967e5e3b7c3b1ffb46
[ "BSD-2-Clause" ]
permissive
freebsd/freebsd-ports
86f2e89d43913412c4f6b2be3e255bc0945eac12
605a2983f245ac63f5420e023e7dce56898ad801
refs/heads/main
2023-08-30T21:46:28.720924
2023-08-30T19:33:44
2023-08-30T19:33:44
1,803,961
916
918
NOASSERTION
2023-09-08T04:06:26
2011-05-26T11:15:35
null
UTF-8
C
false
false
6,267
c
aarch64-fbsd-kern.c
/*- * Copyright (c) 2017 John Baldwin <jhb@FreeBSD.org> * 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 AUTHORS ``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 AUTHORS 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. */ /* Target-dependent code for FreeBSD/aarch64 kernels. */ #include "defs.h" #include "aarch64-tdep.h" #include "frame-unwind.h" #include "gdbarch.h" #include "gdbcore.h" #include "osabi.h" #include "regcache.h" #include "regset.h" #include "solib.h" #include "target.h" #include "trad-frame.h" #include "kgdb.h" static const struct regcache_map_entry aarch64_fbsd_pcbmap[] = { { 30, AARCH64_X0_REGNUM, 8 }, /* x0 ... x29 */ { 1, AARCH64_PC_REGNUM, 8 }, { 1, REGCACHE_MAP_SKIP, 8 }, { 1, AARCH64_SP_REGNUM, 8 }, { 0 } }; static const struct regset aarch64_fbsd_pcbregset = { aarch64_fbsd_pcbmap, regcache_supply_regset, regcache_collect_regset }; static void aarch64_fbsd_supply_pcb(struct regcache *regcache, CORE_ADDR pcb_addr) { gdb_byte buf[8 * 33]; if (target_read_memory (pcb_addr, buf, sizeof buf) == 0) regcache_supply_regset (&aarch64_fbsd_pcbregset, regcache, -1, buf, sizeof (buf)); } static struct trad_frame_cache * aarch64_fbsd_trapframe_cache (frame_info_ptr this_frame, void **this_cache) { struct gdbarch *gdbarch = get_frame_arch (this_frame); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); struct trad_frame_cache *cache; CORE_ADDR func, pc, sp; const char *name; int i; if (*this_cache != NULL) return ((struct trad_frame_cache *)*this_cache); cache = trad_frame_cache_zalloc (this_frame); *this_cache = cache; func = get_frame_func (this_frame); sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM); find_pc_partial_function (func, &name, NULL, NULL); if (strcmp(name, "fork_trampoline") == 0 && get_frame_pc (this_frame) == func) { /* fork_exit hasn't been called (kthread has never run), so SP hasn't been initialized yet. The stack pointer is stored in the X2 in the pcb. */ sp = get_frame_register_unsigned (this_frame, AARCH64_X0_REGNUM + 2); } trad_frame_set_reg_addr (cache, AARCH64_SP_REGNUM, sp); trad_frame_set_reg_addr (cache, AARCH64_LR_REGNUM, sp + 8); trad_frame_set_reg_addr (cache, AARCH64_PC_REGNUM, sp + 16); trad_frame_set_reg_addr (cache, AARCH64_CPSR_REGNUM, sp + 24); for (i = 0; i < 30; i++) trad_frame_set_reg_addr (cache, AARCH64_X0_REGNUM + i, sp + 32 + i * 8); /* Read $PC from trap frame. */ pc = read_memory_unsigned_integer (sp + 16, 8, byte_order); if (pc == 0 && strcmp(name, "fork_trampoline") == 0) { /* Initial frame of a kthread; terminate backtrace. */ trad_frame_set_id (cache, outer_frame_id); } else { /* Construct the frame ID using the function start. */ trad_frame_set_id (cache, frame_id_build (sp + 8 * 34, func)); } return cache; } static void aarch64_fbsd_trapframe_this_id (frame_info_ptr this_frame, void **this_cache, struct frame_id *this_id) { struct trad_frame_cache *cache = aarch64_fbsd_trapframe_cache (this_frame, this_cache); trad_frame_get_id (cache, this_id); } static struct value * aarch64_fbsd_trapframe_prev_register (frame_info_ptr this_frame, void **this_cache, int regnum) { struct trad_frame_cache *cache = aarch64_fbsd_trapframe_cache (this_frame, this_cache); return trad_frame_get_register (cache, this_frame, regnum); } static int aarch64_fbsd_trapframe_sniffer (const struct frame_unwind *self, frame_info_ptr this_frame, void **this_prologue_cache) { const char *name; find_pc_partial_function (get_frame_func (this_frame), &name, NULL, NULL); return (name && ((strcmp (name, "handle_el1h_sync") == 0) || (strcmp (name, "handle_el1h_irq") == 0) || (strcmp (name, "handle_el0_sync") == 0) || (strcmp (name, "handle_el0_irq") == 0) || (strcmp (name, "handle_el0_error") == 0) || (strcmp (name, "fork_trampoline") == 0))); } static const struct frame_unwind aarch64_fbsd_trapframe_unwind = { "aarch64 FreeBSD kernel trap", SIGTRAMP_FRAME, default_frame_unwind_stop_reason, aarch64_fbsd_trapframe_this_id, aarch64_fbsd_trapframe_prev_register, NULL, aarch64_fbsd_trapframe_sniffer }; /* Implement the 'init_osabi' method of struct gdb_osabi_handler. */ static void aarch64_fbsd_kernel_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) { aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch); frame_unwind_prepend_unwinder (gdbarch, &aarch64_fbsd_trapframe_unwind); set_gdbarch_so_ops (gdbarch, &kld_so_ops); /* Enable longjmp. */ tdep->jb_pc = 13; fbsd_vmcore_set_supply_pcb (gdbarch, aarch64_fbsd_supply_pcb); fbsd_vmcore_set_cpu_pcb_addr (gdbarch, kgdb_trgt_stop_pcb); } void _initialize_aarch64_kgdb_tdep (); void _initialize_aarch64_kgdb_tdep () { gdbarch_register_osabi_sniffer(bfd_arch_aarch64, bfd_target_elf_flavour, fbsd_kernel_osabi_sniffer); gdbarch_register_osabi (bfd_arch_aarch64, 0, GDB_OSABI_FREEBSD_KERNEL, aarch64_fbsd_kernel_init_abi); }
681f9a6fb548949c7125609d44e70d0e2d3441f1
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/fs/gfs2/dir.c
b631c904346084b5fb7b7d96985e724e7b4173a3
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
48,650
c
dir.c
/* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions * of the GNU General Public License version 2. */ /* * Implements Extendible Hashing as described in: * "Extendible Hashing" by Fagin, et al in * __ACM Trans. on Database Systems__, Sept 1979. * * * Here's the layout of dirents which is essentially the same as that of ext2 * within a single block. The field de_name_len is the number of bytes * actually required for the name (no null terminator). The field de_rec_len * is the number of bytes allocated to the dirent. The offset of the next * dirent in the block is (dirent + dirent->de_rec_len). When a dirent is * deleted, the preceding dirent inherits its allocated space, ie * prev->de_rec_len += deleted->de_rec_len. Since the next dirent is obtained * by adding de_rec_len to the current dirent, this essentially causes the * deleted dirent to get jumped over when iterating through all the dirents. * * When deleting the first dirent in a block, there is no previous dirent so * the field de_ino is set to zero to designate it as deleted. When allocating * a dirent, gfs2_dirent_alloc iterates through the dirents in a block. If the * first dirent has (de_ino == 0) and de_rec_len is large enough, this first * dirent is allocated. Otherwise it must go through all the 'used' dirents * searching for one in which the amount of total space minus the amount of * used space will provide enough space for the new dirent. * * There are two types of blocks in which dirents reside. In a stuffed dinode, * the dirents begin at offset sizeof(struct gfs2_dinode) from the beginning of * the block. In leaves, they begin at offset sizeof(struct gfs2_leaf) from the * beginning of the leaf block. The dirents reside in leaves when * * dip->i_diskflags & GFS2_DIF_EXHASH is true * * Otherwise, the dirents are "linear", within a single stuffed dinode block. * * When the dirents are in leaves, the actual contents of the directory file are * used as an array of 64-bit block pointers pointing to the leaf blocks. The * dirents are NOT in the directory file itself. There can be more than one * block pointer in the array that points to the same leaf. In fact, when a * directory is first converted from linear to exhash, all of the pointers * point to the same leaf. * * When a leaf is completely full, the size of the hash table can be * doubled unless it is already at the maximum size which is hard coded into * GFS2_DIR_MAX_DEPTH. After that, leaves are chained together in a linked list, * but never before the maximum hash table size has been reached. */ #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/buffer_head.h> #include <linux/sort.h> #include <linux/gfs2_ondisk.h> #include <linux/crc32.h> #include <linux/vmalloc.h> #include "gfs2.h" #include "incore.h" #include "dir.h" #include "glock.h" #include "inode.h" #include "meta_io.h" #include "quota.h" #include "rgrp.h" #include "trans.h" #include "bmap.h" #include "util.h" #define IS_LEAF 1 /* Hashed (leaf) directory */ #define IS_DINODE 2 /* Linear (stuffed dinode block) directory */ #define MAX_RA_BLOCKS 32 /* max read-ahead blocks */ #define gfs2_disk_hash2offset(h) (((u64)(h)) >> 1) #define gfs2_dir_offset2hash(p) ((u32)(((u64)(p)) << 1)) struct qstr gfs2_qdot __read_mostly; struct qstr gfs2_qdotdot __read_mostly; typedef int (*gfs2_dscan_t)(const struct gfs2_dirent *dent, const struct qstr *name, void *opaque); int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, u64 block, struct buffer_head **bhp) { struct buffer_head *bh; bh = gfs2_meta_new(ip->i_gl, block); gfs2_trans_add_meta(ip->i_gl, bh); gfs2_metatype_set(bh, GFS2_METATYPE_JD, GFS2_FORMAT_JD); gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); *bhp = bh; return 0; } static int gfs2_dir_get_existing_buffer(struct gfs2_inode *ip, u64 block, struct buffer_head **bhp) { struct buffer_head *bh; int error; error = gfs2_meta_read(ip->i_gl, block, DIO_WAIT, &bh); if (error) return error; if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), bh, GFS2_METATYPE_JD)) { brelse(bh); return -EIO; } *bhp = bh; return 0; } static int gfs2_dir_write_stuffed(struct gfs2_inode *ip, const char *buf, unsigned int offset, unsigned int size) { struct buffer_head *dibh; int error; error = gfs2_meta_inode_buffer(ip, &dibh); if (error) return error; gfs2_trans_add_meta(ip->i_gl, dibh); memcpy(dibh->b_data + offset + sizeof(struct gfs2_dinode), buf, size); if (ip->i_inode.i_size < offset + size) i_size_write(&ip->i_inode, offset + size); ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME; gfs2_dinode_out(ip, dibh->b_data); brelse(dibh); return size; } /** * gfs2_dir_write_data - Write directory information to the inode * @ip: The GFS2 inode * @buf: The buffer containing information to be written * @offset: The file offset to start writing at * @size: The amount of data to write * * Returns: The number of bytes correctly written or error code */ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, u64 offset, unsigned int size) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct buffer_head *dibh; u64 lblock, dblock; u32 extlen = 0; unsigned int o; int copied = 0; int error = 0; int new = 0; if (!size) return 0; if (gfs2_is_stuffed(ip) && offset + size <= sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) return gfs2_dir_write_stuffed(ip, buf, (unsigned int)offset, size); if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip))) return -EINVAL; if (gfs2_is_stuffed(ip)) { error = gfs2_unstuff_dinode(ip, NULL); if (error) return error; } lblock = offset; o = do_div(lblock, sdp->sd_jbsize) + sizeof(struct gfs2_meta_header); while (copied < size) { unsigned int amount; struct buffer_head *bh; amount = size - copied; if (amount > sdp->sd_sb.sb_bsize - o) amount = sdp->sd_sb.sb_bsize - o; if (!extlen) { new = 1; error = gfs2_extent_map(&ip->i_inode, lblock, &new, &dblock, &extlen); if (error) goto fail; error = -EIO; if (gfs2_assert_withdraw(sdp, dblock)) goto fail; } if (amount == sdp->sd_jbsize || new) error = gfs2_dir_get_new_buffer(ip, dblock, &bh); else error = gfs2_dir_get_existing_buffer(ip, dblock, &bh); if (error) goto fail; gfs2_trans_add_meta(ip->i_gl, bh); memcpy(bh->b_data + o, buf, amount); brelse(bh); buf += amount; copied += amount; lblock++; dblock++; extlen--; o = sizeof(struct gfs2_meta_header); } out: error = gfs2_meta_inode_buffer(ip, &dibh); if (error) return error; if (ip->i_inode.i_size < offset + copied) i_size_write(&ip->i_inode, offset + copied); ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME; gfs2_trans_add_meta(ip->i_gl, dibh); gfs2_dinode_out(ip, dibh->b_data); brelse(dibh); return copied; fail: if (copied) goto out; return error; } static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, __be64 *buf, unsigned int size) { struct buffer_head *dibh; int error; error = gfs2_meta_inode_buffer(ip, &dibh); if (!error) { memcpy(buf, dibh->b_data + sizeof(struct gfs2_dinode), size); brelse(dibh); } return (error) ? error : size; } /** * gfs2_dir_read_data - Read a data from a directory inode * @ip: The GFS2 Inode * @buf: The buffer to place result into * @size: Amount of data to transfer * * Returns: The amount of data actually copied or the error */ static int gfs2_dir_read_data(struct gfs2_inode *ip, __be64 *buf, unsigned int size) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); u64 lblock, dblock; u32 extlen = 0; unsigned int o; int copied = 0; int error = 0; if (gfs2_is_stuffed(ip)) return gfs2_dir_read_stuffed(ip, buf, size); if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip))) return -EINVAL; lblock = 0; o = do_div(lblock, sdp->sd_jbsize) + sizeof(struct gfs2_meta_header); while (copied < size) { unsigned int amount; struct buffer_head *bh; int new; amount = size - copied; if (amount > sdp->sd_sb.sb_bsize - o) amount = sdp->sd_sb.sb_bsize - o; if (!extlen) { new = 0; error = gfs2_extent_map(&ip->i_inode, lblock, &new, &dblock, &extlen); if (error || !dblock) goto fail; BUG_ON(extlen < 1); bh = gfs2_meta_ra(ip->i_gl, dblock, extlen); } else { error = gfs2_meta_read(ip->i_gl, dblock, DIO_WAIT, &bh); if (error) goto fail; } error = gfs2_metatype_check(sdp, bh, GFS2_METATYPE_JD); if (error) { brelse(bh); goto fail; } dblock++; extlen--; memcpy(buf, bh->b_data + o, amount); brelse(bh); buf += (amount/sizeof(__be64)); copied += amount; lblock++; o = sizeof(struct gfs2_meta_header); } return copied; fail: return (copied) ? copied : error; } /** * gfs2_dir_get_hash_table - Get pointer to the dir hash table * @ip: The inode in question * * Returns: The hash table or an error */ static __be64 *gfs2_dir_get_hash_table(struct gfs2_inode *ip) { struct inode *inode = &ip->i_inode; int ret; u32 hsize; __be64 *hc; BUG_ON(!(ip->i_diskflags & GFS2_DIF_EXHASH)); hc = ip->i_hash_cache; if (hc) return hc; hsize = 1 << ip->i_depth; hsize *= sizeof(__be64); if (hsize != i_size_read(&ip->i_inode)) { gfs2_consist_inode(ip); return ERR_PTR(-EIO); } hc = kmalloc(hsize, GFP_NOFS | __GFP_NOWARN); if (hc == NULL) hc = __vmalloc(hsize, GFP_NOFS, PAGE_KERNEL); if (hc == NULL) return ERR_PTR(-ENOMEM); ret = gfs2_dir_read_data(ip, hc, hsize); if (ret < 0) { if (is_vmalloc_addr(hc)) vfree(hc); else kfree(hc); return ERR_PTR(ret); } spin_lock(&inode->i_lock); if (ip->i_hash_cache) { if (is_vmalloc_addr(hc)) vfree(hc); else kfree(hc); } else { ip->i_hash_cache = hc; } spin_unlock(&inode->i_lock); return ip->i_hash_cache; } /** * gfs2_dir_hash_inval - Invalidate dir hash * @ip: The directory inode * * Must be called with an exclusive glock, or during glock invalidation. */ void gfs2_dir_hash_inval(struct gfs2_inode *ip) { __be64 *hc = ip->i_hash_cache; ip->i_hash_cache = NULL; if (is_vmalloc_addr(hc)) vfree(hc); else kfree(hc); } static inline int gfs2_dirent_sentinel(const struct gfs2_dirent *dent) { return dent->de_inum.no_addr == 0 || dent->de_inum.no_formal_ino == 0; } static inline int __gfs2_dirent_find(const struct gfs2_dirent *dent, const struct qstr *name, int ret) { if (!gfs2_dirent_sentinel(dent) && be32_to_cpu(dent->de_hash) == name->hash && be16_to_cpu(dent->de_name_len) == name->len && memcmp(dent+1, name->name, name->len) == 0) return ret; return 0; } static int gfs2_dirent_find(const struct gfs2_dirent *dent, const struct qstr *name, void *opaque) { return __gfs2_dirent_find(dent, name, 1); } static int gfs2_dirent_prev(const struct gfs2_dirent *dent, const struct qstr *name, void *opaque) { return __gfs2_dirent_find(dent, name, 2); } /* * name->name holds ptr to start of block. * name->len holds size of block. */ static int gfs2_dirent_last(const struct gfs2_dirent *dent, const struct qstr *name, void *opaque) { const char *start = name->name; const char *end = (const char *)dent + be16_to_cpu(dent->de_rec_len); if (name->len == (end - start)) return 1; return 0; } static int gfs2_dirent_find_space(const struct gfs2_dirent *dent, const struct qstr *name, void *opaque) { unsigned required = GFS2_DIRENT_SIZE(name->len); unsigned actual = GFS2_DIRENT_SIZE(be16_to_cpu(dent->de_name_len)); unsigned totlen = be16_to_cpu(dent->de_rec_len); if (gfs2_dirent_sentinel(dent)) actual = 0; if (totlen - actual >= required) return 1; return 0; } struct dirent_gather { const struct gfs2_dirent **pdent; unsigned offset; }; static int gfs2_dirent_gather(const struct gfs2_dirent *dent, const struct qstr *name, void *opaque) { struct dirent_gather *g = opaque; if (!gfs2_dirent_sentinel(dent)) { g->pdent[g->offset++] = dent; } return 0; } /* * Other possible things to check: * - Inode located within filesystem size (and on valid block) * - Valid directory entry type * Not sure how heavy-weight we want to make this... could also check * hash is correct for example, but that would take a lot of extra time. * For now the most important thing is to check that the various sizes * are correct. */ static int gfs2_check_dirent(struct gfs2_dirent *dent, unsigned int offset, unsigned int size, unsigned int len, int first) { const char *msg = "gfs2_dirent too small"; if (unlikely(size < sizeof(struct gfs2_dirent))) goto error; msg = "gfs2_dirent misaligned"; if (unlikely(offset & 0x7)) goto error; msg = "gfs2_dirent points beyond end of block"; if (unlikely(offset + size > len)) goto error; msg = "zero inode number"; if (unlikely(!first && gfs2_dirent_sentinel(dent))) goto error; msg = "name length is greater than space in dirent"; if (!gfs2_dirent_sentinel(dent) && unlikely(sizeof(struct gfs2_dirent)+be16_to_cpu(dent->de_name_len) > size)) goto error; return 0; error: printk(KERN_WARNING "gfs2_check_dirent: %s (%s)\n", msg, first ? "first in block" : "not first in block"); return -EIO; } static int gfs2_dirent_offset(const void *buf) { const struct gfs2_meta_header *h = buf; int offset; BUG_ON(buf == NULL); switch(be32_to_cpu(h->mh_type)) { case GFS2_METATYPE_LF: offset = sizeof(struct gfs2_leaf); break; case GFS2_METATYPE_DI: offset = sizeof(struct gfs2_dinode); break; default: goto wrong_type; } return offset; wrong_type: printk(KERN_WARNING "gfs2_scan_dirent: wrong block type %u\n", be32_to_cpu(h->mh_type)); return -1; } static struct gfs2_dirent *gfs2_dirent_scan(struct inode *inode, void *buf, unsigned int len, gfs2_dscan_t scan, const struct qstr *name, void *opaque) { struct gfs2_dirent *dent, *prev; unsigned offset; unsigned size; int ret = 0; ret = gfs2_dirent_offset(buf); if (ret < 0) goto consist_inode; offset = ret; prev = NULL; dent = buf + offset; size = be16_to_cpu(dent->de_rec_len); if (gfs2_check_dirent(dent, offset, size, len, 1)) goto consist_inode; do { ret = scan(dent, name, opaque); if (ret) break; offset += size; if (offset == len) break; prev = dent; dent = buf + offset; size = be16_to_cpu(dent->de_rec_len); if (gfs2_check_dirent(dent, offset, size, len, 0)) goto consist_inode; } while(1); switch(ret) { case 0: return NULL; case 1: return dent; case 2: return prev ? prev : dent; default: BUG_ON(ret > 0); return ERR_PTR(ret); } consist_inode: gfs2_consist_inode(GFS2_I(inode)); return ERR_PTR(-EIO); } static int dirent_check_reclen(struct gfs2_inode *dip, const struct gfs2_dirent *d, const void *end_p) { const void *ptr = d; u16 rec_len = be16_to_cpu(d->de_rec_len); if (unlikely(rec_len < sizeof(struct gfs2_dirent))) goto broken; ptr += rec_len; if (ptr < end_p) return rec_len; if (ptr == end_p) return -ENOENT; broken: gfs2_consist_inode(dip); return -EIO; } /** * dirent_next - Next dirent * @dip: the directory * @bh: The buffer * @dent: Pointer to list of dirents * * Returns: 0 on success, error code otherwise */ static int dirent_next(struct gfs2_inode *dip, struct buffer_head *bh, struct gfs2_dirent **dent) { struct gfs2_dirent *cur = *dent, *tmp; char *bh_end = bh->b_data + bh->b_size; int ret; ret = dirent_check_reclen(dip, cur, bh_end); if (ret < 0) return ret; tmp = (void *)cur + ret; ret = dirent_check_reclen(dip, tmp, bh_end); if (ret == -EIO) return ret; /* Only the first dent could ever have de_inum.no_addr == 0 */ if (gfs2_dirent_sentinel(tmp)) { gfs2_consist_inode(dip); return -EIO; } *dent = tmp; return 0; } /** * dirent_del - Delete a dirent * @dip: The GFS2 inode * @bh: The buffer * @prev: The previous dirent * @cur: The current dirent * */ static void dirent_del(struct gfs2_inode *dip, struct buffer_head *bh, struct gfs2_dirent *prev, struct gfs2_dirent *cur) { u16 cur_rec_len, prev_rec_len; if (gfs2_dirent_sentinel(cur)) { gfs2_consist_inode(dip); return; } gfs2_trans_add_meta(dip->i_gl, bh); /* If there is no prev entry, this is the first entry in the block. The de_rec_len is already as big as it needs to be. Just zero out the inode number and return. */ if (!prev) { cur->de_inum.no_addr = 0; cur->de_inum.no_formal_ino = 0; return; } /* Combine this dentry with the previous one. */ prev_rec_len = be16_to_cpu(prev->de_rec_len); cur_rec_len = be16_to_cpu(cur->de_rec_len); if ((char *)prev + prev_rec_len != (char *)cur) gfs2_consist_inode(dip); if ((char *)cur + cur_rec_len > bh->b_data + bh->b_size) gfs2_consist_inode(dip); prev_rec_len += cur_rec_len; prev->de_rec_len = cpu_to_be16(prev_rec_len); } /* * Takes a dent from which to grab space as an argument. Returns the * newly created dent. */ static struct gfs2_dirent *gfs2_init_dirent(struct inode *inode, struct gfs2_dirent *dent, const struct qstr *name, struct buffer_head *bh) { struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_dirent *ndent; unsigned offset = 0, totlen; if (!gfs2_dirent_sentinel(dent)) offset = GFS2_DIRENT_SIZE(be16_to_cpu(dent->de_name_len)); totlen = be16_to_cpu(dent->de_rec_len); BUG_ON(offset + name->len > totlen); gfs2_trans_add_meta(ip->i_gl, bh); ndent = (struct gfs2_dirent *)((char *)dent + offset); dent->de_rec_len = cpu_to_be16(offset); gfs2_qstr2dirent(name, totlen - offset, ndent); return ndent; } static struct gfs2_dirent *gfs2_dirent_alloc(struct inode *inode, struct buffer_head *bh, const struct qstr *name) { struct gfs2_dirent *dent; dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, gfs2_dirent_find_space, name, NULL); if (!dent || IS_ERR(dent)) return dent; return gfs2_init_dirent(inode, dent, name, bh); } static int get_leaf(struct gfs2_inode *dip, u64 leaf_no, struct buffer_head **bhp) { int error; error = gfs2_meta_read(dip->i_gl, leaf_no, DIO_WAIT, bhp); if (!error && gfs2_metatype_check(GFS2_SB(&dip->i_inode), *bhp, GFS2_METATYPE_LF)) { /* printk(KERN_INFO "block num=%llu\n", leaf_no); */ error = -EIO; } return error; } /** * get_leaf_nr - Get a leaf number associated with the index * @dip: The GFS2 inode * @index: * @leaf_out: * * Returns: 0 on success, error code otherwise */ static int get_leaf_nr(struct gfs2_inode *dip, u32 index, u64 *leaf_out) { __be64 *hash; hash = gfs2_dir_get_hash_table(dip); if (IS_ERR(hash)) return PTR_ERR(hash); *leaf_out = be64_to_cpu(*(hash + index)); return 0; } static int get_first_leaf(struct gfs2_inode *dip, u32 index, struct buffer_head **bh_out) { u64 leaf_no; int error; error = get_leaf_nr(dip, index, &leaf_no); if (!error) error = get_leaf(dip, leaf_no, bh_out); return error; } static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, const struct qstr *name, gfs2_dscan_t scan, struct buffer_head **pbh) { struct buffer_head *bh; struct gfs2_dirent *dent; struct gfs2_inode *ip = GFS2_I(inode); int error; if (ip->i_diskflags & GFS2_DIF_EXHASH) { struct gfs2_leaf *leaf; unsigned hsize = 1 << ip->i_depth; unsigned index; u64 ln; if (hsize * sizeof(u64) != i_size_read(inode)) { gfs2_consist_inode(ip); return ERR_PTR(-EIO); } index = name->hash >> (32 - ip->i_depth); error = get_first_leaf(ip, index, &bh); if (error) return ERR_PTR(error); do { dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, scan, name, NULL); if (dent) goto got_dent; leaf = (struct gfs2_leaf *)bh->b_data; ln = be64_to_cpu(leaf->lf_next); brelse(bh); if (!ln) break; error = get_leaf(ip, ln, &bh); } while(!error); return error ? ERR_PTR(error) : NULL; } error = gfs2_meta_inode_buffer(ip, &bh); if (error) return ERR_PTR(error); dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, scan, name, NULL); got_dent: if (unlikely(dent == NULL || IS_ERR(dent))) { brelse(bh); bh = NULL; } *pbh = bh; return dent; } static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh, u16 depth) { struct gfs2_inode *ip = GFS2_I(inode); unsigned int n = 1; u64 bn; int error; struct buffer_head *bh; struct gfs2_leaf *leaf; struct gfs2_dirent *dent; struct qstr name = { .name = "" }; error = gfs2_alloc_blocks(ip, &bn, &n, 0, NULL); if (error) return NULL; bh = gfs2_meta_new(ip->i_gl, bn); if (!bh) return NULL; gfs2_trans_add_unrevoke(GFS2_SB(inode), bn, 1); gfs2_trans_add_meta(ip->i_gl, bh); gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); leaf = (struct gfs2_leaf *)bh->b_data; leaf->lf_depth = cpu_to_be16(depth); leaf->lf_entries = 0; leaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE); leaf->lf_next = 0; memset(leaf->lf_reserved, 0, sizeof(leaf->lf_reserved)); dent = (struct gfs2_dirent *)(leaf+1); gfs2_qstr2dirent(&name, bh->b_size - sizeof(struct gfs2_leaf), dent); *pbh = bh; return leaf; } /** * dir_make_exhash - Convert a stuffed directory into an ExHash directory * @dip: The GFS2 inode * * Returns: 0 on success, error code otherwise */ static int dir_make_exhash(struct inode *inode) { struct gfs2_inode *dip = GFS2_I(inode); struct gfs2_sbd *sdp = GFS2_SB(inode); struct gfs2_dirent *dent; struct qstr args; struct buffer_head *bh, *dibh; struct gfs2_leaf *leaf; int y; u32 x; __be64 *lp; u64 bn; int error; error = gfs2_meta_inode_buffer(dip, &dibh); if (error) return error; /* Turn over a new leaf */ leaf = new_leaf(inode, &bh, 0); if (!leaf) return -ENOSPC; bn = bh->b_blocknr; gfs2_assert(sdp, dip->i_entries < (1 << 16)); leaf->lf_entries = cpu_to_be16(dip->i_entries); /* Copy dirents */ gfs2_buffer_copy_tail(bh, sizeof(struct gfs2_leaf), dibh, sizeof(struct gfs2_dinode)); /* Find last entry */ x = 0; args.len = bh->b_size - sizeof(struct gfs2_dinode) + sizeof(struct gfs2_leaf); args.name = bh->b_data; dent = gfs2_dirent_scan(&dip->i_inode, bh->b_data, bh->b_size, gfs2_dirent_last, &args, NULL); if (!dent) { brelse(bh); brelse(dibh); return -EIO; } if (IS_ERR(dent)) { brelse(bh); brelse(dibh); return PTR_ERR(dent); } /* Adjust the last dirent's record length (Remember that dent still points to the last entry.) */ dent->de_rec_len = cpu_to_be16(be16_to_cpu(dent->de_rec_len) + sizeof(struct gfs2_dinode) - sizeof(struct gfs2_leaf)); brelse(bh); /* We're done with the new leaf block, now setup the new hash table. */ gfs2_trans_add_meta(dip->i_gl, dibh); gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); lp = (__be64 *)(dibh->b_data + sizeof(struct gfs2_dinode)); for (x = sdp->sd_hash_ptrs; x--; lp++) *lp = cpu_to_be64(bn); i_size_write(inode, sdp->sd_sb.sb_bsize / 2); gfs2_add_inode_blocks(&dip->i_inode, 1); dip->i_diskflags |= GFS2_DIF_EXHASH; for (x = sdp->sd_hash_ptrs, y = -1; x; x >>= 1, y++) ; dip->i_depth = y; gfs2_dinode_out(dip, dibh->b_data); brelse(dibh); return 0; } /** * dir_split_leaf - Split a leaf block into two * @dip: The GFS2 inode * @index: * @leaf_no: * * Returns: 0 on success, error code on failure */ static int dir_split_leaf(struct inode *inode, const struct qstr *name) { struct gfs2_inode *dip = GFS2_I(inode); struct buffer_head *nbh, *obh, *dibh; struct gfs2_leaf *nleaf, *oleaf; struct gfs2_dirent *dent = NULL, *prev = NULL, *next = NULL, *new; u32 start, len, half_len, divider; u64 bn, leaf_no; __be64 *lp; u32 index; int x, moved = 0; int error; index = name->hash >> (32 - dip->i_depth); error = get_leaf_nr(dip, index, &leaf_no); if (error) return error; /* Get the old leaf block */ error = get_leaf(dip, leaf_no, &obh); if (error) return error; oleaf = (struct gfs2_leaf *)obh->b_data; if (dip->i_depth == be16_to_cpu(oleaf->lf_depth)) { brelse(obh); return 1; /* can't split */ } gfs2_trans_add_meta(dip->i_gl, obh); nleaf = new_leaf(inode, &nbh, be16_to_cpu(oleaf->lf_depth) + 1); if (!nleaf) { brelse(obh); return -ENOSPC; } bn = nbh->b_blocknr; /* Compute the start and len of leaf pointers in the hash table. */ len = 1 << (dip->i_depth - be16_to_cpu(oleaf->lf_depth)); half_len = len >> 1; if (!half_len) { printk(KERN_WARNING "i_depth %u lf_depth %u index %u\n", dip->i_depth, be16_to_cpu(oleaf->lf_depth), index); gfs2_consist_inode(dip); error = -EIO; goto fail_brelse; } start = (index & ~(len - 1)); /* Change the pointers. Don't bother distinguishing stuffed from non-stuffed. This code is complicated enough already. */ lp = kmalloc(half_len * sizeof(__be64), GFP_NOFS); if (!lp) { error = -ENOMEM; goto fail_brelse; } /* Change the pointers */ for (x = 0; x < half_len; x++) lp[x] = cpu_to_be64(bn); gfs2_dir_hash_inval(dip); error = gfs2_dir_write_data(dip, (char *)lp, start * sizeof(u64), half_len * sizeof(u64)); if (error != half_len * sizeof(u64)) { if (error >= 0) error = -EIO; goto fail_lpfree; } kfree(lp); /* Compute the divider */ divider = (start + half_len) << (32 - dip->i_depth); /* Copy the entries */ dent = (struct gfs2_dirent *)(obh->b_data + sizeof(struct gfs2_leaf)); do { next = dent; if (dirent_next(dip, obh, &next)) next = NULL; if (!gfs2_dirent_sentinel(dent) && be32_to_cpu(dent->de_hash) < divider) { struct qstr str; str.name = (char*)(dent+1); str.len = be16_to_cpu(dent->de_name_len); str.hash = be32_to_cpu(dent->de_hash); new = gfs2_dirent_alloc(inode, nbh, &str); if (IS_ERR(new)) { error = PTR_ERR(new); break; } new->de_inum = dent->de_inum; /* No endian worries */ new->de_type = dent->de_type; /* No endian worries */ be16_add_cpu(&nleaf->lf_entries, 1); dirent_del(dip, obh, prev, dent); if (!oleaf->lf_entries) gfs2_consist_inode(dip); be16_add_cpu(&oleaf->lf_entries, -1); if (!prev) prev = dent; moved = 1; } else { prev = dent; } dent = next; } while (dent); oleaf->lf_depth = nleaf->lf_depth; error = gfs2_meta_inode_buffer(dip, &dibh); if (!gfs2_assert_withdraw(GFS2_SB(&dip->i_inode), !error)) { gfs2_trans_add_meta(dip->i_gl, dibh); gfs2_add_inode_blocks(&dip->i_inode, 1); gfs2_dinode_out(dip, dibh->b_data); brelse(dibh); } brelse(obh); brelse(nbh); return error; fail_lpfree: kfree(lp); fail_brelse: brelse(obh); brelse(nbh); return error; } /** * dir_double_exhash - Double size of ExHash table * @dip: The GFS2 dinode * * Returns: 0 on success, error code on failure */ static int dir_double_exhash(struct gfs2_inode *dip) { struct buffer_head *dibh; u32 hsize; u32 hsize_bytes; __be64 *hc; __be64 *hc2, *h; int x; int error = 0; hsize = 1 << dip->i_depth; hsize_bytes = hsize * sizeof(__be64); hc = gfs2_dir_get_hash_table(dip); if (IS_ERR(hc)) return PTR_ERR(hc); h = hc2 = kmalloc(hsize_bytes * 2, GFP_NOFS | __GFP_NOWARN); if (hc2 == NULL) hc2 = __vmalloc(hsize_bytes * 2, GFP_NOFS, PAGE_KERNEL); if (!hc2) return -ENOMEM; error = gfs2_meta_inode_buffer(dip, &dibh); if (error) goto out_kfree; for (x = 0; x < hsize; x++) { *h++ = *hc; *h++ = *hc; hc++; } error = gfs2_dir_write_data(dip, (char *)hc2, 0, hsize_bytes * 2); if (error != (hsize_bytes * 2)) goto fail; gfs2_dir_hash_inval(dip); dip->i_hash_cache = hc2; dip->i_depth++; gfs2_dinode_out(dip, dibh->b_data); brelse(dibh); return 0; fail: /* Replace original hash table & size */ gfs2_dir_write_data(dip, (char *)hc, 0, hsize_bytes); i_size_write(&dip->i_inode, hsize_bytes); gfs2_dinode_out(dip, dibh->b_data); brelse(dibh); out_kfree: if (is_vmalloc_addr(hc2)) vfree(hc2); else kfree(hc2); return error; } /** * compare_dents - compare directory entries by hash value * @a: first dent * @b: second dent * * When comparing the hash entries of @a to @b: * gt: returns 1 * lt: returns -1 * eq: returns 0 */ static int compare_dents(const void *a, const void *b) { const struct gfs2_dirent *dent_a, *dent_b; u32 hash_a, hash_b; int ret = 0; dent_a = *(const struct gfs2_dirent **)a; hash_a = be32_to_cpu(dent_a->de_hash); dent_b = *(const struct gfs2_dirent **)b; hash_b = be32_to_cpu(dent_b->de_hash); if (hash_a > hash_b) ret = 1; else if (hash_a < hash_b) ret = -1; else { unsigned int len_a = be16_to_cpu(dent_a->de_name_len); unsigned int len_b = be16_to_cpu(dent_b->de_name_len); if (len_a > len_b) ret = 1; else if (len_a < len_b) ret = -1; else ret = memcmp(dent_a + 1, dent_b + 1, len_a); } return ret; } /** * do_filldir_main - read out directory entries * @dip: The GFS2 inode * @offset: The offset in the file to read from * @opaque: opaque data to pass to filldir * @filldir: The function to pass entries to * @darr: an array of struct gfs2_dirent pointers to read * @entries: the number of entries in darr * @copied: pointer to int that's non-zero if a entry has been copied out * * Jump through some hoops to make sure that if there are hash collsions, * they are read out at the beginning of a buffer. We want to minimize * the possibility that they will fall into different readdir buffers or * that someone will want to seek to that location. * * Returns: errno, >0 on exception from filldir */ static int do_filldir_main(struct gfs2_inode *dip, u64 *offset, void *opaque, filldir_t filldir, const struct gfs2_dirent **darr, u32 entries, int *copied) { const struct gfs2_dirent *dent, *dent_next; u64 off, off_next; unsigned int x, y; int run = 0; int error = 0; sort(darr, entries, sizeof(struct gfs2_dirent *), compare_dents, NULL); dent_next = darr[0]; off_next = be32_to_cpu(dent_next->de_hash); off_next = gfs2_disk_hash2offset(off_next); for (x = 0, y = 1; x < entries; x++, y++) { dent = dent_next; off = off_next; if (y < entries) { dent_next = darr[y]; off_next = be32_to_cpu(dent_next->de_hash); off_next = gfs2_disk_hash2offset(off_next); if (off < *offset) continue; *offset = off; if (off_next == off) { if (*copied && !run) return 1; run = 1; } else run = 0; } else { if (off < *offset) continue; *offset = off; } error = filldir(opaque, (const char *)(dent + 1), be16_to_cpu(dent->de_name_len), off, be64_to_cpu(dent->de_inum.no_addr), be16_to_cpu(dent->de_type)); if (error) return 1; *copied = 1; } /* Increment the *offset by one, so the next time we come into the do_filldir fxn, we get the next entry instead of the last one in the current leaf */ (*offset)++; return 0; } static void *gfs2_alloc_sort_buffer(unsigned size) { void *ptr = NULL; if (size < KMALLOC_MAX_SIZE) ptr = kmalloc(size, GFP_NOFS | __GFP_NOWARN); if (!ptr) ptr = __vmalloc(size, GFP_NOFS, PAGE_KERNEL); return ptr; } static void gfs2_free_sort_buffer(void *ptr) { if (is_vmalloc_addr(ptr)) vfree(ptr); else kfree(ptr); } static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque, filldir_t filldir, int *copied, unsigned *depth, u64 leaf_no) { struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_sbd *sdp = GFS2_SB(inode); struct buffer_head *bh; struct gfs2_leaf *lf; unsigned entries = 0, entries2 = 0; unsigned leaves = 0; const struct gfs2_dirent **darr, *dent; struct dirent_gather g; struct buffer_head **larr; int leaf = 0; int error, i; u64 lfn = leaf_no; do { error = get_leaf(ip, lfn, &bh); if (error) goto out; lf = (struct gfs2_leaf *)bh->b_data; if (leaves == 0) *depth = be16_to_cpu(lf->lf_depth); entries += be16_to_cpu(lf->lf_entries); leaves++; lfn = be64_to_cpu(lf->lf_next); brelse(bh); } while(lfn); if (!entries) return 0; error = -ENOMEM; /* * The extra 99 entries are not normally used, but are a buffer * zone in case the number of entries in the leaf is corrupt. * 99 is the maximum number of entries that can fit in a single * leaf block. */ larr = gfs2_alloc_sort_buffer((leaves + entries + 99) * sizeof(void *)); if (!larr) goto out; darr = (const struct gfs2_dirent **)(larr + leaves); g.pdent = darr; g.offset = 0; lfn = leaf_no; do { error = get_leaf(ip, lfn, &bh); if (error) goto out_free; lf = (struct gfs2_leaf *)bh->b_data; lfn = be64_to_cpu(lf->lf_next); if (lf->lf_entries) { entries2 += be16_to_cpu(lf->lf_entries); dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, gfs2_dirent_gather, NULL, &g); error = PTR_ERR(dent); if (IS_ERR(dent)) goto out_free; if (entries2 != g.offset) { fs_warn(sdp, "Number of entries corrupt in dir " "leaf %llu, entries2 (%u) != " "g.offset (%u)\n", (unsigned long long)bh->b_blocknr, entries2, g.offset); error = -EIO; goto out_free; } error = 0; larr[leaf++] = bh; } else { brelse(bh); } } while(lfn); BUG_ON(entries2 != entries); error = do_filldir_main(ip, offset, opaque, filldir, darr, entries, copied); out_free: for(i = 0; i < leaf; i++) brelse(larr[i]); gfs2_free_sort_buffer(larr); out: return error; } /** * gfs2_dir_readahead - Issue read-ahead requests for leaf blocks. * * Note: we can't calculate each index like dir_e_read can because we don't * have the leaf, and therefore we don't have the depth, and therefore we * don't have the length. So we have to just read enough ahead to make up * for the loss of information. */ static void gfs2_dir_readahead(struct inode *inode, unsigned hsize, u32 index, struct file_ra_state *f_ra) { struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_glock *gl = ip->i_gl; struct buffer_head *bh; u64 blocknr = 0, last; unsigned count; /* First check if we've already read-ahead for the whole range. */ if (index + MAX_RA_BLOCKS < f_ra->start) return; f_ra->start = max((pgoff_t)index, f_ra->start); for (count = 0; count < MAX_RA_BLOCKS; count++) { if (f_ra->start >= hsize) /* if exceeded the hash table */ break; last = blocknr; blocknr = be64_to_cpu(ip->i_hash_cache[f_ra->start]); f_ra->start++; if (blocknr == last) continue; bh = gfs2_getbuf(gl, blocknr, 1); if (trylock_buffer(bh)) { if (buffer_uptodate(bh)) { unlock_buffer(bh); brelse(bh); continue; } bh->b_end_io = end_buffer_read_sync; submit_bh(READA | REQ_META, bh); continue; } brelse(bh); } } /** * dir_e_read - Reads the entries from a directory into a filldir buffer * @dip: dinode pointer * @offset: the hash of the last entry read shifted to the right once * @opaque: buffer for the filldir function to fill * @filldir: points to the filldir function to use * * Returns: errno */ static int dir_e_read(struct inode *inode, u64 *offset, void *opaque, filldir_t filldir, struct file_ra_state *f_ra) { struct gfs2_inode *dip = GFS2_I(inode); u32 hsize, len = 0; u32 hash, index; __be64 *lp; int copied = 0; int error = 0; unsigned depth = 0; hsize = 1 << dip->i_depth; hash = gfs2_dir_offset2hash(*offset); index = hash >> (32 - dip->i_depth); if (dip->i_hash_cache == NULL) f_ra->start = 0; lp = gfs2_dir_get_hash_table(dip); if (IS_ERR(lp)) return PTR_ERR(lp); gfs2_dir_readahead(inode, hsize, index, f_ra); while (index < hsize) { error = gfs2_dir_read_leaf(inode, offset, opaque, filldir, &copied, &depth, be64_to_cpu(lp[index])); if (error) break; len = 1 << (dip->i_depth - depth); index = (index & ~(len - 1)) + len; } if (error > 0) error = 0; return error; } int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque, filldir_t filldir, struct file_ra_state *f_ra) { struct gfs2_inode *dip = GFS2_I(inode); struct gfs2_sbd *sdp = GFS2_SB(inode); struct dirent_gather g; const struct gfs2_dirent **darr, *dent; struct buffer_head *dibh; int copied = 0; int error; if (!dip->i_entries) return 0; if (dip->i_diskflags & GFS2_DIF_EXHASH) return dir_e_read(inode, offset, opaque, filldir, f_ra); if (!gfs2_is_stuffed(dip)) { gfs2_consist_inode(dip); return -EIO; } error = gfs2_meta_inode_buffer(dip, &dibh); if (error) return error; error = -ENOMEM; /* 96 is max number of dirents which can be stuffed into an inode */ darr = kmalloc(96 * sizeof(struct gfs2_dirent *), GFP_NOFS); if (darr) { g.pdent = darr; g.offset = 0; dent = gfs2_dirent_scan(inode, dibh->b_data, dibh->b_size, gfs2_dirent_gather, NULL, &g); if (IS_ERR(dent)) { error = PTR_ERR(dent); goto out; } if (dip->i_entries != g.offset) { fs_warn(sdp, "Number of entries corrupt in dir %llu, " "ip->i_entries (%u) != g.offset (%u)\n", (unsigned long long)dip->i_no_addr, dip->i_entries, g.offset); error = -EIO; goto out; } error = do_filldir_main(dip, offset, opaque, filldir, darr, dip->i_entries, &copied); out: kfree(darr); } if (error > 0) error = 0; brelse(dibh); return error; } /** * gfs2_dir_search - Search a directory * @dip: The GFS2 inode * @filename: * @inode: * * This routine searches a directory for a file or another directory. * Assumes a glock is held on dip. * * Returns: errno */ struct inode *gfs2_dir_search(struct inode *dir, const struct qstr *name) { struct buffer_head *bh; struct gfs2_dirent *dent; struct inode *inode; dent = gfs2_dirent_search(dir, name, gfs2_dirent_find, &bh); if (dent) { if (IS_ERR(dent)) return ERR_CAST(dent); inode = gfs2_inode_lookup(dir->i_sb, be16_to_cpu(dent->de_type), be64_to_cpu(dent->de_inum.no_addr), be64_to_cpu(dent->de_inum.no_formal_ino), 0); brelse(bh); return inode; } return ERR_PTR(-ENOENT); } int gfs2_dir_check(struct inode *dir, const struct qstr *name, const struct gfs2_inode *ip) { struct buffer_head *bh; struct gfs2_dirent *dent; int ret = -ENOENT; dent = gfs2_dirent_search(dir, name, gfs2_dirent_find, &bh); if (dent) { if (IS_ERR(dent)) return PTR_ERR(dent); if (ip) { if (be64_to_cpu(dent->de_inum.no_addr) != ip->i_no_addr) goto out; if (be64_to_cpu(dent->de_inum.no_formal_ino) != ip->i_no_formal_ino) goto out; if (unlikely(IF2DT(ip->i_inode.i_mode) != be16_to_cpu(dent->de_type))) { gfs2_consist_inode(GFS2_I(dir)); ret = -EIO; goto out; } } ret = 0; out: brelse(bh); } return ret; } static int dir_new_leaf(struct inode *inode, const struct qstr *name) { struct buffer_head *bh, *obh; struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_leaf *leaf, *oleaf; int error; u32 index; u64 bn; index = name->hash >> (32 - ip->i_depth); error = get_first_leaf(ip, index, &obh); if (error) return error; do { oleaf = (struct gfs2_leaf *)obh->b_data; bn = be64_to_cpu(oleaf->lf_next); if (!bn) break; brelse(obh); error = get_leaf(ip, bn, &obh); if (error) return error; } while(1); gfs2_trans_add_meta(ip->i_gl, obh); leaf = new_leaf(inode, &bh, be16_to_cpu(oleaf->lf_depth)); if (!leaf) { brelse(obh); return -ENOSPC; } oleaf->lf_next = cpu_to_be64(bh->b_blocknr); brelse(bh); brelse(obh); error = gfs2_meta_inode_buffer(ip, &bh); if (error) return error; gfs2_trans_add_meta(ip->i_gl, bh); gfs2_add_inode_blocks(&ip->i_inode, 1); gfs2_dinode_out(ip, bh->b_data); brelse(bh); return 0; } /** * gfs2_dir_add - Add new filename into directory * @dip: The GFS2 inode * @filename: The new name * @inode: The inode number of the entry * @type: The type of the entry * * Returns: 0 on success, error code on failure */ int gfs2_dir_add(struct inode *inode, const struct qstr *name, const struct gfs2_inode *nip) { struct gfs2_inode *ip = GFS2_I(inode); struct buffer_head *bh; struct gfs2_dirent *dent; struct gfs2_leaf *leaf; int error; while(1) { dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space, &bh); if (dent) { if (IS_ERR(dent)) return PTR_ERR(dent); dent = gfs2_init_dirent(inode, dent, name, bh); gfs2_inum_out(nip, dent); dent->de_type = cpu_to_be16(IF2DT(nip->i_inode.i_mode)); if (ip->i_diskflags & GFS2_DIF_EXHASH) { leaf = (struct gfs2_leaf *)bh->b_data; be16_add_cpu(&leaf->lf_entries, 1); } brelse(bh); ip->i_entries++; ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME; if (S_ISDIR(nip->i_inode.i_mode)) inc_nlink(&ip->i_inode); mark_inode_dirty(inode); error = 0; break; } if (!(ip->i_diskflags & GFS2_DIF_EXHASH)) { error = dir_make_exhash(inode); if (error) break; continue; } error = dir_split_leaf(inode, name); if (error == 0) continue; if (error < 0) break; if (ip->i_depth < GFS2_DIR_MAX_DEPTH) { error = dir_double_exhash(ip); if (error) break; error = dir_split_leaf(inode, name); if (error < 0) break; if (error == 0) continue; } error = dir_new_leaf(inode, name); if (!error) continue; error = -ENOSPC; break; } return error; } /** * gfs2_dir_del - Delete a directory entry * @dip: The GFS2 inode * @filename: The filename * * Returns: 0 on success, error code on failure */ int gfs2_dir_del(struct gfs2_inode *dip, const struct dentry *dentry) { const struct qstr *name = &dentry->d_name; struct gfs2_dirent *dent, *prev = NULL; struct buffer_head *bh; /* Returns _either_ the entry (if its first in block) or the previous entry otherwise */ dent = gfs2_dirent_search(&dip->i_inode, name, gfs2_dirent_prev, &bh); if (!dent) { gfs2_consist_inode(dip); return -EIO; } if (IS_ERR(dent)) { gfs2_consist_inode(dip); return PTR_ERR(dent); } /* If not first in block, adjust pointers accordingly */ if (gfs2_dirent_find(dent, name, NULL) == 0) { prev = dent; dent = (struct gfs2_dirent *)((char *)dent + be16_to_cpu(prev->de_rec_len)); } dirent_del(dip, bh, prev, dent); if (dip->i_diskflags & GFS2_DIF_EXHASH) { struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data; u16 entries = be16_to_cpu(leaf->lf_entries); if (!entries) gfs2_consist_inode(dip); leaf->lf_entries = cpu_to_be16(--entries); } brelse(bh); if (!dip->i_entries) gfs2_consist_inode(dip); dip->i_entries--; dip->i_inode.i_mtime = dip->i_inode.i_ctime = CURRENT_TIME; if (S_ISDIR(dentry->d_inode->i_mode)) drop_nlink(&dip->i_inode); mark_inode_dirty(&dip->i_inode); return 0; } /** * gfs2_dir_mvino - Change inode number of directory entry * @dip: The GFS2 inode * @filename: * @new_inode: * * This routine changes the inode number of a directory entry. It's used * by rename to change ".." when a directory is moved. * Assumes a glock is held on dvp. * * Returns: errno */ int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename, const struct gfs2_inode *nip, unsigned int new_type) { struct buffer_head *bh; struct gfs2_dirent *dent; int error; dent = gfs2_dirent_search(&dip->i_inode, filename, gfs2_dirent_find, &bh); if (!dent) { gfs2_consist_inode(dip); return -EIO; } if (IS_ERR(dent)) return PTR_ERR(dent); gfs2_trans_add_meta(dip->i_gl, bh); gfs2_inum_out(nip, dent); dent->de_type = cpu_to_be16(new_type); if (dip->i_diskflags & GFS2_DIF_EXHASH) { brelse(bh); error = gfs2_meta_inode_buffer(dip, &bh); if (error) return error; gfs2_trans_add_meta(dip->i_gl, bh); } dip->i_inode.i_mtime = dip->i_inode.i_ctime = CURRENT_TIME; gfs2_dinode_out(dip, bh->b_data); brelse(bh); return 0; } /** * leaf_dealloc - Deallocate a directory leaf * @dip: the directory * @index: the hash table offset in the directory * @len: the number of pointers to this leaf * @leaf_no: the leaf number * @leaf_bh: buffer_head for the starting leaf * last_dealloc: 1 if this is the final dealloc for the leaf, else 0 * * Returns: errno */ static int leaf_dealloc(struct gfs2_inode *dip, u32 index, u32 len, u64 leaf_no, struct buffer_head *leaf_bh, int last_dealloc) { struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct gfs2_leaf *tmp_leaf; struct gfs2_rgrp_list rlist; struct buffer_head *bh, *dibh; u64 blk, nblk; unsigned int rg_blocks = 0, l_blocks = 0; char *ht; unsigned int x, size = len * sizeof(u64); int error; error = gfs2_rindex_update(sdp); if (error) return error; memset(&rlist, 0, sizeof(struct gfs2_rgrp_list)); ht = kzalloc(size, GFP_NOFS); if (ht == NULL) ht = vzalloc(size); if (!ht) return -ENOMEM; error = gfs2_quota_hold(dip, NO_UID_QUOTA_CHANGE, NO_GID_QUOTA_CHANGE); if (error) goto out; /* Count the number of leaves */ bh = leaf_bh; for (blk = leaf_no; blk; blk = nblk) { if (blk != leaf_no) { error = get_leaf(dip, blk, &bh); if (error) goto out_rlist; } tmp_leaf = (struct gfs2_leaf *)bh->b_data; nblk = be64_to_cpu(tmp_leaf->lf_next); if (blk != leaf_no) brelse(bh); gfs2_rlist_add(dip, &rlist, blk); l_blocks++; } gfs2_rlist_alloc(&rlist, LM_ST_EXCLUSIVE); for (x = 0; x < rlist.rl_rgrps; x++) { struct gfs2_rgrpd *rgd; rgd = rlist.rl_ghs[x].gh_gl->gl_object; rg_blocks += rgd->rd_length; } error = gfs2_glock_nq_m(rlist.rl_rgrps, rlist.rl_ghs); if (error) goto out_rlist; error = gfs2_trans_begin(sdp, rg_blocks + (DIV_ROUND_UP(size, sdp->sd_jbsize) + 1) + RES_DINODE + RES_STATFS + RES_QUOTA, l_blocks); if (error) goto out_rg_gunlock; bh = leaf_bh; for (blk = leaf_no; blk; blk = nblk) { if (blk != leaf_no) { error = get_leaf(dip, blk, &bh); if (error) goto out_end_trans; } tmp_leaf = (struct gfs2_leaf *)bh->b_data; nblk = be64_to_cpu(tmp_leaf->lf_next); if (blk != leaf_no) brelse(bh); gfs2_free_meta(dip, blk, 1); gfs2_add_inode_blocks(&dip->i_inode, -1); } error = gfs2_dir_write_data(dip, ht, index * sizeof(u64), size); if (error != size) { if (error >= 0) error = -EIO; goto out_end_trans; } error = gfs2_meta_inode_buffer(dip, &dibh); if (error) goto out_end_trans; gfs2_trans_add_meta(dip->i_gl, dibh); /* On the last dealloc, make this a regular file in case we crash. (We don't want to free these blocks a second time.) */ if (last_dealloc) dip->i_inode.i_mode = S_IFREG; gfs2_dinode_out(dip, dibh->b_data); brelse(dibh); out_end_trans: gfs2_trans_end(sdp); out_rg_gunlock: gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs); out_rlist: gfs2_rlist_free(&rlist); gfs2_quota_unhold(dip); out: if (is_vmalloc_addr(ht)) vfree(ht); else kfree(ht); return error; } /** * gfs2_dir_exhash_dealloc - free all the leaf blocks in a directory * @dip: the directory * * Dealloc all on-disk directory leaves to FREEMETA state * Change on-disk inode type to "regular file" * * Returns: errno */ int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip) { struct buffer_head *bh; struct gfs2_leaf *leaf; u32 hsize, len; u32 index = 0, next_index; __be64 *lp; u64 leaf_no; int error = 0, last; hsize = 1 << dip->i_depth; lp = gfs2_dir_get_hash_table(dip); if (IS_ERR(lp)) return PTR_ERR(lp); while (index < hsize) { leaf_no = be64_to_cpu(lp[index]); if (leaf_no) { error = get_leaf(dip, leaf_no, &bh); if (error) goto out; leaf = (struct gfs2_leaf *)bh->b_data; len = 1 << (dip->i_depth - be16_to_cpu(leaf->lf_depth)); next_index = (index & ~(len - 1)) + len; last = ((next_index >= hsize) ? 1 : 0); error = leaf_dealloc(dip, index, len, leaf_no, bh, last); brelse(bh); if (error) goto out; index = next_index; } else index++; } if (index != hsize) { gfs2_consist_inode(dip); error = -EIO; } out: return error; } /** * gfs2_diradd_alloc_required - find if adding entry will require an allocation * @ip: the file being written to * @filname: the filename that's going to be added * * Returns: 1 if alloc required, 0 if not, -ve on error */ int gfs2_diradd_alloc_required(struct inode *inode, const struct qstr *name) { struct gfs2_dirent *dent; struct buffer_head *bh; dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space, &bh); if (!dent) { return 1; } if (IS_ERR(dent)) return PTR_ERR(dent); brelse(bh); return 0; }
e269c1bbf293ac93dbfe681480efbcef60d753ca
0744dcc5394cebf57ebcba343747af6871b67017
/os/net/netmgr/net_vfs.c
e66d4ec1dab258903bc18e453a5f018b86a25b80
[ "Apache-2.0", "LicenseRef-scancode-other-permissive", "GPL-1.0-or-later", "BSD-3-Clause", "ISC", "MIT", "LicenseRef-scancode-warranty-disclaimer" ]
permissive
Samsung/TizenRT
96abf62f1853f61fcf91ff14671a5e0c6ca48fdb
1a5c2e00a4b1bbf4c505bbf5cc6a8259e926f686
refs/heads/master
2023-08-31T08:59:33.327998
2023-08-08T06:09:20
2023-08-31T04:38:20
82,517,252
590
719
Apache-2.0
2023-09-14T06:54:49
2017-02-20T04:38:30
C
UTF-8
C
false
false
13,635
c
net_vfs.c
/**************************************************************************** * * Copyright 2019 Samsung Electronics All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the License. * ****************************************************************************/ #include <tinyara/config.h> #include <fcntl.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <sys/sockio.h> #include <errno.h> #include <debug.h> #include <net/if.h> #include <tinyara/net/net.h> #include "netstack.h" #include <tinyara/net/netlog.h> #define TAG "[NETMGR]" /**************************************************************************** * Name: net_checksd * * Description: * Check if the socket descriptor is valid for the provided TCB and if it * supports the requested access. This trivial operation is part of the * fdopen() operation when the fdopen() is performed on a socket descriptor. * It simply performs some sanity checking before permitting the socket * descriptor to be wrapped as a C FILE stream. * ****************************************************************************/ int net_checksd(int sd, int oflags) { NETSTACK_CALL_BYFD(sd, checksd, (sd, oflags)); } /**************************************************************************** * Function: net_clone * * Description: * Performs the low level, common portion of net_dupsd() and net_dupsd2() * ****************************************************************************/ int net_clone(FAR struct socket *sock1, FAR struct socket *sock2) { NET_LOGKV(TAG, "Not supported yet\n"); return -1; } /**************************************************************************** * Function: net_dupsd * * Description: * Clone a socket descriptor to an arbitray descriptor number. If file * descriptors are implemented, then this is called by dup() for the case * of socket file descriptors. If file descriptors are not implemented, * then this function IS dup(). * ****************************************************************************/ int net_dupsd(int sd) { NETSTACK_CALL_BYFD(sd, dup, (sd)); } /**************************************************************************** * Function: net_dupsd2 * * Description: * Clone a socket descriptor to an arbitray descriptor number. If file * descriptors are implemented, then this is called by dup2() for the case * of socket file descriptors. If file descriptors are not implemented, * then this function IS dup2(). * ****************************************************************************/ int net_dupsd2(int sd1, int sd2) { NETSTACK_CALL_BYFD(sd1, dup2, (sd1, sd2)); } /**************************************************************************** * Function: net_close * * Description: * Performs the close operation on socket descriptors * * Parameters: * sd Socket descriptor of socket * * Returned Value: * 0 on success; -1 on error with errno set appropriately. * * Assumptions: * ****************************************************************************/ int net_close(int sd) { NETSTACK_CALL_BYFD(sd, close, (sd)); } /**************************************************************************** * Function: net_poll * * Description: * poll() waits for one of a set of file descriptors to become ready to * perform I/O. * * Returned Value: * 0 on success; -1 on error with errno set appropriately. * * Assumptions: * ****************************************************************************/ int net_poll(int sd, struct pollfd *fds, bool setup) { NETSTACK_CALL_BYFD(sd, poll, (sd, fds, setup)); } /**************************************************************************** * Name: net_ioctl * * Description: * Perform network device specific operations. * * Parameters: * sd Socket descriptor of device * cmd The ioctl command * arg The argument of the ioctl cmd * * Return: * >=0 on success (positive non-zero values are cmd-specific) * On a failure, -1 is returned with errno set appropriately * * EBADF * 'sd' is not a valid descriptor. * EFAULT * 'arg' references an inaccessible memory area. * ENOTTY * 'cmd' not valid. * EINVAL * 'arg' is not valid. * ENOTTY * 'sd' is not associated with a network device. * ENOTTY * The specified request does not apply to the kind of object that the * descriptor 'sd' references. * ****************************************************************************/ extern int netdev_imsfioctl(FAR struct socket *sock, int cmd, FAR struct ip_msfilter *imsf); extern int netdev_ifrioctl(FAR struct socket *sock, int cmd, FAR struct ifreq *req); int net_ioctl(int sd, int cmd, unsigned long arg) { FAR struct lwip_sock *sock = NULL; int ret = -ENOTTY; /* Check if this is a valid command. In all cases, arg is a pointer that has * been cast to unsigned long. Verify that the value of the to-be-pointer is * non-NULL. */ if (!((_FIOCVALID(cmd)) || (_SIOCVALID(cmd)))) { ret = -ENOTTY; NET_LOGKE(TAG, "command is not valid\n"); goto errout; } /* ToDo: Verify that the sd corresponds to valid, allocated socket */ sock = get_socket_by_pid(sd, getpid()); if (sock == NULL) { NET_LOGKE(TAG, "get socket fail\n"); ret = -EBADF; goto errout; } /* Execute the command */ struct netstack *st = get_netstack_byfd(sd); if (st) { NETSTACK_CALL_RET(st, ioctl, (sd, cmd, arg), ret); } if (ret == -ENOTTY) { ret = netdev_ifrioctl(NULL, cmd, (FAR struct ifreq *)((uintptr_t)arg)); } #ifdef CONFIG_NET_IGMP if (ret == -ENOTTY) { ret = netdev_imsfioctl(NULL, cmd, (FAR struct ip_msfilter *)((uintptr_t)arg)); } #endif /* CONFIG_NET_IGMP */ #ifdef CONFIG_NET_ROUTE if (ret == -ENOTTY) { ret = netdev_rtioctl(NULL, cmd, (FAR struct rtentry *)((uintptr_t)arg)); } #endif /* CONFIG_NET_ROUTE */ /* Check for success or failure */ if (ret >= 0) { return ret; } /* On failure, set the errno and return -1 */ errout: errno = -ret; return ERROR; } /**************************************************************************** * Name: net_vfcntl * * Description: * Performs fcntl operations on socket * * Input Parameters: * sd - Socket descriptor of the socket to operate on * cmd - The fcntl command. * ap - Command-specific arguments * * Returned Value: * Zero (OK) is returned on success; -1 (ERROR) is returned on failure and * the errno value is set appropriately. * ****************************************************************************/ int net_vfcntl(int sd, int cmd, va_list ap) { FAR struct socket *sock = (struct socket *)get_socket_by_pid(sd, getpid()); int err = 0; int ret = 0; NET_LOGKV(TAG, "sd=%d cmd=%d\n", sd, cmd); /* Verify that the sd corresponds to valid, allocated socket */ if (!sock) { err = EBADF; NET_LOGKE(TAG, "invalid socket\n"); goto errout; } /* Interrupts must be disabled in order to perform operations on socket structures */ struct netstack *st = get_netstack_byfd(sd); // net_lock(); switch (cmd) { case F_DUPFD: /* Return a new file descriptor which shall be the lowest numbered * available (that is, not already open) file descriptor greater than * or equal to the third argument, arg, taken as an integer of type * int. The new file descriptor shall refer to the same open file * description as the original file descriptor, and shall share any * locks. The FD_CLOEXEC flag associated with the new file descriptor * shall be cleared to keep the file open across calls to one of the * exec functions. */ { NETSTACK_CALL_RET(st, dup, (sd), ret); } break; case F_GETFD: /* Get the file descriptor flags defined in <fcntl.h> that are associated * with the file descriptor fd. File descriptor flags are associated * with a single file descriptor and do not affect other file descriptors * that refer to the same file. */ case F_SETFD: /* Set the file descriptor flags defined in <fcntl.h>, that are associated * with fd, to the third argument, arg, taken as type int. If the * FD_CLOEXEC flag in the third argument is 0, the file shall remain open * across the exec functions; otherwise, the file shall be closed upon * successful execution of one of the exec functions. */ err = ENOSYS; /* F_GETFD and F_SETFD not implemented */ break; case F_GETFL: /* Get the file status flags and file access modes, defined in * <fcntl.h>, for the file description associated with fd. The file * access modes can be extracted from the return value using the * mask O_ACCMODE, which is defined in <fcntl.h>. File status flags * and file access modes are associated with the file description * and do not affect other file descriptors that refer to the same * file with different open file descriptions. */ { NETSTACK_CALL_RET(st, fcntl, (sd, cmd, ap), ret); } break; case F_SETFL: /* Set the file status flags, defined in <fcntl.h>, for the file description * associated with fd from the corresponding bits in the third argument, * arg, taken as type int. Bits corresponding to the file access mode and * the file creation flags, as defined in <fcntl.h>, that are set in arg shall * be ignored. If any bits in arg other than those mentioned here are changed * by the application, the result is unspecified. */ { NETSTACK_CALL_RET(st, fcntl, (sd, cmd, ap), ret); } break; case F_GETOWN: /* If fd refers to a socket, get the process or process group ID specified * to receive SIGURG signals when out-of-band data is available. Positive values * indicate a process ID; negative values, other than -1, indicate a process group * ID. If fd does not refer to a socket, the results are unspecified. */ case F_SETOWN: /* If fd refers to a socket, set the process or process group ID specified * to receive SIGURG signals when out-of-band data is available, using the value * of the third argument, arg, taken as type int. Positive values indicate a * process ID; negative values, other than -1, indicate a process group ID. If * fd does not refer to a socket, the results are unspecified. */ case F_GETLK: /* Get the first lock which blocks the lock description pointed to by the third * argument, arg, taken as a pointer to type struct flock, defined in <fcntl.h>. * The information retrieved shall overwrite the information passed to fcntl() in * the structure flock. If no lock is found that would prevent this lock from being * created, then the structure shall be left unchanged except for the lock type * which shall be set to F_UNLCK. */ case F_SETLK: /* Set or clear a file segment lock according to the lock description pointed to * by the third argument, arg, taken as a pointer to type struct flock, defined in * <fcntl.h>. F_SETLK can establish shared (or read) locks (F_RDLCK) or exclusive * (or write) locks (F_WRLCK), as well as to remove either type of lock (F_UNLCK). * F_RDLCK, F_WRLCK, and F_UNLCK are defined in <fcntl.h>. If a shared or exclusive * lock cannot be set, fcntl() shall return immediately with a return value of -1. */ case F_SETLKW: /* This command shall be equivalent to F_SETLK except that if a shared or exclusive * lock is blocked by other locks, the thread shall wait until the request can be * satisfied. If a signal that is to be caught is received while fcntl() is waiting * for a region, fcntl() shall be interrupted. Upon return from the signal handler, * fcntl() shall return -1 with errno set to [EINTR], and the lock operation shall * not be done. */ err = ENOSYS; /* F_GETOWN, F_SETOWN, F_GETLK, F_SETLK, F_SETLKW */ break; default: err = EINVAL; break; } // net_unlock(); errout: if (err != 0) { errno = err; return ERROR; } return ret; } /**************************************************************************** * Name: net_initlist * * Description: * Initialize a list of sockets for a new task * * Input Parameters: * list -- A reference to the pre-allocated socket list to be initialized. * * Returned Value: * None * ****************************************************************************/ void net_initlist(FAR struct socketlist *list) { struct netstack *stk = get_netstack(TR_SOCKET); if (stk) { stk->ops->initlist(list); } } /**************************************************************************** * Name: net_releaselist * * Description: * Release resources held by the socket list * * Input Parameters: * list -- A reference to the pre-allocated socket list to be un-initialized. * * Returned Value: * None * ****************************************************************************/ void net_releaselist(FAR struct socketlist *list) { DEBUGASSERT(list); struct netstack *stk = get_netstack(TR_SOCKET); if (stk) { stk->ops->releaselist(list); } /* Destroy the semaphore */ sem_destroy(&list->sl_sem); }
539728f66f1c8b9b73981d09d550c5c3744869e0
bb38c44037a99d0a12a12d92059678f2faebbc80
/src/include/catalog/pg_user_status.h
c06f7acfefca5856e19a186e9c8927f5dfa9cd02
[ "LicenseRef-scancode-mulanpsl-2.0-en", "LicenseRef-scancode-unknown-license-reference", "PostgreSQL", "BSD-3-Clause", "LGPL-2.0-or-later", "LicenseRef-scancode-unicode", "LicenseRef-scancode-warranty-disclaimer", "curl", "GPL-1.0-or-later", "LGPL-2.1-or-later", "LGPL-2.1-only", "CC-BY-4.0", "LicenseRef-scancode-protobuf", "OpenSSL", "LicenseRef-scancode-generic-export-compliance", "X11-distribute-modifications-variant", "LicenseRef-scancode-other-permissive", "MIT", "NCSA", "Python-2.0", "LicenseRef-scancode-openssl", "LicenseRef-scancode-ssleay-windows", "CC-BY-3.0", "LicenseRef-scancode-other-copyleft", "GPL-2.0-only", "BSL-1.0", "Apache-2.0", "LGPL-2.0-only", "LicenseRef-scancode-public-domain", "BSD-2-Clause", "Zlib" ]
permissive
opengauss-mirror/openGauss-server
a9c5a62908643492347830826c56da49f0942796
310e84631c68c8bf37b004148b66f94064f701e4
refs/heads/master
2023-07-26T19:29:12.495484
2023-07-17T12:23:32
2023-07-17T12:23:32
276,117,477
591
208
MulanPSL-2.0
2023-04-28T12:30:18
2020-06-30T14:08:59
C++
UTF-8
C
false
false
2,690
h
pg_user_status.h
/* * Copyright (c) 2020 Huawei Technologies Co.,Ltd. * * openGauss is licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: * * http://license.coscl.org.cn/MulanPSL2 * * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. * --------------------------------------------------------------------------------------- * * pg_user_status.h * definition of the system "user status" relation (pg_user_status) * along with the relation's initial contents. * * * IDENTIFICATION * src/include/catalog/pg_user_status.h * * --------------------------------------------------------------------------------------- */ #ifndef PG_USER_STATUS_H #define PG_USER_STATUS_H #include "catalog/genbki.h" /* define the timestamptz for the locktime in pg_user_status */ #define timestamptz Datum /* define the OID of the table pg_user_status */ #define UserStatusRelationId 3460 #define UserStatusRelation_Rowtype_Id 3463 CATALOG(pg_user_status,3460) BKI_SHARED_RELATION BKI_ROWTYPE_OID(3463) BKI_SCHEMA_MACRO { Oid roloid; /* role OID */ int4 failcount; /* failed num of login attampts */ timestamptz locktime; /* role lock time */ int2 rolstatus; /* role status */ int8 permspace; /* perm space */ int8 tempspace; /* temp space */ int2 passwordexpired; /* password expired status */ } FormData_pg_user_status; #undef timestamptz /* ------------------------------------------------------------------------- * Form_pg_user_status corresponds to a pointer to a tuple with * the format of pg_user_status relation. * ------------------------------------------------------------------------- */ typedef FormData_pg_user_status *Form_pg_user_status; /* ------------------------------------------------------------------------- * compiler constants for pg_user_status * ------------------------------------------------------------------------- */ #define Natts_pg_user_status 7 #define Anum_pg_user_status_roloid 1 #define Anum_pg_user_status_failcount 2 #define Anum_pg_user_status_locktime 3 #define Anum_pg_user_status_rolstatus 4 #define Anum_pg_user_status_permspace 5 #define Anum_pg_user_status_tempspace 6 #define Anum_pg_user_status_passwordexpired 7 #endif /* PG_USER_STATUS_H */
4d20c8984b1aae6ab42ac7122c55f9fa4d4eeca8
ea91147a26512b81b33be0e398e62d8624b7ec9d
/examples/weak_linking/src/error.c
5e7db631c125ef0a2e7722572284db6d0c0b2b37
[ "MIT" ]
permissive
meekrosoft/fff
7755024c49b0369635bc173fb265d20c3b5f41ae
5111c61e1ef7848e3afd3550044a8cf4405f4199
refs/heads/master
2023-09-02T12:45:28.872264
2023-05-22T09:31:38
2023-05-22T09:31:38
1,168,299
590
173
NOASSERTION
2023-05-19T23:43:18
2010-12-14T15:16:42
C++
UTF-8
C
false
false
216
c
error.c
#include <assert.h> #include "error.h" char* runtime_error_nice_print( const char* msg ) { char* buffer = malloc(512); snprintf(buffer, 512, "Got error: %s", msg ); buffer[511] = 0; return buffer; }
f334ed859209657f5b20008a007044ea8da2977b
763d301330d5b5c74aa06582832955d4ac35c19b
/AnimatedNoise/AnimatedNoise.h
e452ce570a1d4719b0e488128898d0e3b82d692e
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
bryful/F-s-PluginsProjects
dd0bc719df6b0a9c7dd397377319d954ba1099a8
942be10e7b334912649f39223d1aca1824946c58
refs/heads/master
2022-07-22T05:14:13.664573
2022-07-14T09:46:30
2022-07-14T09:46:30
186,790,231
185
33
MIT
2020-12-31T04:50:48
2019-05-15T09:06:45
C++
SHIFT_JIS
C
false
false
2,497
h
AnimatedNoise.h
//----------------------------------------------------------------------------------- /* F's Plugins-cs4 for VS2008 */ //----------------------------------------------------------------------------------- #pragma once #ifndef AnimatedNoise_H #define AnimatedNoise_H #include "Fs_Target.h" #include "AEConfig.h" #include "entry.h" //#include "PrSDKAESupport.h" #include "AE_Effect.h" #include "AE_EffectCB.h" #include "AE_EffectCBSuites.h" #include "AE_Macros.h" #include "AEGP_SuiteHandler.h" #include "String_Utils.h" #include "Param_Utils.h" #include "Smart_Utils.h" #if defined(PF_AE100_PLUG_IN_VERSION) #include "AEFX_SuiteHelper.h" #define refconType void* #else #include "PF_Suite_Helper.h" #define refconType A_long #endif #ifdef AE_OS_WIN #include <Windows.h> #endif #include "../FsLibrary/FsAE.h" //ユーザーインターフェースのID //ParamsSetup関数とRender関数のparamsパラメータのIDになる enum { ID_INPUT = 0, // default input layer ID_ANIMATED_CB, //動き ID_ANIMATED_ADD, //動き ID_VALUE_ADD, //ノイズの量 ID_LENGTH_FIXED, //ノイズの強さ ID_COLOR_CB, //カラーかモノクロか ID_BLOCK_VALUE_FIXED, //ブロックノイズの量 ID_BLOCK_LENGTH_FIXED, //ブロックノイズの強さ ID_BLOCK_WIDTH_ADD, //ブロックノイズ横幅 ID_BLOCK_HEIGHT_ADD, //ブロックノイズ縦幅 ID_BLOCK_COLOR_CB, //カラーかモノクロか ID_NUM_PARAMS }; typedef struct PrmTbl{ PF_PixelPtr data; //画像 A_long width; //画像の横幅 A_long height; //画像の高さ A_long w; //ターゲット A_long h; A_long target; PF_Boolean animFlag; // A_long anim; A_long frame; A_long seed; A_long value; PF_Fixed length; PF_Boolean colorFlag; PF_Fixed block_value; PF_Fixed block_length; A_long block_width; A_long block_height; PF_Boolean block_colorFlag; } PrmTbl; static void NoiseMain8(PrmTbl *prm); static void NoiseMain16(PrmTbl *prm); static void NoiseMain32(PrmTbl *prm); static void NoiseBlock8(PrmTbl *prm); static void NoiseBlock16(PrmTbl *prm); static void NoiseBlock32(PrmTbl *prm); //------------------------------------------------------------------------------------------------- extern "C" { DllExport PF_Err EntryPointFunc ( PF_Cmd cmd, PF_InData *in_data, PF_OutData *out_data, PF_ParamDef *params[], PF_LayerDef *output, void *extraP); } //------------------------------------------------------- #endif // AnimatedNoise_H
a786379b00637a03bc47f5ae901fb148cd74d048
5eff7a36d9a9917dce9111f0c3074375fe6f7656
/lib/mesa/src/imagination/vulkan/winsys/pvr_winsys.h
c8887255553f8b28edc8096abb391c553498f80f
[]
no_license
openbsd/xenocara
cb392d02ebba06f6ff7d826fd8a89aa3b8401779
a012b5de33ea0b977095d77316a521195b26cc6b
refs/heads/master
2023-08-25T12:16:58.862008
2023-08-12T16:16:25
2023-08-12T16:16:25
66,967,384
177
66
null
2023-07-22T18:12:37
2016-08-30T18:36:01
C
UTF-8
C
false
false
15,559
h
pvr_winsys.h
/* * Copyright © 2022 Imagination Technologies Ltd. * * Based on radv_radeon_winsys.h which is: * Copyright © 2016 Red Hat. * Copyright © 2016 Bas Nieuwenhuizen * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #ifndef PVR_WINSYS_H #define PVR_WINSYS_H #include <pthread.h> #include <stdbool.h> #include <stdint.h> #include <vulkan/vulkan.h> #include "hwdef/rogue_hw_defs.h" #include "pvr_limits.h" #include "pvr_rogue_fw.h" #include "pvr_types.h" #include "util/macros.h" #include "util/vma.h" #include "vk_sync.h" struct pvr_device_info; struct pvr_device_runtime_info; struct pvr_winsys_heaps { struct pvr_winsys_heap *general_heap; struct pvr_winsys_heap *pds_heap; struct pvr_winsys_heap *rgn_hdr_heap; struct pvr_winsys_heap *transfer_3d_heap; struct pvr_winsys_heap *usc_heap; struct pvr_winsys_heap *vis_test_heap; }; struct pvr_winsys_static_data_offsets { uint64_t eot; uint64_t fence; uint64_t vdm_sync; uint64_t yuv_csc; }; struct pvr_winsys_heap { struct pvr_winsys *ws; pvr_dev_addr_t base_addr; pvr_dev_addr_t reserved_addr; uint64_t size; uint64_t reserved_size; uint32_t page_size; uint32_t log2_page_size; struct util_vma_heap vma_heap; int ref_count; pthread_mutex_t lock; /* These are the offsets from the base at which static data might be * uploaded. Some of these might be invalid since the kernel might not * return all of these offsets per each heap as they might not be * applicable. * You should know which to use beforehand. There should be no need to check * whether an offset is valid or invalid. */ struct pvr_winsys_static_data_offsets static_data_offsets; }; enum pvr_winsys_bo_type { PVR_WINSYS_BO_TYPE_GPU = 0, PVR_WINSYS_BO_TYPE_DISPLAY = 1, }; /** * \brief Flag passed to #pvr_winsys_ops.buffer_create to indicate that the * buffer should be CPU accessible. This is required in order to map the buffer * using #pvr_winsys_ops.buffer_map. */ #define PVR_WINSYS_BO_FLAG_CPU_ACCESS BITFIELD_BIT(0U) /** * \brief Flag passed to #pvr_winsys_ops.buffer_create to indicate that, when * the buffer is mapped to the GPU using #pvr_winsys.vma_map, it should be * mapped uncached. */ #define PVR_WINSYS_BO_FLAG_GPU_UNCACHED BITFIELD_BIT(1U) /** * \brief Flag passed to #pvr_winsys_ops.buffer_create to indicate that, when * the buffer is mapped to the GPU using #pvr_winsys.vma_map, it should only be * accessible to the Parameter Manager unit and firmware processor. */ #define PVR_WINSYS_BO_FLAG_PM_FW_PROTECT BITFIELD_BIT(2U) /** * \brief Flag passed to #pvr_winsys_ops.buffer_create to indicate that the * buffer should be zeroed at allocation time. */ #define PVR_WINSYS_BO_FLAG_ZERO_ON_ALLOC BITFIELD_BIT(3U) struct pvr_winsys_bo { struct pvr_winsys *ws; void *map; uint64_t size; bool is_imported; }; struct pvr_winsys_vma { struct pvr_winsys_heap *heap; /* Buffer and offset this vma is bound to. */ struct pvr_winsys_bo *bo; VkDeviceSize bo_offset; pvr_dev_addr_t dev_addr; uint64_t size; uint64_t mapped_size; }; struct pvr_winsys_free_list { struct pvr_winsys *ws; }; struct pvr_winsys_rt_dataset_create_info { /* Local freelist */ struct pvr_winsys_free_list *local_free_list; /* ISP register values */ uint32_t isp_merge_lower_x; uint32_t isp_merge_lower_y; uint32_t isp_merge_scale_x; uint32_t isp_merge_scale_y; uint32_t isp_merge_upper_x; uint32_t isp_merge_upper_y; uint32_t isp_mtile_size; /* PPP register values */ uint64_t ppp_multi_sample_ctl; uint64_t ppp_multi_sample_ctl_y_flipped; uint32_t ppp_screen; /* TE register values */ uint32_t te_aa; uint32_t te_mtile1; uint32_t te_mtile2; uint32_t te_screen; /* Allocations and associated information */ pvr_dev_addr_t vheap_table_dev_addr; pvr_dev_addr_t rtc_dev_addr; pvr_dev_addr_t tpc_dev_addr; uint32_t tpc_stride; uint32_t tpc_size; struct { pvr_dev_addr_t pm_mlist_dev_addr; pvr_dev_addr_t macrotile_array_dev_addr; pvr_dev_addr_t rgn_header_dev_addr; } rt_datas[ROGUE_NUM_RTDATAS]; uint64_t rgn_header_size; /* Miscellaneous */ uint32_t mtile_stride; uint16_t max_rts; }; struct pvr_winsys_rt_dataset { struct pvr_winsys *ws; }; enum pvr_winsys_ctx_priority { PVR_WINSYS_CTX_PRIORITY_LOW, PVR_WINSYS_CTX_PRIORITY_MEDIUM, PVR_WINSYS_CTX_PRIORITY_HIGH, }; struct pvr_winsys_render_ctx_create_info { enum pvr_winsys_ctx_priority priority; pvr_dev_addr_t vdm_callstack_addr; struct pvr_winsys_render_ctx_static_state { uint64_t vdm_ctx_state_base_addr; uint64_t geom_ctx_state_base_addr; struct { uint64_t vdm_ctx_store_task0; uint32_t vdm_ctx_store_task1; uint64_t vdm_ctx_store_task2; uint64_t vdm_ctx_resume_task0; uint32_t vdm_ctx_resume_task1; uint64_t vdm_ctx_resume_task2; } geom_state[2]; } static_state; }; struct pvr_winsys_render_ctx { struct pvr_winsys *ws; }; struct pvr_winsys_compute_ctx_create_info { enum pvr_winsys_ctx_priority priority; struct pvr_winsys_compute_ctx_static_state { uint64_t cdm_ctx_store_pds0; uint64_t cdm_ctx_store_pds0_b; uint32_t cdm_ctx_store_pds1; uint64_t cdm_ctx_terminate_pds; uint32_t cdm_ctx_terminate_pds1; uint64_t cdm_ctx_resume_pds0; uint64_t cdm_ctx_resume_pds0_b; } static_state; }; struct pvr_winsys_compute_ctx { struct pvr_winsys *ws; }; struct pvr_winsys_transfer_ctx_create_info { enum pvr_winsys_ctx_priority priority; }; struct pvr_winsys_transfer_ctx { struct pvr_winsys *ws; }; #define PVR_WINSYS_TRANSFER_FLAG_START BITFIELD_BIT(0U) #define PVR_WINSYS_TRANSFER_FLAG_END BITFIELD_BIT(1U) #define PVR_TRANSFER_MAX_PREPARES_PER_SUBMIT 16U #define PVR_TRANSFER_MAX_RENDER_TARGETS 3U struct pvr_winsys_transfer_regs { uint32_t event_pixel_pds_code; uint32_t event_pixel_pds_data; uint32_t event_pixel_pds_info; uint32_t isp_aa; uint32_t isp_bgobjvals; uint32_t isp_ctl; uint64_t isp_mtile_base; uint32_t isp_mtile_size; uint32_t isp_render; uint32_t isp_render_origin; uint32_t isp_rgn; uint64_t pbe_wordx_mrty[PVR_TRANSFER_MAX_RENDER_TARGETS * ROGUE_NUM_PBESTATE_REG_WORDS]; uint64_t pds_bgnd0_base; uint64_t pds_bgnd1_base; uint64_t pds_bgnd3_sizeinfo; uint32_t usc_clear_register0; uint32_t usc_clear_register1; uint32_t usc_clear_register2; uint32_t usc_clear_register3; uint32_t usc_pixel_output_ctrl; }; struct pvr_winsys_transfer_submit_info { uint32_t frame_num; uint32_t job_num; struct vk_sync *barrier; /* waits and stage_flags are arrays of length wait_count. */ struct vk_sync **waits; uint32_t wait_count; uint32_t *stage_flags; uint32_t cmd_count; struct { struct pvr_winsys_transfer_regs regs; /* Must be 0 or a combination of PVR_WINSYS_TRANSFER_FLAG_* flags. */ uint32_t flags; } cmds[PVR_TRANSFER_MAX_PREPARES_PER_SUBMIT]; }; #define PVR_WINSYS_COMPUTE_FLAG_PREVENT_ALL_OVERLAP BITFIELD_BIT(0U) #define PVR_WINSYS_COMPUTE_FLAG_SINGLE_CORE BITFIELD_BIT(1U) struct pvr_winsys_compute_submit_info { uint32_t frame_num; uint32_t job_num; struct vk_sync *barrier; /* waits and stage_flags are arrays of length wait_count. */ struct vk_sync **waits; uint32_t wait_count; uint32_t *stage_flags; struct { uint64_t tpu_border_colour_table; uint64_t cdm_ctrl_stream_base; uint64_t cdm_ctx_state_base_addr; uint32_t tpu; uint32_t cdm_resume_pds1; uint32_t cdm_item; uint32_t compute_cluster; } regs; /* Must be 0 or a combination of PVR_WINSYS_COMPUTE_FLAG_* flags. */ uint32_t flags; }; #define PVR_WINSYS_GEOM_FLAG_FIRST_GEOMETRY BITFIELD_BIT(0U) #define PVR_WINSYS_GEOM_FLAG_LAST_GEOMETRY BITFIELD_BIT(1U) #define PVR_WINSYS_GEOM_FLAG_SINGLE_CORE BITFIELD_BIT(2U) #define PVR_WINSYS_FRAG_FLAG_DEPTH_BUFFER_PRESENT BITFIELD_BIT(0U) #define PVR_WINSYS_FRAG_FLAG_STENCIL_BUFFER_PRESENT BITFIELD_BIT(1U) #define PVR_WINSYS_FRAG_FLAG_PREVENT_CDM_OVERLAP BITFIELD_BIT(2U) #define PVR_WINSYS_FRAG_FLAG_SINGLE_CORE BITFIELD_BIT(3U) struct pvr_winsys_render_submit_info { struct pvr_winsys_rt_dataset *rt_dataset; uint8_t rt_data_idx; uint32_t frame_num; uint32_t job_num; /* FIXME: should this be flags instead? */ bool run_frag; struct vk_sync *barrier_geom; struct vk_sync *barrier_frag; /* waits and stage_flags are arrays of length wait_count. */ struct vk_sync **waits; uint32_t wait_count; uint32_t *stage_flags; struct pvr_winsys_geometry_state { struct { uint64_t pds_ctrl; uint32_t ppp_ctrl; uint32_t te_psg; uint32_t tpu; uint64_t tpu_border_colour_table; uint64_t vdm_ctrl_stream_base; uint32_t vdm_ctx_resume_task0_size; } regs; /* Must be 0 or a combination of PVR_WINSYS_GEOM_FLAG_* flags. */ uint32_t flags; } geometry; struct pvr_winsys_fragment_state { struct { uint32_t event_pixel_pds_data; uint32_t event_pixel_pds_info; uint32_t isp_aa; uint32_t isp_bgobjdepth; uint32_t isp_bgobjvals; uint32_t isp_ctl; uint64_t isp_dbias_base; uint64_t isp_oclqry_base; uint64_t isp_scissor_base; uint64_t isp_stencil_load_store_base; uint64_t isp_zload_store_base; uint64_t isp_zlsctl; uint32_t isp_zls_pixels; uint64_t pbe_word[PVR_MAX_COLOR_ATTACHMENTS] [ROGUE_NUM_PBESTATE_REG_WORDS]; uint32_t pixel_phantom; uint64_t pds_bgnd[ROGUE_NUM_CR_PDS_BGRND_WORDS]; uint64_t pds_pr_bgnd[ROGUE_NUM_CR_PDS_BGRND_WORDS]; uint32_t tpu; uint64_t tpu_border_colour_table; uint32_t usc_pixel_output_ctrl; } regs; /* Must be 0 or a combination of PVR_WINSYS_FRAG_FLAG_* flags. */ uint32_t flags; uint32_t zls_stride; uint32_t sls_stride; } fragment; }; struct pvr_winsys_ops { void (*destroy)(struct pvr_winsys *ws); int (*device_info_init)(struct pvr_winsys *ws, struct pvr_device_info *dev_info, struct pvr_device_runtime_info *runtime_info); void (*get_heaps_info)(struct pvr_winsys *ws, struct pvr_winsys_heaps *heaps); VkResult (*buffer_create)(struct pvr_winsys *ws, uint64_t size, uint64_t alignment, enum pvr_winsys_bo_type type, uint32_t flags, struct pvr_winsys_bo **const bo_out); VkResult (*buffer_create_from_fd)(struct pvr_winsys *ws, int fd, struct pvr_winsys_bo **const bo_out); void (*buffer_destroy)(struct pvr_winsys_bo *bo); VkResult (*buffer_get_fd)(struct pvr_winsys_bo *bo, int *const fd_out); void *(*buffer_map)(struct pvr_winsys_bo *bo); void (*buffer_unmap)(struct pvr_winsys_bo *bo); struct pvr_winsys_vma *(*heap_alloc)(struct pvr_winsys_heap *heap, uint64_t size, uint64_t alignment); void (*heap_free)(struct pvr_winsys_vma *vma); pvr_dev_addr_t (*vma_map)(struct pvr_winsys_vma *vma, struct pvr_winsys_bo *bo, uint64_t offset, uint64_t size); void (*vma_unmap)(struct pvr_winsys_vma *vma); VkResult (*free_list_create)( struct pvr_winsys *ws, struct pvr_winsys_vma *free_list_vma, uint32_t initial_num_pages, uint32_t max_num_pages, uint32_t grow_num_pages, uint32_t grow_threshold, struct pvr_winsys_free_list *parent_free_list, struct pvr_winsys_free_list **const free_list_out); void (*free_list_destroy)(struct pvr_winsys_free_list *free_list); VkResult (*render_target_dataset_create)( struct pvr_winsys *ws, const struct pvr_winsys_rt_dataset_create_info *create_info, struct pvr_winsys_rt_dataset **const rt_dataset_out); void (*render_target_dataset_destroy)( struct pvr_winsys_rt_dataset *rt_dataset); VkResult (*render_ctx_create)( struct pvr_winsys *ws, struct pvr_winsys_render_ctx_create_info *create_info, struct pvr_winsys_render_ctx **const ctx_out); void (*render_ctx_destroy)(struct pvr_winsys_render_ctx *ctx); VkResult (*render_submit)( const struct pvr_winsys_render_ctx *ctx, const struct pvr_winsys_render_submit_info *submit_info, struct vk_sync *signal_sync_geom, struct vk_sync *signal_sync_frag); VkResult (*compute_ctx_create)( struct pvr_winsys *ws, const struct pvr_winsys_compute_ctx_create_info *create_info, struct pvr_winsys_compute_ctx **const ctx_out); void (*compute_ctx_destroy)(struct pvr_winsys_compute_ctx *ctx); VkResult (*compute_submit)( const struct pvr_winsys_compute_ctx *ctx, const struct pvr_winsys_compute_submit_info *submit_info, struct vk_sync *signal_sync); VkResult (*transfer_ctx_create)( struct pvr_winsys *ws, const struct pvr_winsys_transfer_ctx_create_info *create_info, struct pvr_winsys_transfer_ctx **const ctx_out); void (*transfer_ctx_destroy)(struct pvr_winsys_transfer_ctx *ctx); VkResult (*transfer_submit)( const struct pvr_winsys_transfer_ctx *ctx, const struct pvr_winsys_transfer_submit_info *submit_info, struct vk_sync *signal_sync); VkResult (*null_job_submit)(struct pvr_winsys *ws, struct vk_sync **waits, uint32_t wait_count, struct vk_sync *signal_sync); }; struct pvr_winsys { uint64_t page_size; uint32_t log2_page_size; const struct vk_sync_type *sync_types[2]; struct vk_sync_type syncobj_type; const struct pvr_winsys_ops *ops; }; void pvr_winsys_destroy(struct pvr_winsys *ws); struct pvr_winsys *pvr_winsys_create(int master_fd, int render_fd, const VkAllocationCallbacks *alloc); #endif /* PVR_WINSYS_H */
67aa3586640575bee6e5bf55af896844b1d8ac9b
50e95229b9a1161ac294137120aaba94c9eb06bc
/sources/ippcp/pcpdlpverifydsaca.c
6bfd7592c60d1d26cc62482c0429ce4508bb21c4
[ "Apache-2.0", "Intel" ]
permissive
intel/ipp-crypto
f0f05b87203705e82603db67bed5f8def13a5ee8
36e76e2388f3dd10cc440e213dfcf6ef59a0dfb8
refs/heads/develop
2023-09-04T08:15:06.851373
2023-07-27T12:47:12
2023-07-27T12:47:12
140,034,345
304
81
Apache-2.0
2023-08-30T17:18:36
2018-07-06T22:16:28
C
UTF-8
C
false
false
6,274
c
pcpdlpverifydsaca.c
/******************************************************************************* * Copyright (C) 2005 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions * and limitations under the License. * *******************************************************************************/ /* // // Purpose: // Cryptography Primitive. // DL over Prime Finite Field (Verify, DSA version) // // Contents: // ippsDLPVerifyDSA() // // */ #include "owndefs.h" #include "owncp.h" #include "pcpdlp.h" /*F* // Name: ippsDLPVerifyDSA // // Purpose: Verify Signature (DSA version) // // Returns: Reason: // ippStsNullPtrErr NULL == pDL // NULL == pMsgDigest // NULL == pSignR // NULL == pSignS // NULL == pResult // // ippStsContextMatchErr illegal pDL->idCtx // illegal pMsgDigest->idCtx // illegal pSignR->idCtx // illegal pSignS->idCtx // // ippStsIncompleteContextErr // incomplete context // // ippStsMessageErr MsgDigest >= R // MsgDigest < 0 // // ippStsNoErr no errors // // Parameters: // pMsgDigest pointer to the message representative to be signed // pSignR,pSignS pointer to the signature // pResult pointer to the result: IppSignIsValid/IppSignIsInvalid // pDSA pointer to the DL context // // Primitive sequence call: // 1) set up domain parameters // 2) set up (signatory's) public key *F*/ IPPFUN(IppStatus, ippsDLPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppDLResult* pResult, IppsDLPState* pDL)) { /* test context*/ IPP_BAD_PTR2_RET(pDL,pResult); IPP_BADARG_RET(!DLP_VALID_ID(pDL), ippStsContextMatchErr); /* test operation flag */ IPP_BADARG_RET(!DLP_COMPLETE(pDL), ippStsIncompleteContextErr); /* test message representative */ IPP_BAD_PTR1_RET(pMsgDigest); IPP_BADARG_RET(!BN_VALID_ID(pMsgDigest), ippStsContextMatchErr); IPP_BADARG_RET(BN_NEGATIVE(pMsgDigest), ippStsMessageErr); /* test signature */ IPP_BAD_PTR2_RET(pSignR,pSignS); IPP_BADARG_RET(!BN_VALID_ID(pSignR), ippStsContextMatchErr); IPP_BADARG_RET(!BN_VALID_ID(pSignS), ippStsContextMatchErr); /* test signature range */ if(0<cpBN_cmp(cpBN_OneRef(), pSignR)|| 0<=cpCmp_BNU(BN_NUMBER(pSignR),BN_SIZE(pSignR), DLP_R(pDL), BITS_BNU_CHUNK(DLP_BITSIZER(pDL)))) { *pResult = ippDLInvalidSignature; return ippStsNoErr; } if(0<cpBN_cmp(cpBN_OneRef(), pSignS)|| 0<=cpCmp_BNU(BN_NUMBER(pSignS),BN_SIZE(pSignS), DLP_R(pDL), BITS_BNU_CHUNK(DLP_BITSIZER(pDL)))) { *pResult = ippDLInvalidSignature; return ippStsNoErr; } { /* allocate BN resources */ BigNumNode* pList = DLP_BNCTX(pDL); IppsBigNumState* pW = cpBigNumListGet(&pList); IppsBigNumState* pU1 = cpBigNumListGet(&pList); IppsBigNumState* pU2 = cpBigNumListGet(&pList); IppsBigNumState* pOrder = cpBigNumListGet(&pList); ippsSet_BN(ippBigNumPOS, BITS2WORD32_SIZE(DLP_BITSIZER(pDL)), (Ipp32u*)DLP_R(pDL), pOrder); /* W = 1/SignS (mod R) */ ippsModInv_BN((IppsBigNumState*)pSignS, pOrder, pW); cpMontEnc_BN(pW, pW, DLP_MONTR(pDL)); /* reduct pMsgDigest if necessary */ if(0 < cpBN_cmp(pMsgDigest, pOrder)) ippsMod_BN((IppsBigNumState*)pMsgDigest, pOrder, pU1); else cpBN_copy(pU1, pMsgDigest); /* U1 = (MsgDigest*W) (mod R) */ cpMontMul_BN(pU1, pW, pU1, DLP_MONTR(pDL)); /* U2 = (SignR*W) (mod R) */ cpMontMul_BN(pU2, pSignR, pW, DLP_MONTR(pDL)); /* // V = ((G^U1)*(Y^U2) (mod P)) (mod R) */ /* precompute multi-exp table {1, G, Y, G*Y} */ { cpSize pSize = BITS_BNU_CHUNK( DLP_BITSIZEP(pDL) ); BNU_CHUNK_T* pX1 = BN_NUMBER(DLP_GENC(pDL)); BNU_CHUNK_T* pX2 = BN_NUMBER(DLP_YENC(pDL)); const BNU_CHUNK_T* ppX[2]; ppX[0] = pX1; ppX[1] = pX2; ZEXPAND_BNU(pX1, BN_SIZE(DLP_GENC(pDL)), pSize); ZEXPAND_BNU(pX2, BN_SIZE(DLP_YENC(pDL)), pSize); cpMontMultiExpInitArray(DLP_METBL(pDL), ppX, pSize*BITSIZE(BNU_CHUNK_T), 2, DLP_MONTP0(pDL)); } /* W = ((G^U1)*(Y^U2) (mod P) */ { cpSize sizeE1 = BN_SIZE(pU1); cpSize sizeE2 = BN_SIZE(pU2); cpSize sizeE = IPP_MAX(sizeE1, sizeE2); BNU_CHUNK_T* pE1 = BN_NUMBER(pU1); BNU_CHUNK_T* pE2 = BN_NUMBER(pU2); const Ipp8u* ppE[2]; ppE[0] = (Ipp8u*)pE1; ppE[1] = (Ipp8u*)pE2; ZEXPAND_BNU(pE1, sizeE1, sizeE); ZEXPAND_BNU(pE2, sizeE2, sizeE); cpFastMontMultiExp(BN_NUMBER(pW), DLP_METBL(pDL), ppE, sizeE*BITSIZE(BNU_CHUNK_T), 2, DLP_MONTP0(pDL)); BN_SIZE(pW) = BITS_BNU_CHUNK( DLP_BITSIZEP(pDL) ); BN_SIGN(pW) = ippBigNumPOS; } cpMontDec_BN(pW, pW, DLP_MONTP0(pDL)); BN_SIZE(pW) = cpMod_BNU(BN_NUMBER(pW), BN_SIZE(pW), BN_NUMBER(pOrder), BN_SIZE(pOrder)); /* result = W~R */ *pResult = 0==cpBN_cmp(pW, pSignR)? ippDLValid : ippDLInvalidSignature; return ippStsNoErr; } }
c17f0780ebe7eb5402b9dfb7dfbd3fad5ff9b69b
f82728b6f868a2275e63848f936d2c22354dc024
/Basic/Reverse A Given Number/SolutionByMashiyat.c
fef38b46843bfaa2d16388d553f3627f9ea7a650
[ "MIT" ]
permissive
shoaibrayeen/Programmers-Community
0b0fa4ba1427fa472126e640cda52dff3416b939
cd0855e604cfd54101aaa9118f01a3e3b4c48c1c
refs/heads/master
2023-03-16T03:13:48.980900
2023-03-12T00:25:37
2023-03-12T00:25:37
209,997,598
285
424
MIT
2023-03-12T00:25:38
2019-09-21T14:17:24
C++
UTF-8
C
false
false
408
c
SolutionByMashiyat.c
#include <conio.h> #include <stdio.h> int reverse(int); void main() { int number, rev_no; printf("\n Enter a number\n"); scanf("%d", &number); rev_no = reverse(number); printf("\n The reverse is: %d", rev_no); getch(); } int reverse(int n) { int rem, i, rev = 0; while (n > 0) { rem = n % 10; rev = rev * 10 + rem; n = n / 10; } return rev; }
eb5f8003107f409773258596e7aa214e6aa205a1
88ae8695987ada722184307301e221e1ba3cc2fa
/native_client/src/include/nacl_assert.h
4daf2636cf8ff009b8bf960ed33cda48a098c759
[ "BSD-3-Clause", "Zlib", "Classpath-exception-2.0", "BSD-Source-Code", "LZMA-exception", "LicenseRef-scancode-unicode", "LGPL-3.0-only", "LGPL-2.0-or-later", "LicenseRef-scancode-philippe-de-muyter", "LicenseRef-scancode-warranty-disclaimer", "LicenseRef-scancode-intel-osl-1993", "HPND-sell-variant", "ICU", "LicenseRef-scancode-protobuf", "bzip2-1.0.6", "Spencer-94", "NCSA", "LicenseRef-scancode-nilsson-historical", "CC0-1.0", "LicenseRef-scancode-proprietary-license", "LGPL-2.1-only", "LicenseRef-scancode-other-copyleft", "GPL-2.0-or-later", "NTP", "GPL-2.0-only", "LicenseRef-scancode-other-permissive", "GPL-3.0-only", "GFDL-1.1-only", "W3C", "LicenseRef-scancode-python-cwi", "GCC-exception-3.1", "BSL-1.0", "Python-2.0", "GPL-1.0-or-later", "LGPL-2.1-or-later", "LicenseRef-scancode-unknown-license-reference", "CPL-1.0", "GFDL-1.1-or-later", "W3C-19980720", "LGPL-2.0-only", "LicenseRef-scancode-amd-historical", "LicenseRef-scancode-ietf", "SAX-PD", "LicenseRef-scancode-x11-hanson", "LicenseRef-scancode-public-domain", "BSD-2-Clause", "dtoa", "MIT", "LicenseRef-scancode-public-domain-disclaimer", "PSF-2.0", "LicenseRef-scancode-newlib-historical", "LicenseRef-scancode-generic-exception", "SMLNJ", "HP-1986", "LicenseRef-scancode-free-unknown", "SunPro", "MPL-1.1" ]
permissive
iridium-browser/iridium-browser
71d9c5ff76e014e6900b825f67389ab0ccd01329
5ee297f53dc7f8e70183031cff62f37b0f19d25f
refs/heads/master
2023-08-03T16:44:16.844552
2023-07-20T15:17:00
2023-07-23T16:09:30
220,016,632
341
40
BSD-3-Clause
2021-08-13T13:54:45
2019-11-06T14:32:31
null
UTF-8
C
false
false
4,505
h
nacl_assert.h
/* * Copyright 2010 The Native Client Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ /* * NaCl service runtime, assertion macros. * * THIS FILE SHOULD BE USED ONLY IN TEST CODE. */ #ifndef NATIVE_CLIENT_SRC_INCLUDE_NACL_ASSERT_H_ #define NATIVE_CLIENT_SRC_INCLUDE_NACL_ASSERT_H_ #include <stdio.h> #include "native_client/src/include/portability.h" /* get NACL_PRIxPTR */ /* * Instead of using <assert.h>, we define a version that works with * our testing framework, printing out FAIL / SUCCESS to standard * output and then exiting with a non-zero exit status. */ #define ASSERT(bool_expr) do { \ if (!(bool_expr)) { \ fprintf(stderr, \ "Error at line %d, %s: " #bool_expr " is FALSE\n", \ __LINE__, __FILE__); \ printf("FAIL\n"); \ exit(1); \ } \ } while (0) #define ASSERT_MSG(bool_expr, msg) do { \ if (!(bool_expr)) { \ fprintf(stderr, \ "Error at line %d, %s: " #bool_expr " is FALSE\n", \ __LINE__, __FILE__); \ fprintf(stderr, "%s\n", msg); \ printf("FAIL\n"); \ exit(1); \ } \ } while (0) static INLINE void NaClAssertOpFailMessage(uintptr_t lhs, uintptr_t rhs, const char *lhs_expr, const char *rhs_expr, const char *comparison_op, int source_line, const char *source_file) { fprintf(stderr, "Error at line %d, %s:\n" "Error: %s %s %s is FALSE\n", source_line, source_file, lhs_expr, comparison_op, rhs_expr); fprintf(stderr, "got 0x%08" NACL_PRIxPTR " (%" NACL_PRIdPTR "); " "comparison value 0x%08" NACL_PRIxPTR " (%" NACL_PRIdPTR ")\n", lhs, lhs, rhs, rhs); } #define ASSERT_OP_THUNK(lhs, op, rhs, slhs, srhs, thunk) do { \ if (!((lhs) op (rhs))) { \ NaClAssertOpFailMessage((uintptr_t) (lhs), (uintptr_t) (rhs), \ slhs, srhs, #op, __LINE__, __FILE__); \ thunk; \ printf("FAIL\n"); \ exit(1); \ } \ } while (0) #define ASSERT_OP_MSG(lhs, op, rhs, slhs, srhs, msg) \ ASSERT_OP_THUNK(lhs, op, rhs, \ slhs, srhs, do { fprintf(stderr, "%s\n", msg); } while (0)) #define ASSERT_EQ_MSG(lhs, rhs, msg) \ ASSERT_OP_MSG(lhs, ==, rhs, #lhs, #rhs, msg) #define ASSERT_NE_MSG(lhs, rhs, msg) \ ASSERT_OP_MSG(lhs, !=, rhs, #lhs, #rhs, msg) #define ASSERT_LE_MSG(lhs, rhs, msg) \ ASSERT_OP_MSG(lhs, <=, rhs, #lhs, #rhs, msg) #define ASSERT_OP(lhs, op, rhs, slhs, srhs) \ ASSERT_OP_THUNK(lhs, op, rhs, slhs, srhs, do { ; } while (0)) #define ASSERT_EQ(lhs, rhs) ASSERT_OP(lhs, ==, rhs, #lhs, #rhs) #define ASSERT_NE(lhs, rhs) ASSERT_OP(lhs, !=, rhs, #lhs, #rhs) #define ASSERT_LE(lhs, rhs) ASSERT_OP(lhs, <=, rhs, #lhs, #rhs) #define ASSERT_GE(lhs, rhs) ASSERT_OP(lhs, >=, rhs, #lhs, #rhs) #define ASSERT_LT(lhs, rhs) ASSERT_OP(lhs, <, rhs, #lhs, #rhs) #define ASSERT_GT(lhs, rhs) ASSERT_OP(lhs, >, rhs, #lhs, #rhs) #endif /* NATIVE_CLIENT_SRC_INCLUDE_NACL_ASSERT_H_ */
819dd9be551a1107a8b97760b1fae73f175bbb19
fdbb74a95924e2677466614f6ab6e2bb13b2a95a
/net/http/foldheader.c
bd010dff420da84b3cb23d48cef3a1892b294d93
[ "ISC" ]
permissive
jart/cosmopolitan
fb11b5658939023977060a7c6c71a74093d9cb44
0d748ad58e1063dd1f8560f18a0c75293b9415b7
refs/heads/master
2023-09-06T09:17:29.303607
2023-09-02T03:49:13
2023-09-02T03:50:18
272,457,606
11,887
435
ISC
2023-09-14T17:47:58
2020-06-15T14:16:13
C
UTF-8
C
false
false
2,661
c
foldheader.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "net/http/http.h" /** * Collapses repeating headers onto a single line. */ char *FoldHeader(struct HttpMessage *msg, const char *b, int h, size_t *z) { char *p, *p2; size_t i, n, m; struct HttpHeader *x; n = msg->headers[h].b - msg->headers[h].a; if ((p = malloc(n))) { memcpy(p, b + msg->headers[h].a, n); for (i = 0; i < msg->xheaders.n; ++i) { x = msg->xheaders.p + i; if (GetHttpHeader(b + x->k.a, x->k.b - x->k.a) == h) { m = x->v.b - x->v.a; if ((p2 = realloc(p, n + 2 + m))) { memcpy(mempcpy((p = p2) + n, ", ", 2), b + x->v.a, m); n += 2 + m; } else { free(p); return 0; } } } *z = n; } return p; }
79c369f5a16466e6854f51424a7f3276d6350320
c39862dcbc5b9ad65f582752bcfd0c5eb9be463e
/dev/src/xenon_decompiler/lzx.h
212d02e9427719765956e90392c30862c8cc7148
[ "MIT" ]
permissive
rexdex/recompiler
5f1138adf5d02a052c8b37c290296d5cf5faadc2
7cd1d5a33d6c02a13f972c6564550ea816fc8b5b
refs/heads/master
2023-08-16T16:24:37.810517
2022-02-12T21:20:21
2022-02-12T21:20:21
81,953,901
1,714
120
MIT
2022-02-12T21:20:22
2017-02-14T14:32:17
C++
UTF-8
C
false
false
7,422
h
lzx.h
/* This file is part of libmspack. * (C) 2003-2004 Stuart Caie. * * The LZX method was created by Jonathan Forbes and Tomi Poutanen, adapted * by Microsoft Corporation. * * libmspack is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License (LGPL) version 2.1 * * For further details, see the file COPYING.LIB distributed with libmspack */ #ifndef MSPACK_LZX_H #define MSPACK_LZX_H 1 /* LZX compression / decompression definitions */ /* some constants defined by the LZX specification */ #define LZX_MIN_MATCH (2) #define LZX_MAX_MATCH (257) #define LZX_NUM_CHARS (256) #define LZX_BLOCKTYPE_INVALID (0) /* also blocktypes 4-7 invalid */ #define LZX_BLOCKTYPE_VERBATIM (1) #define LZX_BLOCKTYPE_ALIGNED (2) #define LZX_BLOCKTYPE_UNCOMPRESSED (3) #define LZX_PRETREE_NUM_ELEMENTS (20) #define LZX_ALIGNED_NUM_ELEMENTS (8) /* aligned offset tree #elements */ #define LZX_NUM_PRIMARY_LENGTHS (7) /* this one missing from spec! */ #define LZX_NUM_SECONDARY_LENGTHS (249) /* length tree #elements */ /* LZX huffman defines: tweak tablebits as desired */ #define LZX_PRETREE_MAXSYMBOLS (LZX_PRETREE_NUM_ELEMENTS) #define LZX_PRETREE_TABLEBITS (6) #define LZX_MAINTREE_MAXSYMBOLS (LZX_NUM_CHARS + 50*8) #define LZX_MAINTREE_TABLEBITS (12) #define LZX_LENGTH_MAXSYMBOLS (LZX_NUM_SECONDARY_LENGTHS+1) #define LZX_LENGTH_TABLEBITS (12) #define LZX_ALIGNED_MAXSYMBOLS (LZX_ALIGNED_NUM_ELEMENTS) #define LZX_ALIGNED_TABLEBITS (7) #define LZX_LENTABLE_SAFETY (64) /* table decoding overruns are allowed */ #define LZX_FRAME_SIZE (32768) /* the size of a frame in LZX */ struct lzxd_stream { struct mspack_system *sys; /* I/O routines */ struct mspack_file *input; /* input file handle */ struct mspack_file *output; /* output file handle */ off_t offset; /* number of bytes actually output */ off_t length; /* overall decompressed length of stream */ unsigned char *window; /* decoding window */ unsigned int window_size; /* window size */ unsigned int window_posn; /* decompression offset within window */ unsigned int frame_posn; /* current frame offset within in window */ unsigned int frame; /* the number of 32kb frames processed */ unsigned int reset_interval; /* which frame do we reset the compressor? */ unsigned int R0, R1, R2; /* for the LRU offset system */ unsigned int block_length; /* uncompressed length of this LZX block */ unsigned int block_remaining; /* uncompressed bytes still left to decode */ signed int intel_filesize; /* magic header value used for transform */ signed int intel_curpos; /* current offset in transform space */ unsigned char intel_started; /* has intel E8 decoding started? */ unsigned char block_type; /* type of the current block */ unsigned char header_read; /* have we started decoding at all yet? */ unsigned char posn_slots; /* how many posn slots in stream? */ unsigned char input_end; /* have we reached the end of input? */ int error; /* I/O buffering */ unsigned char *inbuf, *i_ptr, *i_end, *o_ptr, *o_end; unsigned int bit_buffer, bits_left, inbuf_size; /* huffman code lengths */ unsigned char PRETREE_len [LZX_PRETREE_MAXSYMBOLS + LZX_LENTABLE_SAFETY]; unsigned char MAINTREE_len [LZX_MAINTREE_MAXSYMBOLS + LZX_LENTABLE_SAFETY]; unsigned char LENGTH_len [LZX_LENGTH_MAXSYMBOLS + LZX_LENTABLE_SAFETY]; unsigned char ALIGNED_len [LZX_ALIGNED_MAXSYMBOLS + LZX_LENTABLE_SAFETY]; /* huffman decoding tables */ unsigned short PRETREE_table [(1 << LZX_PRETREE_TABLEBITS) + (LZX_PRETREE_MAXSYMBOLS * 2)]; unsigned short MAINTREE_table[(1 << LZX_MAINTREE_TABLEBITS) + (LZX_MAINTREE_MAXSYMBOLS * 2)]; unsigned short LENGTH_table [(1 << LZX_LENGTH_TABLEBITS) + (LZX_LENGTH_MAXSYMBOLS * 2)]; unsigned short ALIGNED_table [(1 << LZX_ALIGNED_TABLEBITS) + (LZX_ALIGNED_MAXSYMBOLS * 2)]; /* this is used purely for doing the intel E8 transform */ unsigned char e8_buf[LZX_FRAME_SIZE]; }; /* allocates LZX decompression state for decoding the given stream. * * - returns NULL if window_bits is outwith the range 15 to 21 (inclusive). * * - uses system->alloc() to allocate memory * * - returns NULL if not enough memory * * - window_bits is the size of the LZX window, from 32Kb (15) to 2Mb (21). * * - reset_interval is how often the bitstream is reset, measured in * multiples of 32Kb bytes output. For CAB LZX streams, this is always 0 * (does not occur). * * - input_buffer_size is how many bytes to use as an input bitstream buffer * * - output_length is the length in bytes of the entirely decompressed * output stream, if known in advance. It is used to correctly perform * the Intel E8 transformation, which must stop 6 bytes before the very * end of the decompressed stream. It is not otherwise used or adhered * to. If the full decompressed length is known in advance, set it here. * If it is NOT known, use the value 0, and call lzxd_set_output_length() * once it is known. If never set, 4 of the final 6 bytes of the output * stream may be incorrect. */ extern struct lzxd_stream *lzxd_init(struct mspack_system *system, struct mspack_file *input, struct mspack_file *output, int window_bits, int reset_interval, int input_buffer_size, off_t output_length); /* see description of output_length in lzxd_init() */ extern void lzxd_set_output_length(struct lzxd_stream *lzx, off_t output_length); /* decompresses, or decompresses more of, an LZX stream. * * - out_bytes of data will be decompressed and the function will return * with an MSPACK_ERR_OK return code. * * - decompressing will stop as soon as out_bytes is reached. if the true * amount of bytes decoded spills over that amount, they will be kept for * a later invocation of lzxd_decompress(). * * - the output bytes will be passed to the system->write() function given in * lzxd_init(), using the output file handle given in lzxd_init(). More * than one call may be made to system->write(). * * - LZX will read input bytes as necessary using the system->read() function * given in lzxd_init(), using the input file handle given in lzxd_init(). * This will continue until system->read() returns 0 bytes, or an error. * input streams should convey an "end of input stream" by refusing to * supply all the bytes that LZX asks for when they reach the end of the * stream, rather than return an error code. * * - if an error code other than MSPACK_ERR_OK is returned, the stream should * be considered unusable and lzxd_decompress() should not be called again * on this stream. */ extern int lzxd_decompress(struct lzxd_stream *lzx, off_t out_bytes); /* frees all state associated with an LZX data stream * * - calls system->free() using the system pointer given in lzxd_init() */ void lzxd_free(struct lzxd_stream *lzx); #endif
199ba0b6a6c5f83cf0ae13f3f85841d7eab7dba5
e73547787354afd9b717ea57fe8dd0695d161821
/src/world/dead/area_flo/flo_15/flo_15_0_header.c
002e99fae7dd2896ab72a31473d447b96d0a12d5
[]
no_license
pmret/papermario
8b514b19653cef8d6145e47499b3636b8c474a37
9774b26d93f1045dd2a67e502b6efc9599fb6c31
refs/heads/main
2023-08-31T07:09:48.951514
2023-08-21T18:07:08
2023-08-21T18:07:08
287,151,133
904
139
null
2023-09-14T02:44:23
2020-08-13T01:22:57
C
UTF-8
C
false
false
383
c
flo_15_0_header.c
#include "flo_15.h" EntryList N(Entrances) = { [flo_15_ENTRY_0] { 320.0, 0.0, 0.0, 270.0 }, [flo_15_ENTRY_1] { -170.0, 0.0, 55.0, 0.0 }, }; MapSettings N(settings) = { .main = &N(EVS_Main), .entryList = &N(Entrances), .entryCount = ENTRY_COUNT(N(Entrances)), .background = &gBackgroundImage, .tattle = { MSG_MapTattle_flo_15 }, };
fe33d8dca4a282e50a79fe623f74450014bca3a6
030d0641553fe32c41dc302cd191dd63466a4eb9
/plugins/modprobe.c
16f08dc7ca7e1ed64ae90f514e17840635b4f645
[ "MIT" ]
permissive
troglobit/finit
0e03c0a37af5568baab2484b5203ff104dbaa4af
a58002588eb30b5ac595a0d6f8902f4abffc1b5c
refs/heads/master
2023-08-03T04:18:53.053351
2023-07-30T07:56:30
2023-07-30T08:09:34
5,778,132
605
69
MIT
2023-02-06T15:13:14
2012-09-12T10:07:53
C
UTF-8
C
false
false
4,957
c
modprobe.c
/* Coldplug modules using modalias magic * * Copyright (c) 2021-2023 Joachim Wiberg <troglobit@gmail.com> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ /* * Cold plug magic taken from Buildroot * https://github.com/buildroot/buildroot/commit/b4fc5a180c81689a982d5c595844331684c14f51 * * The plugin basically does this, only in C: * * system("find /sys/devices -name modalias -print0" * " | xargs -0 sort -u -z" * " | xargs -0 modprobe -abq"); * * Note: BusyBox must *not* be built with CONFIG_MODPROBE_SMALL */ #include <fnmatch.h> #include <ftw.h> #include <unistd.h> #include <sys/stat.h> #include <sys/time.h> /* gettimeofday() */ #include <sys/types.h> #ifdef _LIBITE_LITE # include <libite/lite.h> #else # include <lite/lite.h> #endif #include "config.h" #include "finit.h" #include "util.h" #include "plugin.h" struct module { TAILQ_ENTRY(module) link; char *alias; }; static TAILQ_HEAD(, module) modules = TAILQ_HEAD_INITIALIZER(modules); static int modprobe(char *alias) { char *args[] = { "modprobe", "-abq", alias, NULL, }; pid_t pid; pid = fork(); switch (pid) { case -1: err(1, "Failed forking modprobe child"); return 1; case 0: execvp(args[0], args); break; default: if (!complete(args[0], pid)) dbg("Successful modprobe of %s", alias); break; } return 0; } static void alias_add(char *alias) { struct module *m; m = malloc(sizeof(*m)); if (!m) return; m->alias = strdup(alias); if (!m->alias) { free(m); return; } TAILQ_INSERT_TAIL(&modules, m, link); } static void alias_remove(struct module *m) { TAILQ_REMOVE(&modules, m, link); free(m->alias); free(m); } static int alias_exist(char *alias) { struct module *m; TAILQ_FOREACH(m, &modules, link) { if (!strcmp(m->alias, alias)) return 1; } return 0; } static void alias_add_uniq(char *alias) { if (alias_exist(alias)) return; alias_add(alias); } static FILE *maybe_fopen_alias(const char *file, const char *path) { const char *basename; basename = rindex(path, '/'); if (!basename) return NULL; basename++; if (strcmp(file, basename)) return NULL; return fopen(path, "r"); } static int scan_modalias(const char *path) { char buf[256]; FILE *fp; fp = maybe_fopen_alias("modalias", path); if (!fp) return 1; if (fgets(buf, sizeof(buf), fp)) { chomp(buf); alias_add_uniq(buf); } fclose(fp); return 0; } static int scan_uevent(const char *path) { char buf[256]; FILE *fp; fp = maybe_fopen_alias("uevent", path); if (!fp) return 1; while (fgets(buf, sizeof(buf), fp)) { if (strstr(buf, "MODALIAS=") != buf) continue; chomp(buf); alias_add_uniq(buf + strlen("MODALIAS=")); break; } fclose(fp); return 0; } static int scan_alias(const char *path, const struct stat *st, int flag, struct FTW *unused) { /* Sanity check: is this a regular file we can read? */ if (!(S_ISREG(st->st_mode) && (st->st_mode & S_IRUSR))) return 0; if (!scan_uevent(path)) return 0; scan_modalias(path); return 0; } static void coldplug(void *arg) { struct module *m, *tmp; int rc = 0; /* Skip for systems without modules, e.g. small embedded or containers */ if (!fisdir("/lib/modules")) return; if (!fismnt("/sys")) { print(1, "Cannot modprobe system, /sys is not mounted"); return; } print_desc("Cold plugging system", NULL); rc = nftw("/sys/devices", scan_alias, 200, FTW_DEPTH | FTW_PHYS); if (!rc) { TAILQ_FOREACH_SAFE(m, &modules, link, tmp) { rc += modprobe(m->alias); alias_remove(m); } } print_result(rc); } static plugin_t plugin = { .name = __FILE__, .hook[HOOK_BASEFS_UP] = { .cb = coldplug }, .depends = { "bootmisc", } }; PLUGIN_INIT(plugin_init) { plugin_register(&plugin); } PLUGIN_EXIT(plugin_exit) { plugin_unregister(&plugin); } /** * Local Variables: * indent-tabs-mode: t * c-file-style: "linux" * End: */
5a2a2800adedd8cd712dd967de2128c31f9cc8d0
5816ae8b5fdfe9ab93b3653742b5d4c2a1567111
/hitcon-2018/abyss/src/kernel/syscalls/syscall_handler.h
6e1cb8efbec0249797f08d4ee919a650c195aed9
[]
no_license
david942j/ctf-writeups
6c2ff633d80809e422f0263b8ac9a69607d31e84
a4d086684a939000286d0876dd29463ccdceea2e
refs/heads/master
2022-09-07T00:27:23.594820
2021-12-14T10:50:47
2021-12-14T10:50:47
77,058,219
316
49
null
null
null
null
UTF-8
C
false
false
985
h
syscall_handler.h
#ifndef SYSCALL_HANDLER_H #define SYSCALL_HANDLER_H #include <stdint.h> #include <syscalls/sys_brk.h> #include <syscalls/sys_close.h> #include <syscalls/sys_execve.h> #include <syscalls/sys_exit.h> #include <syscalls/sys_mmap.h> #include <syscalls/sys_open.h> #include <syscalls/sys_prctl.h> #include <syscalls/sys_read.h> #include <syscalls/sys_stat.h> #include <syscalls/sys_write.h> #define SYS_read 0 #define SYS_write 1 #define SYS_open 2 #define SYS_close 3 #define SYS_fstat 5 #define SYS_mmap 9 #define SYS_mprotect 10 #define SYS_munmap 11 #define SYS_brk 12 #define SYS_writev 20 #define SYS_access 21 #define SYS_execve 59 #define SYS_exit 60 #define SYS_arch_prctl 158 #define SYS_fadvise64 221 #define SYS_exit_group 231 #define SYS_openat 257 #define MAX_SYS_NR 257 static int ZERO(void) { return 0; } /* nop */ #define sys_fadvise64 ZERO uint64_t syscall_handler(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5); #endif
f8248b9bbe6bc407f6ba05bca4d080215c298e62
7f6c235b0598353549959c18f69eefd20b766907
/libsrc/target/cpm/graphics/drawto.c
a893bff83d16a4a504c9a89d22ce4fdd32d92c3a
[ "ClArtistic" ]
permissive
z88dk/z88dk
46dfd4905f36d99333173cadd0a660839befc9f0
8b07f37cc43c5d9ffe69b563c80763491d8faff7
refs/heads/master
2023-09-04T19:29:49.254958
2023-09-03T20:51:24
2023-09-03T20:51:24
54,035,569
820
263
NOASSERTION
2023-09-05T11:09:04
2016-03-16T13:48:16
Assembly
UTF-8
C
false
false
402
c
drawto.c
/* * CP/M GSX based graphics libraries * * drawto(x,y) * * Stefano Bodrato - March 2021 * * $Id: drawto.c $ */ #include <cpm.h> //#include <graphics.h> extern void __LIB__ drawto(int x2, int y2) __smallc; extern int __LIB__ gsx_xscale(int x) __z88dk_fastcall; extern int __LIB__ gsx_yscale(int y) __z88dk_fastcall; void drawto(int x,int y) { gios_drawto(gsx_xscale(x),gsx_yscale(y)); }
836bcd4b29db9d9f99e01b6c3cd8f285afc7a372
b1fcecfa2d9b42db62ba22f4635b3e845bf4ab56
/nginx/src/http/v2/ngx_http_v2.h
42333e47f6987564dba39fc7fbceaf815b7dd6a5
[ "BSD-2-Clause" ]
permissive
chronolaw/annotated_nginx
606b5ae08b8173daa01fcac353b089b17deff08d
60b0e2a15d4c7c51313bd117bab026046c3da01b
refs/heads/master
2023-06-29T09:15:23.066046
2023-06-17T08:35:25
2023-06-17T08:35:25
51,183,743
573
206
null
null
null
null
UTF-8
C
false
false
14,016
h
ngx_http_v2.h
// annotated by chrono since 2016 // // * NGX_HTTP_V2_DATA_FRAME // * NGX_HTTP_V2_AUTHORITY_INDEX /* * Copyright (C) Nginx, Inc. * Copyright (C) Valentin V. Bartenev */ #ifndef _NGX_HTTP_V2_H_INCLUDED_ #define _NGX_HTTP_V2_H_INCLUDED_ #include <ngx_config.h> #include <ngx_core.h> #include <ngx_http.h> // 旧的npn标志,同alpn //#define NGX_HTTP_V2_NPN_ADVERTISE NGX_HTTP_V2_ALPN_ADVERTISE // 在tls的alpn扩展里识别http2 // 第一个0x02是长度 #define NGX_HTTP_V2_ALPN_PROTO "\x02h2" #define NGX_HTTP_V2_STATE_BUFFER_SIZE 16 // 默认帧大小, 2^14 #define NGX_HTTP_V2_DEFAULT_FRAME_SIZE (1 << 14) // 最大帧, 2^24,即头部的三个字节 #define NGX_HTTP_V2_MAX_FRAME_SIZE ((1 << 24) - 1) // hpack头部压缩 #define NGX_HTTP_V2_INT_OCTETS 4 #define NGX_HTTP_V2_MAX_FIELD \ (127 + (1 << (NGX_HTTP_V2_INT_OCTETS - 1) * 7) - 1) // 帧头大小,9字节 #define NGX_HTTP_V2_FRAME_HEADER_SIZE 9 // 3字节长度后是1字节类型 // 定义的各种帧类型 /* frame types */ #define NGX_HTTP_V2_DATA_FRAME 0x0 #define NGX_HTTP_V2_HEADERS_FRAME 0x1 #define NGX_HTTP_V2_PRIORITY_FRAME 0x2 #define NGX_HTTP_V2_RST_STREAM_FRAME 0x3 #define NGX_HTTP_V2_SETTINGS_FRAME 0x4 #define NGX_HTTP_V2_PUSH_PROMISE_FRAME 0x5 #define NGX_HTTP_V2_PING_FRAME 0x6 #define NGX_HTTP_V2_GOAWAY_FRAME 0x7 #define NGX_HTTP_V2_WINDOW_UPDATE_FRAME 0x8 #define NGX_HTTP_V2_CONTINUATION_FRAME 0x9 // 类型后是1字节标志位 /* frame flags */ #define NGX_HTTP_V2_NO_FLAG 0x00 #define NGX_HTTP_V2_ACK_FLAG 0x01 #define NGX_HTTP_V2_END_STREAM_FLAG 0x01 #define NGX_HTTP_V2_END_HEADERS_FLAG 0x04 #define NGX_HTTP_V2_PADDED_FLAG 0x08 #define NGX_HTTP_V2_PRIORITY_FLAG 0x20 // 流量窗口 #define NGX_HTTP_V2_MAX_WINDOW ((1U << 31) - 1) #define NGX_HTTP_V2_DEFAULT_WINDOW 65535 #define NGX_HTTP_V2_DEFAULT_WEIGHT 16 typedef struct ngx_http_v2_connection_s ngx_http_v2_connection_t; typedef struct ngx_http_v2_node_s ngx_http_v2_node_t; typedef struct ngx_http_v2_out_frame_s ngx_http_v2_out_frame_t; typedef u_char *(*ngx_http_v2_handler_pt) (ngx_http_v2_connection_t *h2c, u_char *pos, u_char *end); typedef struct { ngx_flag_t enable; size_t pool_size; ngx_uint_t concurrent_streams; size_t preread_size; ngx_uint_t streams_index_mask; } ngx_http_v2_srv_conf_t; typedef struct { ngx_str_t name; ngx_str_t value; } ngx_http_v2_header_t; typedef struct { ngx_uint_t sid; size_t length; size_t padding; unsigned flags:8; unsigned incomplete:1; unsigned keep_pool:1; /* HPACK */ unsigned parse_name:1; unsigned parse_value:1; unsigned index:1; ngx_http_v2_header_t header; size_t header_limit; u_char field_state; u_char *field_start; u_char *field_end; size_t field_rest; ngx_pool_t *pool; ngx_http_v2_stream_t *stream; u_char buffer[NGX_HTTP_V2_STATE_BUFFER_SIZE]; size_t buffer_used; ngx_http_v2_handler_pt handler; } ngx_http_v2_state_t; // 头部压缩 typedef struct { ngx_http_v2_header_t **entries; ngx_uint_t added; ngx_uint_t deleted; ngx_uint_t reused; ngx_uint_t allocated; size_t size; size_t free; u_char *storage; u_char *pos; } ngx_http_v2_hpack_t; // 连接状态 struct ngx_http_v2_connection_s { ngx_connection_t *connection; ngx_http_connection_t *http_connection; off_t total_bytes; off_t payload_bytes; ngx_uint_t processing; ngx_uint_t frames; ngx_uint_t idle; ngx_uint_t priority_limit; size_t send_window; size_t recv_window; size_t init_window; size_t frame_size; ngx_queue_t waiting; ngx_http_v2_state_t state; ngx_http_v2_hpack_t hpack; ngx_pool_t *pool; ngx_http_v2_out_frame_t *free_frames; ngx_connection_t *free_fake_connections; ngx_http_v2_node_t **streams_index; ngx_http_v2_out_frame_t *last_out; ngx_queue_t dependencies; ngx_queue_t closed; ngx_uint_t closed_nodes; ngx_uint_t last_sid; time_t lingering_time; unsigned settings_ack:1; unsigned table_update:1; unsigned blocked:1; unsigned goaway:1; }; struct ngx_http_v2_node_s { ngx_uint_t id; ngx_http_v2_node_t *index; ngx_http_v2_node_t *parent; ngx_queue_t queue; ngx_queue_t children; ngx_queue_t reuse; ngx_uint_t rank; ngx_uint_t weight; double rel_weight; ngx_http_v2_stream_t *stream; }; // http2流 struct ngx_http_v2_stream_s { ngx_http_request_t *request; ngx_http_v2_connection_t *connection; ngx_http_v2_node_t *node; ngx_uint_t queued; /* * A change to SETTINGS_INITIAL_WINDOW_SIZE could cause the * send_window to become negative, hence it's signed. */ ssize_t send_window; size_t recv_window; ngx_buf_t *preread; ngx_uint_t frames; ngx_http_v2_out_frame_t *free_frames; ngx_chain_t *free_frame_headers; ngx_chain_t *free_bufs; ngx_queue_t queue; ngx_array_t *cookies; ngx_pool_t *pool; unsigned waiting:1; unsigned blocked:1; unsigned exhausted:1; unsigned in_closed:1; unsigned out_closed:1; unsigned rst_sent:1; unsigned no_flow_control:1; unsigned skip_data:1; }; struct ngx_http_v2_out_frame_s { ngx_http_v2_out_frame_t *next; ngx_chain_t *first; ngx_chain_t *last; ngx_int_t (*handler)(ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *frame); ngx_http_v2_stream_t *stream; size_t length; unsigned blocked:1; unsigned fin:1; }; static ngx_inline void ngx_http_v2_queue_frame(ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *frame) { ngx_http_v2_out_frame_t **out; for (out = &h2c->last_out; *out; out = &(*out)->next) { if ((*out)->blocked || (*out)->stream == NULL) { break; } if ((*out)->stream->node->rank < frame->stream->node->rank || ((*out)->stream->node->rank == frame->stream->node->rank && (*out)->stream->node->rel_weight >= frame->stream->node->rel_weight)) { break; } } frame->next = *out; *out = frame; } static ngx_inline void ngx_http_v2_queue_blocked_frame(ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *frame) { ngx_http_v2_out_frame_t **out; for (out = &h2c->last_out; *out; out = &(*out)->next) { if ((*out)->blocked || (*out)->stream == NULL) { break; } } frame->next = *out; *out = frame; } static ngx_inline void ngx_http_v2_queue_ordered_frame(ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *frame) { frame->next = h2c->last_out; h2c->last_out = frame; } void ngx_http_v2_init(ngx_event_t *rev); ngx_int_t ngx_http_v2_read_request_body(ngx_http_request_t *r); ngx_int_t ngx_http_v2_read_unbuffered_request_body(ngx_http_request_t *r); void ngx_http_v2_close_stream(ngx_http_v2_stream_t *stream, ngx_int_t rc); ngx_int_t ngx_http_v2_send_output_queue(ngx_http_v2_connection_t *h2c); ngx_str_t *ngx_http_v2_get_static_name(ngx_uint_t index); ngx_str_t *ngx_http_v2_get_static_value(ngx_uint_t index); ngx_int_t ngx_http_v2_get_indexed_header(ngx_http_v2_connection_t *h2c, ngx_uint_t index, ngx_uint_t name_only); ngx_int_t ngx_http_v2_add_header(ngx_http_v2_connection_t *h2c, ngx_http_v2_header_t *header); ngx_int_t ngx_http_v2_table_size(ngx_http_v2_connection_t *h2c, size_t size); #define ngx_http_v2_prefix(bits) ((1 << (bits)) - 1) #if (NGX_HAVE_NONALIGNED) #define ngx_http_v2_parse_uint16(p) ntohs(*(uint16_t *) (p)) #define ngx_http_v2_parse_uint32(p) ntohl(*(uint32_t *) (p)) #else #define ngx_http_v2_parse_uint16(p) ((p)[0] << 8 | (p)[1]) #define ngx_http_v2_parse_uint32(p) \ ((uint32_t) (p)[0] << 24 | (p)[1] << 16 | (p)[2] << 8 | (p)[3]) #endif #define ngx_http_v2_parse_length(p) ((p) >> 8) #define ngx_http_v2_parse_type(p) ((p) & 0xff) #define ngx_http_v2_parse_sid(p) (ngx_http_v2_parse_uint32(p) & 0x7fffffff) #define ngx_http_v2_parse_window(p) (ngx_http_v2_parse_uint32(p) & 0x7fffffff) #define ngx_http_v2_write_uint16_aligned(p, s) \ (*(uint16_t *) (p) = htons((uint16_t) (s)), (p) + sizeof(uint16_t)) #define ngx_http_v2_write_uint32_aligned(p, s) \ (*(uint32_t *) (p) = htonl((uint32_t) (s)), (p) + sizeof(uint32_t)) #if (NGX_HAVE_NONALIGNED) #define ngx_http_v2_write_uint16 ngx_http_v2_write_uint16_aligned #define ngx_http_v2_write_uint32 ngx_http_v2_write_uint32_aligned #else #define ngx_http_v2_write_uint16(p, s) \ ((p)[0] = (u_char) ((s) >> 8), \ (p)[1] = (u_char) (s), \ (p) + sizeof(uint16_t)) #define ngx_http_v2_write_uint32(p, s) \ ((p)[0] = (u_char) ((s) >> 24), \ (p)[1] = (u_char) ((s) >> 16), \ (p)[2] = (u_char) ((s) >> 8), \ (p)[3] = (u_char) (s), \ (p) + sizeof(uint32_t)) #endif #define ngx_http_v2_write_len_and_type(p, l, t) \ ngx_http_v2_write_uint32_aligned(p, (l) << 8 | (t)) #define ngx_http_v2_write_sid ngx_http_v2_write_uint32 #define ngx_http_v2_indexed(i) (128 + (i)) #define ngx_http_v2_inc_indexed(i) (64 + (i)) #define ngx_http_v2_write_name(dst, src, len, tmp) \ ngx_http_v2_string_encode(dst, src, len, tmp, 1) #define ngx_http_v2_write_value(dst, src, len, tmp) \ ngx_http_v2_string_encode(dst, src, len, tmp, 0) #define NGX_HTTP_V2_ENCODE_RAW 0 #define NGX_HTTP_V2_ENCODE_HUFF 0x80 // hpack字典索引值 #define NGX_HTTP_V2_AUTHORITY_INDEX 1 #define NGX_HTTP_V2_METHOD_INDEX 2 #define NGX_HTTP_V2_METHOD_GET_INDEX 2 #define NGX_HTTP_V2_METHOD_POST_INDEX 3 #define NGX_HTTP_V2_PATH_INDEX 4 #define NGX_HTTP_V2_PATH_ROOT_INDEX 4 #define NGX_HTTP_V2_SCHEME_HTTP_INDEX 6 #define NGX_HTTP_V2_SCHEME_HTTPS_INDEX 7 #define NGX_HTTP_V2_STATUS_INDEX 8 #define NGX_HTTP_V2_STATUS_200_INDEX 8 #define NGX_HTTP_V2_STATUS_204_INDEX 9 #define NGX_HTTP_V2_STATUS_206_INDEX 10 #define NGX_HTTP_V2_STATUS_304_INDEX 11 #define NGX_HTTP_V2_STATUS_400_INDEX 12 #define NGX_HTTP_V2_STATUS_404_INDEX 13 #define NGX_HTTP_V2_STATUS_500_INDEX 14 #define NGX_HTTP_V2_CONTENT_LENGTH_INDEX 28 #define NGX_HTTP_V2_CONTENT_TYPE_INDEX 31 #define NGX_HTTP_V2_DATE_INDEX 33 #define NGX_HTTP_V2_LAST_MODIFIED_INDEX 44 #define NGX_HTTP_V2_LOCATION_INDEX 46 #define NGX_HTTP_V2_SERVER_INDEX 54 #define NGX_HTTP_V2_VARY_INDEX 59 #define NGX_HTTP_V2_PREFACE_START "PRI * HTTP/2.0\r\n" #define NGX_HTTP_V2_PREFACE_END "\r\nSM\r\n\r\n" #define NGX_HTTP_V2_PREFACE NGX_HTTP_V2_PREFACE_START \ NGX_HTTP_V2_PREFACE_END u_char *ngx_http_v2_string_encode(u_char *dst, u_char *src, size_t len, u_char *tmp, ngx_uint_t lower); extern ngx_module_t ngx_http_v2_module; #endif /* _NGX_HTTP_V2_H_INCLUDED_ */
299dfe6806f98bd622e406820526caa9f0f318be
9907672fcd81ab73ac63b2a83422a82bf31eadde
/atcoder/abs/9.c
620af504327152d3fa082b5526b1c27a3ac2fb35
[ "0BSD" ]
permissive
cielavenir/procon
bbe1974b9bddb51b76d58722a0686a5b477c4456
746e1a91f574f20647e8aaaac0d9e6173f741176
refs/heads/master
2023-06-21T23:11:24.562546
2023-06-11T13:15:15
2023-06-11T13:15:15
7,557,464
137
136
null
2020-10-20T09:35:52
2013-01-11T09:40:26
C++
UTF-8
C
false
false
517
c
9.c
#include <stdio.h> #include <string.h> void rev(char *s){ int l=strlen(s),i; for(i=0;i<l/2;i++){ char t=s[i]; s[i]=s[l-1-i]; s[l-1-i]=t; } } char T[4][8]={"dream","dreamer","erase","eraser"}; int main(){ int i=0,c,l; char s[100001]; for(i=0;i<4;i++)rev(T[i]); scanf("%s",s); l=strlen(s); rev(s); for(;c<l;){ int k=-1; for(i=0;i<4;i++){ if(!strncmp(s+c,T[i],strlen(T[i]))){ k=strlen(T[i]); break; } } if(k<0){ puts("NO"); return 0; } c+=k; } puts("YES"); return 0; }
625893ae47440b440a08fade4b0f5ce7f594a463
72f2515c4cef9e02c27452b32269ca403f76c69a
/src/modules/MouseUtils/MouseJump/pch.h
74abb62da1ea980b0874f311a12de3b9a0d15acb
[ "LicenseRef-scancode-generic-cla", "MIT", "BSL-1.0", "Unlicense" ]
permissive
microsoft/PowerToys
4625ffc4c513265094bf9e0f490753a54aabeaa0
3244ba989921dd26dd32be75021ed68c9cfcdda9
refs/heads/main
2023-08-17T00:10:06.645243
2023-08-16T16:31:10
2023-08-16T16:31:10
184,456,251
103,306
7,187
MIT
2023-09-14T16:52:26
2019-05-01T17:44:02
C#
UTF-8
C
false
false
228
h
pch.h
#pragma once #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <shellapi.h> //#include <common/common.h> #include <ProjectTelemetry.h> #include <common/SettingsAPI/settings_helpers.h> #include <common/logger/logger.h>
a320bd53121a184482a446c6140aa0be3d55199c
340cc5d8ba77fbbafefb8a1755ae4dacbfb6953e
/src/output/output_json.c
36b5d61761905800a99b0b983c23ec42b72060e5
[ "BSD-3-Clause" ]
permissive
phaag/nfdump
1899c1b376c62040acdc994892949310cf85b32a
584453e6e3b4d6f23cf6c83cd2a7298cf0b5c44a
refs/heads/master
2023-08-31T06:53:13.565444
2023-08-20T12:22:46
2023-08-20T12:22:46
40,435,192
703
200
NOASSERTION
2023-08-20T18:40:33
2015-08-09T12:12:03
C
UTF-8
C
false
false
24,184
c
output_json.c
/* * Copyright (c) 2019-2023, Peter Haag * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 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. * * Neither the name of the author nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR CONTRIBUTORS 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 "config.h" // for asprintf prototype #define _GNU_SOURCE #include <arpa/inet.h> #include <netinet/in.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <sys/types.h> #include <time.h> #include "maxmind.h" #include "nfdump.h" #include "nffile.h" #include "nfxV3.h" #include "output_json.h" #include "output_util.h" #include "util.h" #define IP_STRING_LEN (INET6_ADDRSTRLEN) // record counter static uint32_t recordCount; static void stringEXgenericFlow(FILE *stream, master_record_t *r) { char datebuff1[64], datebuff2[64], dateBuff3[64]; time_t when = r->msecFirst / 1000LL; struct tm *ts = localtime(&when); strftime(datebuff1, 63, "%Y-%m-%dT%H:%M:%S", ts); when = r->msecLast / 1000LL; ts = localtime(&when); strftime(datebuff2, 63, "%Y-%m-%dT%H:%M:%S", ts); when = r->msecReceived / 1000LL; ts = localtime(&when); strftime(dateBuff3, 63, "%Y-%m-%dT%H:%M:%S", ts); fprintf(stream, " \"first\" : \"%s.%03u\",\n" " \"last\" : \"%s.%03u\",\n" " \"received\" : \"%s.%03u\",\n" " \"in_packets\" : %llu,\n" " \"in_bytes\" : %llu,\n", datebuff1, (unsigned)(r->msecFirst % 1000LL), datebuff2, (unsigned)(r->msecLast % 1000LL), dateBuff3, (unsigned)(r->msecReceived % 1000LL), (unsigned long long)r->inPackets, (unsigned long long)r->inBytes); if (r->proto == IPPROTO_ICMP || r->proto == IPPROTO_ICMPV6) { // ICMP fprintf(stream, " \"proto\" : %u,\n" " \"icmp_type\" : %u,\n" " \"icmp_code\" : %u,\n" " \"src_tos\" : %u,\n", r->proto, r->icmpType, r->icmpCode, r->tos); } else { fprintf(stream, " \"proto\" : %u,\n" " \"tcp_flags\" : \"%s\",\n" " \"src_port\" : %u,\n" " \"dst_port\" : %u,\n" " \"src_tos\" : %u,\n", r->proto, FlagsString(r->tcp_flags), r->srcPort, r->dstPort, r->tos); } } // End of stringEXgenericFlow static void stringEXipv4Flow(FILE *stream, master_record_t *r) { char as[IP_STRING_LEN], ds[IP_STRING_LEN]; char sloc[128], dloc[128]; uint32_t src = htonl(r->V4.srcaddr); uint32_t dst = htonl(r->V4.dstaddr); inet_ntop(AF_INET, &src, as, sizeof(as)); inet_ntop(AF_INET, &dst, ds, sizeof(ds)); LookupLocation(r->V6.srcaddr, sloc, 128); LookupLocation(r->V6.dstaddr, dloc, 128); fprintf(stream, " \"src4_addr\" : \"%s\",\n" " \"dst4_addr\" : \"%s\",\n" " \"src_geo\" : \"%s\",\n" " \"dst_geo\" : \"%s\",\n", as, ds, sloc, dloc); } // End of stringEXipv4Flow static void stringEXipv6Flow(FILE *stream, master_record_t *r) { char as[IP_STRING_LEN], ds[IP_STRING_LEN]; char sloc[128], dloc[128]; uint64_t src[2], dst[2]; src[0] = htonll(r->V6.srcaddr[0]); src[1] = htonll(r->V6.srcaddr[1]); dst[0] = htonll(r->V6.dstaddr[0]); dst[1] = htonll(r->V6.dstaddr[1]); inet_ntop(AF_INET6, &src, as, sizeof(as)); inet_ntop(AF_INET6, &dst, ds, sizeof(ds)); LookupLocation(r->V6.srcaddr, sloc, 128); LookupLocation(r->V6.dstaddr, dloc, 128); fprintf(stream, " \"src6_addr\" : \"%s\",\n" " \"dst6_addr\" : \"%s\",\n" " \"src_geo\" : \"%s\",\n" " \"dst_geo\" : \"%s\",\n", as, ds, sloc, dloc); } // End of stringEXipv6Flow static void stringEXflowMisc(FILE *stream, master_record_t *r) { char snet[IP_STRING_LEN], dnet[IP_STRING_LEN]; if (TestFlag(r->mflags, V3_FLAG_IPV6_ADDR) != 0) { // IPv6 if (r->src_mask || r->dst_mask) { uint64_t src[2]; uint64_t dst[2]; if (r->src_mask >= 64) { src[0] = r->V6.srcaddr[0] & (0xffffffffffffffffLL << (r->src_mask - 64)); src[1] = 0; } else { src[0] = r->V6.srcaddr[0]; src[1] = r->V6.srcaddr[1] & (0xffffffffffffffffLL << r->src_mask); } src[0] = htonll(src[0]); src[1] = htonll(src[1]); inet_ntop(AF_INET6, &src, snet, sizeof(snet)); if (r->dst_mask >= 64) { dst[0] = r->V6.dstaddr[0] & (0xffffffffffffffffLL << (r->dst_mask - 64)); dst[1] = 0; } else { dst[0] = r->V6.dstaddr[0]; dst[1] = r->V6.dstaddr[1] & (0xffffffffffffffffLL << r->dst_mask); } dst[0] = htonll(dst[0]); dst[1] = htonll(dst[1]); inet_ntop(AF_INET6, &dst, dnet, sizeof(dnet)); } else { snet[0] = '\0'; dnet[0] = '\0'; } } else { // IPv4 if (r->src_mask || r->dst_mask) { uint32_t src, dst; src = r->V4.srcaddr & (0xffffffffL << (32 - r->src_mask)); src = htonl(src); inet_ntop(AF_INET, &src, snet, sizeof(snet)); dst = r->V4.dstaddr & (0xffffffffL << (32 - r->dst_mask)); dst = htonl(dst); inet_ntop(AF_INET, &dst, dnet, sizeof(dnet)); } else { snet[0] = '\0'; dnet[0] = '\0'; } } fprintf(stream, " \"input_snmp\" : %u,\n" " \"output_snmp\" : %u,\n" " \"src_mask\" : %u,\n" " \"dst_mask\" : %u,\n" " \"src_net\" : \"%s\",\n" " \"dst_net\" : \"%s\",\n" " \"fwd_status\" : %u,\n" " \"direction\" : %u,\n" " \"dst_tos\" : %u,\n", r->input, r->output, r->src_mask, r->dst_mask, snet, dnet, r->fwd_status, r->dir, r->dst_tos); } // End of stringEXflowMisc static void stringEXcntFlow(FILE *stream, master_record_t *r) { fprintf(stream, " \"out_packets\" : %llu,\n" " \"out_bytes\" : %llu,\n" " \"aggr_flows\" : %llu,\n", (long long unsigned)r->out_pkts, (long long unsigned)r->out_bytes, (long long unsigned)r->aggr_flows); } // End of stringEXcntFlow static void stringEXvLan(FILE *stream, master_record_t *r) { fprintf(stream, " \"src_vlan\" : %u,\n" " \"dst_vlan\" : %u,\n", r->src_vlan, r->dst_vlan); } // End of stringEXvLan static void stringEXasRouting(FILE *stream, master_record_t *r) { if (r->srcas == 0) r->srcas = LookupAS(r->V6.srcaddr); if (r->dstas == 0) r->dstas = LookupAS(r->V6.dstaddr); fprintf(stream, " \"src_as\" : %u,\n" " \"dst_as\" : %u,\n", r->srcas, r->dstas); } // End of stringEXasRouting static void stringEXbgpNextHopV4(FILE *stream, master_record_t *r) { char ip[IP_STRING_LEN]; ip[0] = 0; uint32_t i = htonl(r->bgp_nexthop.V4); inet_ntop(AF_INET, &i, ip, sizeof(ip)); ip[IP_STRING_LEN - 1] = 0; fprintf(stream, " \"bgp4_next_hop\" : \"%s\",\n", ip); } // End of stringEXbgpNextHopV4 static void stringEXbgpNextHopV6(FILE *stream, master_record_t *r) { char ip[IP_STRING_LEN]; uint64_t i[2]; i[0] = htonll(r->bgp_nexthop.V6[0]); i[1] = htonll(r->bgp_nexthop.V6[1]); inet_ntop(AF_INET6, i, ip, sizeof(ip)); ip[IP_STRING_LEN - 1] = 0; fprintf(stream, " \"bgp6_next_hop\" : \"%s\",\n", ip); } // End of stringEXbgpNextHopV6 static void stringEXipNextHopV4(FILE *stream, master_record_t *r) { char ip[IP_STRING_LEN]; ip[0] = 0; uint32_t i = htonl(r->ip_nexthop.V4); inet_ntop(AF_INET, &i, ip, sizeof(ip)); ip[IP_STRING_LEN - 1] = 0; fprintf(stream, " \"ip4_next_hop\" : \"%s\",\n", ip); } // End of stringEXipNextHopV4 static void stringEXipNextHopV6(FILE *stream, master_record_t *r) { char ip[IP_STRING_LEN]; uint64_t i[2]; i[0] = htonll(r->ip_nexthop.V6[0]); i[1] = htonll(r->ip_nexthop.V6[1]); inet_ntop(AF_INET6, i, ip, sizeof(ip)); ip[IP_STRING_LEN - 1] = 0; fprintf(stream, " \"ip6_next_hop\" : \"%s\",\n", ip); } // End of stringEXipNextHopV6 static void stringEXipReceivedV4(FILE *stream, master_record_t *r) { char ip[IP_STRING_LEN]; ip[0] = 0; uint32_t i = htonl(r->ip_router.V4); inet_ntop(AF_INET, &i, ip, sizeof(ip)); ip[IP_STRING_LEN - 1] = 0; fprintf(stream, " \"ip4_router\" : \"%s\",\n", ip); } // End of stringEXipReceivedV4 static void stringEXipReceivedV6(FILE *stream, master_record_t *r) { char ip[IP_STRING_LEN]; uint64_t i[2]; i[0] = htonll(r->ip_router.V6[0]); i[1] = htonll(r->ip_router.V6[1]); inet_ntop(AF_INET6, i, ip, sizeof(ip)); ip[IP_STRING_LEN - 1] = 0; fprintf(stream, " \"ip6_router\" : \"%s\",\n", ip); } // End of stringEXipReceivedV6 static void stringEXmplsLabel(FILE *stream, master_record_t *r) { for (int i = 0; i < 10; i++) { fprintf(stream, " \"mpls_%u\" : \"%u-%u-%u\",\n", i + 1, r->mpls_label[i] >> 4, (r->mpls_label[i] & 0xF) >> 1, r->mpls_label[i] & 1); } } // End of stringEXipReceivedV6 static void stringEXmacAddr(FILE *stream, master_record_t *r) { uint8_t mac1[6], mac2[6], mac3[6], mac4[6]; for (int i = 0; i < 6; i++) { mac1[i] = (r->in_src_mac >> (i * 8)) & 0xFF; mac2[i] = (r->out_dst_mac >> (i * 8)) & 0xFF; mac3[i] = (r->in_dst_mac >> (i * 8)) & 0xFF; mac4[i] = (r->out_src_mac >> (i * 8)) & 0xFF; } fprintf(stream, " \"in_src_mac\" : \"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\",\n" " \"out_dst_mac\" : \"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\",\n" " \"in_dst_mac\" : \"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\",\n" " \"out_src_mac\" : \"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\",\n", mac1[5], mac1[4], mac1[3], mac1[2], mac1[1], mac1[0], mac2[5], mac2[4], mac2[3], mac2[2], mac2[1], mac2[0], mac3[5], mac3[4], mac3[3], mac3[2], mac3[1], mac3[0], mac4[5], mac4[4], mac4[3], mac4[2], mac4[1], mac4[0]); } // End of stringEXmacAddr static void stringEXasAdjacent(FILE *stream, master_record_t *r) { fprintf(stream, " \"next_as\" : %u,\n" " \"prev_as\" : %u,\n", r->bgpNextAdjacentAS, r->bgpPrevAdjacentAS); } // End of stringEXasAdjacent static void stringEXlatency(FILE *stream, master_record_t *r) { double f1, f2, f3; f1 = (double)r->client_nw_delay_usec / 1000.0; f2 = (double)r->server_nw_delay_usec / 1000.0; f3 = (double)r->appl_latency_usec / 1000.0; fprintf(stream, " \"cli_latency\" : %f,\n" " \"srv_latency\" : %f,\n" " \"app_latency\" : %f,\n", f1, f2, f3); } // End of stringEXlatency static void String_ja3(FILE *stream, master_record_t *r) { uint8_t zero[16] = {0}; if (r->inPayloadLength == 0 || memcmp(r->ja3, zero, 16) == 0) { return; } char out[33]; int i, j; for (i = 0, j = 0; i < 16; i++, j += 2) { uint8_t ln = r->ja3[i] & 0xF; uint8_t hn = (r->ja3[i] >> 4) & 0xF; out[j + 1] = ln <= 9 ? ln + '0' : ln + 'a' - 10; out[j] = hn <= 9 ? hn + '0' : hn + 'a' - 10; } out[32] = '\0'; fprintf(stream, " \"ja3\" : %s,\n", out); } // End of String_ja3 static void stringEXtunIPv4(FILE *stream, master_record_t *r) { char as[IP_STRING_LEN], ds[IP_STRING_LEN]; uint32_t src = htonl(r->tun_src_ip.V4); uint32_t dst = htonl(r->tun_dst_ip.V4); inet_ntop(AF_INET, &src, as, sizeof(as)); inet_ntop(AF_INET, &dst, ds, sizeof(ds)); fprintf(stream, " \"tun proto\" : %u,\n" " \"src4_tun_ip\" : \"%s\",\n" " \"dst4_tun_ip\" : \"%s\",\n", r->tun_proto, as, ds); } // End of stringEXtunIPv4 static void stringEXtunIPv6(FILE *stream, master_record_t *r) { char as[IP_STRING_LEN], ds[IP_STRING_LEN]; uint64_t src[2]; uint64_t dst[2]; src[0] = htonll(r->tun_src_ip.V6[0]); src[1] = htonll(r->tun_src_ip.V6[1]); dst[0] = htonll(r->tun_dst_ip.V6[0]); dst[1] = htonll(r->tun_dst_ip.V6[1]); inet_ntop(AF_INET6, &src, as, sizeof(as)); inet_ntop(AF_INET6, &dst, ds, sizeof(ds)); fprintf(stream, " \"tun proto\" : %u,\n" " \"src6_tun_ip\" : \"%s\",\n" " \"dst6_tun_ip\" : \"%s\",\n", r->tun_proto, as, ds); } // End of stringEXtunIPv6 static void stringEXobservation(FILE *stream, master_record_t *r) { fprintf(stream, " \"observationDoaminID\" : %u,\n" " \"observationPointID\" : %llu,\n", r->observationDomainID, (long long unsigned)r->observationPointID); } // End of stringEXobservation static void stringEXvrf(FILE *stream, master_record_t *r) { fprintf(stream, " \"ingress_vrf\" : \"%u\",\n" " \"egress_vrf\" : \"%u\",\n", r->ingressVrf, r->egressVrf); } // End of stringEXvrf #ifdef NSEL static void stringEXnselCommon(FILE *stream, master_record_t *r) { char datestr[64]; time_t when = r->msecEvent / 1000LL; if (when == 0) { strncpy(datestr, "<unknown>", 63); } else { struct tm *ts = localtime(&when); strftime(datestr, 63, "%Y-%m-%dT%H:%M:%S", ts); } fprintf(stream, " \"connect_id\" : \"%u\",\n" " \"event_id\" : \"%u\",\n" " \"event\" : \"%s\",\n" " \"xevent_id\" : \"%u\",\n" " \"t_event\" : \"%s.%llu\",\n", r->connID, r->event, r->event_flag == FW_EVENT ? FwEventString(r->event) : EventString(r->event), r->fwXevent, datestr, r->msecEvent % 1000LL); } // End of stringEXnselCommon static void stringEXnselXlateIPv4(FILE *stream, master_record_t *r) { char as[IP_STRING_LEN], ds[IP_STRING_LEN]; uint32_t src = htonl(r->xlate_src_ip.V4); uint32_t dst = htonl(r->xlate_dst_ip.V4); inet_ntop(AF_INET, &src, as, sizeof(as)); inet_ntop(AF_INET, &dst, ds, sizeof(ds)); fprintf(stream, " \"src4_xlt_ip\" : \"%s\",\n" " \"dst4_xlt_ip\" : \"%s\",\n", as, ds); } // End of stringEXnselXlateIPv4 static void stringEXnselXlateIPv6(FILE *stream, master_record_t *r) { char as[IP_STRING_LEN], ds[IP_STRING_LEN]; uint64_t src[2]; uint64_t dst[2]; src[0] = htonll(r->xlate_src_ip.V6[0]); src[1] = htonll(r->xlate_src_ip.V6[1]); dst[0] = htonll(r->xlate_dst_ip.V6[0]); dst[1] = htonll(r->xlate_dst_ip.V6[1]); inet_ntop(AF_INET6, &src, as, sizeof(as)); inet_ntop(AF_INET6, &dst, ds, sizeof(ds)); fprintf(stream, " \"src6_xlt_ip\" : \"%s\",\n" " \"dst6_xlt_ip\" : \"%s\",\n", as, ds); } // End of stringEXnselXlateIPv4 static void stringEXnselXlatePort(FILE *stream, master_record_t *r) { fprintf(stream, " \"src_xlt_port\" : \"%u\",\n" " \"dst_xlt_port\" : \"%u\",\n", r->xlate_src_port, r->xlate_dst_port); } // End of stringEXnselXlatePort static void stringEXnselAcl(FILE *stream, master_record_t *r) { fprintf(stream, " \"ingress_acl\" : \"0x%x/0x%x/0x%x\",\n" " \"egress_acl\" : \"0x%x/0x%x/0x%x\",\n", r->ingressAcl[0], r->ingressAcl[1], r->ingressAcl[2], r->egressAcl[0], r->egressAcl[1], r->egressAcl[2]); } // End of stringEXnselAcl static void stringEXnselUserID(FILE *stream, master_record_t *r) { fprintf(stream, " \"user_name\" : \"%s\",\n", r->username[0] ? r->username : "<empty>"); } // End of stringEXnselUserID static void stringEXnelCommon(FILE *stream, master_record_t *r) { char datestr[64]; char *event; switch (r->event) { case 0: event = "Reserved"; break; case 1: event = "NAT translation create"; break; case 2: event = "NAT translation delete"; break; case 3: event = "NAT Addresses exhausted"; break; case 4: event = "NAT44 session create"; break; case 5: event = "NAT44 session delete"; break; case 6: event = "NAT64 session create"; break; case 7: event = "NAT64 session delete"; break; case 8: event = "NAT44 BIB create"; break; case 9: event = "NAT44 BIB delete"; break; case 10: event = "NAT64 BIB create"; break; case 11: event = "NAT64 BIB delete"; break; case 12: event = "NAT ports exhausted"; break; case 13: event = "Quota Exceeded"; break; case 14: event = "Address binding create"; break; case 15: event = "Address binding delete"; break; case 16: event = "Port block allocation"; break; case 17: event = "Port block de-allocation"; break; case 18: event = "Threshold Reached"; break; default: event = ""; break; } time_t when = r->msecEvent / 1000LL; if (when == 0) { strncpy(datestr, "<unknown>", 63); } else { struct tm *ts = localtime(&when); strftime(datestr, 63, "%Y-%m-%dT%H:%M:%S", ts); } fprintf(stream, " \"nat_event_id\" : \"%u\",\n" " \"nat_event\" : \"%s\",\n" " \"ingress_vrf\" : \"%u\",\n" " \"egress_vrf\" : \"%u\",\n" " \"t_event\" : \"%s.%llu\",\n", r->event, event, r->ingressVrf, r->egressVrf, datestr, r->msecEvent % 1000LL); } // End of stringEXnelCommon static void stringEXnelXlatePort(FILE *stream, master_record_t *r) { fprintf(stream, " \"pblock_start\" : \"%u\",\n" " \"pblock_end\" : \"%u\",\n" " \"pblock_step\" : \"%u\",\n" " \"pblock_size\" : \"%u\",\n", r->block_start, r->block_end, r->block_step, r->block_size); } // End of stringEXnelXlatePort #endif void json_prolog(void) { recordCount = 0; // open json printf("[\n"); } // End of json_prolog void json_epilog(void) { // close json printf("]\n"); } // End of json_epilog void flow_record_to_json(FILE *stream, void *record, int tag) { master_record_t *r = (master_record_t *)record; if (recordCount) { fprintf(stream, ",\n"); } recordCount++; fprintf(stream, "{\n" " \"type\" : \"%s\",\n" " \"sampled\" : %u,\n" " \"export_sysid\" : %u,\n", TestFlag(r->flags, V3_FLAG_EVENT) ? "EVENT" : "FLOW", TestFlag(r->flags, V3_FLAG_SAMPLED) ? 1 : 0, r->exporter_sysid); int i = 0; while (r->exElementList[i]) { switch (r->exElementList[i]) { case EXnull: fprintf(stderr, "Found unexpected NULL extension \n"); break; case EXgenericFlowID: stringEXgenericFlow(stream, r); break; case EXipv4FlowID: stringEXipv4Flow(stream, r); break; case EXipv6FlowID: stringEXipv6Flow(stream, r); break; case EXflowMiscID: stringEXflowMisc(stream, r); break; case EXcntFlowID: stringEXcntFlow(stream, r); break; case EXvLanID: stringEXvLan(stream, r); break; case EXasRoutingID: stringEXasRouting(stream, r); break; case EXbgpNextHopV4ID: stringEXbgpNextHopV4(stream, r); break; case EXbgpNextHopV6ID: stringEXbgpNextHopV6(stream, r); break; case EXipNextHopV4ID: stringEXipNextHopV4(stream, r); break; case EXipNextHopV6ID: stringEXipNextHopV6(stream, r); break; case EXipReceivedV4ID: stringEXipReceivedV4(stream, r); break; case EXipReceivedV6ID: stringEXipReceivedV6(stream, r); break; case EXmplsLabelID: stringEXmplsLabel(stream, r); break; case EXmacAddrID: stringEXmacAddr(stream, r); break; case EXasAdjacentID: stringEXasAdjacent(stream, r); break; case EXlatencyID: stringEXlatency(stream, r); break; case EXinPayloadID: String_ja3(stream, r); break; case EXoutPayloadID: String_ja3(stream, r); break; case EXtunIPv4ID: stringEXtunIPv4(stream, r); break; case EXtunIPv6ID: stringEXtunIPv6(stream, r); break; case EXobservationID: stringEXobservation(stream, r); break; case EXvrfID: stringEXvrf(stream, r); break; #ifdef NSEL case EXnselCommonID: stringEXnselCommon(stream, r); break; case EXnselXlateIPv4ID: stringEXnselXlateIPv4(stream, r); break; case EXnselXlateIPv6ID: stringEXnselXlateIPv6(stream, r); break; case EXnselXlatePortID: stringEXnselXlatePort(stream, r); break; case EXnselAclID: stringEXnselAcl(stream, r); break; case EXnselUserID: stringEXnselUserID(stream, r); break; case EXnelCommonID: stringEXnelCommon(stream, r); break; case EXnelXlatePortID: stringEXnelXlatePort(stream, r); break; #endif default: dbg_printf("Extension %i not yet implemented\n", r->exElementList[i]); } i++; } // add label and close json object fprintf(stream, " \"label\" : \"%s\"\n" "}", r->label ? r->label : "<none>"); } // End of flow_record_to_json
6e99db2bc73c813c62f2c316f2010b5f2944ce0c
1af43c4ba32d78c60f007a4d068136ce575d917f
/tools/rtl433/rtltest/devices/generic_temperature_sensor.c
753aacb5a6c52da249296ffdf7eddb555e50b507
[ "MIT" ]
permissive
gabonator/LA104
a4f1cdf2b3e513300d61c50fff091c5717abda9e
27d0eece7302c479da2cf86e881b6a51a535f93d
refs/heads/master
2023-08-31T22:09:36.272616
2023-08-27T20:08:08
2023-08-27T20:08:08
155,659,451
500
69
MIT
2023-08-17T08:44:32
2018-11-01T03:54:21
C
UTF-8
C
false
false
1,788
c
generic_temperature_sensor.c
/* Generic temperature sensor 1 * * Copyright (C) 2015 Alexandre Coffignal * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * */ /* 10 24 bits frames IIIIIIII BBTTTTTT TTTTTTTT - I: 8 bit ID - B: 2 bit? Battery ? - T: 12 bit Temp */ #include "decoder.h" static int generic_temperature_sensor_callback(r_device *decoder, bitbuffer_t *bitbuffer) { data_t *data; uint8_t *b = bitbuffer->bb[1]; int i, device, battery; float temp_f; for (i = 1; i < 10; i++) { if (bitbuffer->bits_per_row[i] != 24) { /*10 24 bits frame*/ return 0; } } // reduce false positives if ((b[0] == 0 && b[1] == 0 && b[2] == 0) || (b[0] == 0xff && b[1] == 0xff && b[2] == 0xff)) { return 0; } device = (b[0]); battery = (b[1] & 0xF0) >> 4; temp_f = (float)((signed short)(((b[1] & 0x3f) * 256 + b[2]) << 2)) / 160.0; data = data_make( "model", "", DATA_STRING, "Generic temperature sensor 1", "id", "Id", DATA_INT, device, "temperature_C", "Temperature", DATA_FORMAT, "%.02f C", DATA_DOUBLE, temp_f, "battery", "Battery?", DATA_INT, battery, NULL); decoder_output_data(decoder, data); return 1; } static char *output_fields[] = { "model", "id", "temperature_C", "battery", NULL }; r_device generic_temperature_sensor = { .name = "Generic temperature sensor 1", .modulation = OOK_PULSE_PPM, .short_width = 2000, .long_width = 4000, .gap_limit = 4800, .reset_limit = 10000, .decode_fn = &generic_temperature_sensor_callback, .disabled = 0, .fields = output_fields, };
208957cf5f057d163c733302feb1ef0a21beb9d8
ecce427678ecff2a93a47f3b1b664202c7d27617
/levels/ccm/ropeway_lift/collision.inc.c
06e42665f11c67897ef9cb1d3f20bc77a9ca0afd
[]
no_license
sm64pc/sm64ex
ecf37f31b3f7426c4874254660d856030d789714
54cd27ccee45a2403b45f07a00d6043c51149969
refs/heads/nightly
2023-08-11T12:14:34.424168
2023-07-01T11:45:50
2023-07-01T11:45:50
262,091,731
795
238
null
2023-07-01T11:45:51
2020-05-07T15:43:27
C
UTF-8
C
false
false
2,158
c
collision.inc.c
// 0x070163F8 - 0x070165A8 const Collision ccm_seg7_collision_070163F8[] = { COL_INIT(), COL_VERTEX_INIT(0x18), COL_VERTEX(-204, -204, -101), COL_VERTEX(205, -255, -142), COL_VERTEX(205, -204, -101), COL_VERTEX(-204, -255, -142), COL_VERTEX(-204, -255, 143), COL_VERTEX(-204, -204, 102), COL_VERTEX(205, -204, 102), COL_VERTEX(205, -255, 143), COL_VERTEX(205, -30, -101), COL_VERTEX(-204, 0, -122), COL_VERTEX(-204, -30, -101), COL_VERTEX(205, 0, -122), COL_VERTEX(205, -30, -142), COL_VERTEX(-204, -30, -142), COL_VERTEX(205, -30, 143), COL_VERTEX(205, 0, 123), COL_VERTEX(-204, 0, 123), COL_VERTEX(-204, -30, 143), COL_VERTEX(-204, -30, 102), COL_VERTEX(205, -30, 102), COL_VERTEX(-204, -153, 102), COL_VERTEX(-204, -153, -101), COL_VERTEX(205, -153, -101), COL_VERTEX(205, -153, 102), COL_TRI_INIT(SURFACE_DEFAULT, 10), COL_TRI(0, 1, 2), COL_TRI(0, 3, 1), COL_TRI(4, 5, 6), COL_TRI(4, 6, 7), COL_TRI(6, 22, 23), COL_TRI(6, 2, 22), COL_TRI(0, 5, 20), COL_TRI(0, 20, 21), COL_TRI(5, 2, 6), COL_TRI(5, 0, 2), COL_TRI_INIT(SURFACE_VERY_SLIPPERY, 8), COL_TRI(8, 9, 10), COL_TRI(8, 11, 9), COL_TRI(11, 12, 13), COL_TRI(11, 13, 9), COL_TRI(14, 15, 16), COL_TRI(14, 16, 17), COL_TRI(15, 18, 16), COL_TRI(15, 19, 18), COL_TRI_INIT(SURFACE_HARD_NOT_SLIPPERY, 2), COL_TRI(21, 20, 23), COL_TRI(21, 23, 22), COL_TRI_INIT(SURFACE_NO_CAM_COLLISION, 24), COL_TRI(17, 16, 18), COL_TRI(20, 17, 18), COL_TRI(20, 4, 17), COL_TRI(17, 4, 7), COL_TRI(17, 7, 14), COL_TRI(20, 5, 4), COL_TRI(12, 3, 13), COL_TRI(12, 1, 3), COL_TRI(13, 3, 21), COL_TRI(3, 0, 21), COL_TRI(11, 8, 12), COL_TRI(21, 10, 13), COL_TRI(13, 10, 9), COL_TRI(10, 22, 8), COL_TRI(10, 21, 22), COL_TRI(19, 23, 20), COL_TRI(19, 20, 18), COL_TRI(19, 15, 14), COL_TRI(12, 8, 22), COL_TRI(22, 1, 12), COL_TRI(22, 2, 1), COL_TRI(14, 7, 23), COL_TRI(7, 6, 23), COL_TRI(19, 14, 23), COL_TRI_STOP(), COL_END(), };
30f7826c0d4cdface6c5a032950317bffa6cb86d
1577e1cf4e89584a125cffb855ca50a9654c6d55
/NFS/rpc.rquotad/rquotad.c
d7fc181d657cd2b906b4ad5211dc2baa789896ec
[]
no_license
apple-open-source/macos
a4188b5c2ef113d90281d03cd1b14e5ee52ebffb
2d2b15f13487673de33297e49f00ef94af743a9a
refs/heads/master
2023-08-01T11:03:26.870408
2023-03-27T00:00:00
2023-03-27T00:00:00
180,595,052
124
24
null
2022-12-27T14:54:09
2019-04-10T14:06:23
null
UTF-8
C
false
false
25,558
c
rquotad.c
/* * Copyright (c) 2007-2010 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ /* $NetBSD: rquotad.c,v 1.23 2006/05/09 20:18:07 mrg Exp $ */ /* * by Manuel Bouyer (bouyer@ensta.fr). Public domain. */ #include <sys/cdefs.h> #ifndef lint __RCSID("$NetBSD: rquotad.c,v 1.23 2006/05/09 20:18:07 mrg Exp $"); #endif #include <sys/param.h> #include <sys/types.h> #include <sys/mount.h> #include <sys/file.h> #include <sys/stat.h> #include <sys/socket.h> #include <arpa/inet.h> #include <sys/event.h> #include <sys/time.h> #include <signal.h> #include <sys/queue.h> #include <sys/quota.h> #include <stdio.h> #include <fstab.h> #include <ctype.h> #include <stdlib.h> #include <string.h> #include <pwd.h> #include <grp.h> #include <errno.h> #include <unistd.h> #include <err.h> #include <pthread.h> #include <syslog.h> #include <libutil.h> #include <util.h> #include <oncrpc/rpc.h> #include <oncrpc/rpcb.h> #include "rquota.h" int bindresvport_sa(int sd, struct sockaddr *sa); void rquota_service(struct svc_req *request, SVCXPRT *transp); void ext_rquota_service(struct svc_req *request, SVCXPRT *transp); void sendquota(struct svc_req *request, int vers, SVCXPRT *transp); int getfsquota(int type, int id, char *path, struct dqblk *dqblk); int hasquota(struct statfs *fst, char **uqfnamep, char **gqfnamep); void lock_fsq(void); void unlock_fsq(void); void check_mounts(void); void sigmux(int); void *rquotad_thread(void *arg); #if 0 #define DEBUG(args...) printf(args) #else #define DEBUG(args...) #endif #define _PATH_NFS_CONF "/etc/nfs.conf" #define _PATH_RQUOTAD_PID "/var/run/rquotad.pid" /* * structure holding NFS server config values */ struct nfs_conf_server { int rquota_port; int tcp; int udp; int verbose; }; const struct nfs_conf_server config_defaults = { 0, /* rquota_port */ 1, /* tcp */ 1, /* udp */ 0 /* verbose */ }; int config_read(struct nfs_conf_server *conf); /* * structure containing informations about file systems with quota files */ struct fsq_stat { TAILQ_ENTRY(fsq_stat) chain; /* list of file systems */ char *mountdir; /* mount point of the filesystem */ char *uqfpathname; /* pathname of the user quota file */ char *gqfpathname; /* pathname of the group quota file */ fsid_t fsid; /* fsid for the file system */ dev_t st_dev; /* device of the filesystem */ }; TAILQ_HEAD(fsqhead, fsq_stat) fsqhead; pthread_mutex_t fsq_mutex; /* mutex for file system quota list */ int gotterm = 0; struct nfs_conf_server config; const char *qfextension[] = INITQFNAMES; void sigmux(__unused int dummy) { gotterm = 1; } int main(__unused int argc, __unused char *argv[]) { SVCXPRT *transp = NULL; struct sockaddr_storage saddr; struct sockaddr_in *sin = (struct sockaddr_in*)&saddr; struct sockaddr_in6 *sin6 = (struct sockaddr_in6*)&saddr; int error, on = 1, svcregcnt; pthread_attr_t pattr; pthread_t thd; int kq, rv; struct kevent ke; struct pidfh *pfh; pid_t pid; int rqudpsock, rqtcpsock; int rqudp6sock, rqtcp6sock; /* If we are serving UDP, set up the RQUOTA/UDP sockets. */ /* set defaults then do config_read() to get config values */ config = config_defaults; config_read(&config); openlog("rpc.rquotad", LOG_CONS | LOG_PID, LOG_DAEMON); /* claim PID file */ pfh = pidfile_open(_PATH_RQUOTAD_PID, 0644, &pid); if (pfh == NULL) { syslog(LOG_ERR, "can't open rquotad pidfile: %s (%d)", strerror(errno), errno); if ((errno == EACCES) && getuid()) { syslog(LOG_ERR, "rquotad is expected to be run as root, not as uid %d.", getuid()); } else if (errno == EEXIST) { syslog(LOG_ERR, "rquotad already running, pid: %d", pid); } exit(2); } if (pidfile_write(pfh) == -1) { syslog(LOG_WARNING, "can't write to rquotad pidfile: %s (%d)", strerror(errno), errno); } rpcb_unset(NULL, RQUOTAPROG, RQUOTAVERS); rpcb_unset(NULL, RQUOTAPROG, EXT_RQUOTAVERS); signal(SIGINT, sigmux); signal(SIGTERM, sigmux); signal(SIGHUP, sigmux); /* create and register the service */ rqudpsock = rqtcpsock = -1; rqudp6sock = rqtcp6sock = -1; /* If we are serving UDP, set up the RQUOTA/UDP sockets. */ if (config.udp) { /* IPv4 */ if ((rqudpsock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { syslog(LOG_WARNING, "can't create UDP IPv4 socket: %s (%d)", strerror(errno), errno); } if (rqudpsock >= 0) { sin->sin_family = AF_INET; sin->sin_addr.s_addr = INADDR_ANY; sin->sin_port = htons(config.rquota_port); sin->sin_len = sizeof(*sin); if (bindresvport_sa(rqudpsock, (struct sockaddr *)sin) < 0) { syslog(LOG_WARNING, "can't bind UDP IPv4 addr: %s (%d)", strerror(errno), errno); close(rqudpsock); rqudpsock = -1; } } if ((rqudpsock >= 0) && ((transp = svcudp_create(rqudpsock)) == NULL)) { syslog(LOG_WARNING, "cannot create UDP IPv4 service"); close(rqudpsock); rqudpsock = -1; } if (rqudpsock >= 0) { svcregcnt = 0; if (!svc_register(transp, RQUOTAPROG, RQUOTAVERS, rquota_service, IPPROTO_UDP)) { syslog(LOG_WARNING, "unable to register (RQUOTAPROG, RQUOTAVERS, UDP/IPv4)"); } else { svcregcnt++; } if (!svc_register(transp, RQUOTAPROG, EXT_RQUOTAVERS, ext_rquota_service, IPPROTO_UDP)) { syslog(LOG_WARNING, "unable to register (RQUOTAPROG, EXT_RQUOTAVERS, UDP/IPv4)"); } else { svcregcnt++; } if (!svcregcnt) { svc_destroy(transp); close(rqudpsock); rqudpsock = -1; } } /* IPv6 */ if ((rqudp6sock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { syslog(LOG_WARNING, "can't create UDP IPv6 socket: %s (%d)", strerror(errno), errno); } if (rqudp6sock >= 0) { if (setsockopt(rqudp6sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on))) { syslog(LOG_WARNING, "can't set IPV6_V6ONLY on socket: %s (%d)", strerror(errno), errno); } sin6->sin6_family = AF_INET6; sin6->sin6_addr = in6addr_any; sin6->sin6_port = htons(config.rquota_port); sin6->sin6_len = sizeof(*sin6); if (bindresvport_sa(rqudp6sock, (struct sockaddr *)sin6) < 0) { syslog(LOG_WARNING, "can't bind UDP IPv6 addr: %s (%d)", strerror(errno), errno); close(rqudp6sock); rqudp6sock = -1; } } if ((rqudp6sock >= 0) && ((transp = svcudp_create(rqudp6sock)) == NULL)) { syslog(LOG_WARNING, "cannot create UDP IPv6 service"); close(rqudp6sock); rqudp6sock = -1; } if (rqudp6sock >= 0) { svcregcnt = 0; if (!svc_register(transp, RQUOTAPROG, RQUOTAVERS, rquota_service, IPPROTO_UDP)) { syslog(LOG_WARNING, "unable to register (RQUOTAPROG, RQUOTAVERS, UDP/IPv6)"); } else { svcregcnt++; } if (!svc_register(transp, RQUOTAPROG, EXT_RQUOTAVERS, ext_rquota_service, IPPROTO_UDP)) { syslog(LOG_WARNING, "unable to register (RQUOTAPROG, EXT_RQUOTAVERS, UDP/IPv6)"); } else { svcregcnt++; } if (!svcregcnt) { svc_destroy(transp); close(rqudp6sock); rqudp6sock = -1; } } } /* If we are serving TCP, set up the RQUOTA/TCP sockets. */ if (config.tcp) { /* IPv4 */ if ((rqtcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { syslog(LOG_WARNING, "can't create TCP IPv4 socket: %s (%d)", strerror(errno), errno); } if (rqtcpsock >= 0) { if (setsockopt(rqtcpsock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) { syslog(LOG_WARNING, "setsockopt TCP IPv4 SO_REUSEADDR: %s (%d)", strerror(errno), errno); } sin->sin_family = AF_INET; sin->sin_addr.s_addr = INADDR_ANY; sin->sin_port = htons(config.rquota_port); sin->sin_len = sizeof(*sin); if (bindresvport_sa(rqtcpsock, (struct sockaddr *)sin) < 0) { syslog(LOG_WARNING, "can't bind TCP IPv4 addr: %s (%d)", strerror(errno), errno); close(rqtcpsock); rqtcpsock = -1; } } if ((rqtcpsock >= 0) && ((transp = svctcp_create(rqtcpsock, 0, 0)) == NULL)) { syslog(LOG_WARNING, "cannot create TCP IPv4 service"); close(rqtcpsock); rqtcpsock = -1; } if (rqtcpsock >= 0) { svcregcnt = 0; if (!svc_register(transp, RQUOTAPROG, RQUOTAVERS, rquota_service, IPPROTO_TCP)) { syslog(LOG_WARNING, "unable to register (RQUOTAPROG, RQUOTAVERS, TCP/IPv4)"); } else { svcregcnt++; } if (!svc_register(transp, RQUOTAPROG, EXT_RQUOTAVERS, ext_rquota_service, IPPROTO_TCP)) { syslog(LOG_WARNING, "unable to register (RQUOTAPROG, EXT_RQUOTAVERS, TCP/IPv4)"); } else { svcregcnt++; } if (!svcregcnt) { svc_destroy(transp); close(rqtcpsock); rqtcpsock = -1; } } /* IPv6 */ if ((rqtcp6sock = socket(AF_INET6, SOCK_STREAM, 0)) < 0) { syslog(LOG_WARNING, "can't create TCP IPv6 socket: %s (%d)", strerror(errno), errno); } if (rqtcp6sock >= 0) { if (setsockopt(rqtcp6sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) { syslog(LOG_WARNING, "setsockopt TCP IPv4 SO_REUSEADDR: %s (%d)", strerror(errno), errno); } setsockopt(rqtcp6sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)); sin6->sin6_family = AF_INET6; sin6->sin6_addr = in6addr_any; sin6->sin6_port = htons(config.rquota_port); sin6->sin6_len = sizeof(*sin6); if (bindresvport_sa(rqtcp6sock, (struct sockaddr *)sin6) < 0) { syslog(LOG_WARNING, "can't bind TCP IPv6 addr: %s (%d)", strerror(errno), errno); close(rqtcp6sock); rqtcp6sock = -1; } } if ((rqtcp6sock >= 0) && ((transp = svctcp_create(rqtcp6sock, 0, 0)) == NULL)) { syslog(LOG_WARNING, "cannot create TCP IPv6 service"); close(rqtcp6sock); rqtcp6sock = -1; } if (rqtcp6sock >= 0) { svcregcnt = 0; if (!svc_register(transp, RQUOTAPROG, RQUOTAVERS, rquota_service, IPPROTO_TCP)) { syslog(LOG_WARNING, "unable to register (RQUOTAPROG, RQUOTAVERS, TCP/IPv6)"); } else { svcregcnt++; } if (!svc_register(transp, RQUOTAPROG, EXT_RQUOTAVERS, ext_rquota_service, IPPROTO_TCP)) { syslog(LOG_WARNING, "unable to register (RQUOTAPROG, EXT_RQUOTAVERS, TCP/IPv6)"); } else { svcregcnt++; } if (!svcregcnt) { svc_destroy(transp); close(rqtcp6sock); rqtcp6sock = -1; } } } if ((rqudp6sock < 0) && (rqtcp6sock < 0)) { syslog(LOG_WARNING, "Can't create RQUOTA IPv6 sockets"); } if ((rqudpsock < 0) && (rqtcpsock < 0)) { syslog(LOG_WARNING, "Can't create RQUOTA IPv4 sockets"); } if ((rqudp6sock < 0) && (rqtcp6sock < 0) && (rqudpsock < 0) && (rqtcpsock < 0)) { syslog(LOG_ERR, "Can't create any RQUOTA sockets!"); exit(1); } /* init file system quotas list */ error = pthread_mutex_init(&fsq_mutex, NULL); if (error) { syslog(LOG_ERR, "file system quota mutex init failed: %s (%d)", strerror(error), error); exit(1); } TAILQ_INIT(&fsqhead); check_mounts(); /* launch rquotad pthread */ pthread_attr_init(&pattr); pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED); error = pthread_create(&thd, &pattr, rquotad_thread, NULL); if (error) { syslog(LOG_ERR, "rquotad pthread_create: %s (%d)", strerror(error), error); exit(1); } /* sit around waiting for mount/unmount events and/or a signal */ if ((kq = kqueue()) < 0) { syslog(LOG_ERR, "kqueue: %s (%d)", strerror(errno), errno); exit(1); } EV_SET(&ke, 0, EVFILT_FS, EV_ADD, 0, 0, 0); rv = kevent(kq, &ke, 1, NULL, 0, NULL); if (rv < 0) { syslog(LOG_ERR, "kevent(EVFILT_FS): %s (%d)", strerror(errno), errno); exit(1); } while (!gotterm) { rv = kevent(kq, NULL, 0, &ke, 1, NULL); if ((rv > 0) && !(ke.flags & EV_ERROR) && (ke.fflags & (VQ_MOUNT | VQ_UNMOUNT))) { /* syslog(LOG_DEBUG, "mount list changed: 0x%x", ke.fflags); */ check_mounts(); } } alarm(1); /* XXX 5028243 in case rpcb_unset() gets hung up during shutdown */ rpcb_unset(NULL, RQUOTAPROG, RQUOTAVERS); rpcb_unset(NULL, RQUOTAPROG, EXT_RQUOTAVERS); pidfile_remove(pfh); exit(0); } /* * The incredibly complex rquotad thread function */ void * rquotad_thread(__unused void *arg) { sigset_t sigset; sigemptyset(&sigset); sigaddset(&sigset, SIGINT); sigaddset(&sigset, SIGQUIT); sigaddset(&sigset, SIGSYS); sigaddset(&sigset, SIGPIPE); sigaddset(&sigset, SIGTERM); sigaddset(&sigset, SIGHUP); sigaddset(&sigset, SIGUSR1); sigaddset(&sigset, SIGUSR2); sigaddset(&sigset, SIGABRT); pthread_sigmask(SIG_BLOCK, &sigset, NULL); svc_run(); syslog(LOG_ERR, "rquotad died"); exit(1); } void rquota_service(struct svc_req *request, SVCXPRT *transp) { switch (request->rq_proc) { case NULLPROC: (void) svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL); break; case RQUOTAPROC_GETQUOTA: case RQUOTAPROC_GETACTIVEQUOTA: sendquota(request, RQUOTAVERS, transp); break; default: svcerr_noproc(transp); break; } } void ext_rquota_service(struct svc_req *request, SVCXPRT *transp) { switch (request->rq_proc) { case NULLPROC: (void) svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL); break; case RQUOTAPROC_GETQUOTA: case RQUOTAPROC_GETACTIVEQUOTA: sendquota(request, EXT_RQUOTAVERS, transp); break; default: svcerr_noproc(transp); break; } } int ismember(struct authunix_parms *aup, int gid) { uint g; if (aup->aup_gid == (uint32_t)gid) { return 1; } for (g = 0; g < aup->aup_len; g++) { if (aup->aup_gids[g] == (uint32_t)gid) { return 1; } } return 0; } /* read quota for the specified id, and send it */ void sendquota(struct svc_req *request, int vers, SVCXPRT *transp) { struct getquota_args getq_args; struct ext_getquota_args ext_getq_args; struct getquota_rslt getq_rslt; struct dqblk dqblk; struct timeval timev; struct authunix_parms *aup; memset((char *)&getq_args, 0, sizeof(getq_args)); memset((char *)&ext_getq_args, 0, sizeof(ext_getq_args)); switch (vers) { case RQUOTAVERS: if (!svc_getargs(transp, (xdrproc_t)xdr_getquota_args, (caddr_t)&getq_args)) { svcerr_decode(transp); return; } ext_getq_args.gqa_pathp = getq_args.gqa_pathp; ext_getq_args.gqa_id = getq_args.gqa_uid; ext_getq_args.gqa_type = RQUOTA_USRQUOTA; break; case EXT_RQUOTAVERS: if (!svc_getargs(transp, (xdrproc_t)xdr_ext_getquota_args, (caddr_t)&ext_getq_args)) { svcerr_decode(transp); return; } break; } aup = (struct authunix_parms *)request->rq_clntcred; if (request->rq_cred.oa_flavor != AUTH_UNIX) { /* bad auth */ getq_rslt.status = Q_EPERM; } else if ((ext_getq_args.gqa_type == RQUOTA_USRQUOTA) && aup->aup_uid && (aup->aup_uid != (uint32_t)ext_getq_args.gqa_id)) { /* only allow user or root to get a user quota */ getq_rslt.status = Q_EPERM; } else if ((ext_getq_args.gqa_type == RQUOTA_GRPQUOTA) && aup->aup_uid && !ismember(aup, ext_getq_args.gqa_id)) { /* only allow root or group members to get a group quota */ getq_rslt.status = Q_EPERM; } else if (!getfsquota(ext_getq_args.gqa_type, ext_getq_args.gqa_id, ext_getq_args.gqa_pathp, &dqblk)) { /* failed, return noquota */ getq_rslt.status = Q_NOQUOTA; } else { uint32_t bsize = DEV_BSIZE; #define CLAMP_MAX_32(V) (uint32_t) (((V) > UINT32_MAX) ? UINT32_MAX : (V)) /* scale the block size up to fit values into 32 bits */ while ((bsize < INT32_MAX) && (((dqblk.dqb_bhardlimit / bsize) > UINT32_MAX) || ((dqblk.dqb_bsoftlimit / bsize) > UINT32_MAX) || ((dqblk.dqb_curbytes / bsize) > UINT32_MAX))) { bsize <<= 1; } gettimeofday(&timev, NULL); getq_rslt.status = Q_OK; getq_rslt.getquota_rslt_u.gqr_rquota.rq_active = TRUE; getq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize = bsize; getq_rslt.getquota_rslt_u.gqr_rquota.rq_bhardlimit = CLAMP_MAX_32(dqblk.dqb_bhardlimit / (uint64_t) bsize); getq_rslt.getquota_rslt_u.gqr_rquota.rq_bsoftlimit = CLAMP_MAX_32(dqblk.dqb_bsoftlimit / (uint64_t) bsize); getq_rslt.getquota_rslt_u.gqr_rquota.rq_curblocks = CLAMP_MAX_32(dqblk.dqb_curbytes / (uint64_t) bsize); getq_rslt.getquota_rslt_u.gqr_rquota.rq_fhardlimit = CLAMP_MAX_32(dqblk.dqb_ihardlimit); getq_rslt.getquota_rslt_u.gqr_rquota.rq_fsoftlimit = CLAMP_MAX_32(dqblk.dqb_isoftlimit); getq_rslt.getquota_rslt_u.gqr_rquota.rq_curfiles = CLAMP_MAX_32(dqblk.dqb_curinodes); getq_rslt.getquota_rslt_u.gqr_rquota.rq_btimeleft = dqblk.dqb_btime - (uint32_t) timev.tv_sec; getq_rslt.getquota_rslt_u.gqr_rquota.rq_ftimeleft = dqblk.dqb_itime - (uint32_t) timev.tv_sec; } if (!svc_sendreply(transp, (xdrproc_t)xdr_getquota_rslt, &getq_rslt)) { svcerr_systemerr(transp); } if (!svc_freeargs(transp, (xdrproc_t)xdr_getquota_args, &getq_args)) { syslog(LOG_ERR, "unable to free arguments"); exit(1); } } /* * gets the quotas for id, filesystem path. * Return 0 if fail, 1 otherwise */ int getfsquota(int type, int id, char *path, struct dqblk *dqblk) { struct stat st_path; struct fsq_stat *fs; int qcmd, fd, ret = 0; char *filename; qcmd = QCMD(Q_GETQUOTA, type == RQUOTA_USRQUOTA ? USRQUOTA : GRPQUOTA); lock_fsq(); /* first, ask for quota directly */ if (quotactl(path, qcmd, id, (char*)dqblk) == 0) { ret = 1; goto out; } /* otherwise, search/check manually */ if (stat(path, &st_path) < 0) { ret = 0; goto out; } TAILQ_FOREACH(fs, &fsqhead, chain) { /* where the device is the same as path */ if (st_path.st_dev < fs->st_dev) { ret = 0; goto out; } if (fs->st_dev != st_path.st_dev) { continue; } filename = (type == RQUOTA_USRQUOTA) ? fs->uqfpathname : fs->gqfpathname; if (filename == NULL) { ret = 0; goto out; } if ((fd = open(filename, O_RDONLY)) < 0) { syslog(LOG_WARNING, "open error: %s: %m", filename); ret = 0; goto out; } if (lseek(fd, (off_t)(id * sizeof(struct dqblk)), SEEK_SET) == (off_t)-1) { close(fd); ret = 0; goto out; } switch (read(fd, dqblk, sizeof(struct dqblk))) { case 0: /* * Convert implicit 0 quota (EOF) * into an explicit one (zero'ed dqblk) */ memset((caddr_t) dqblk, 0, sizeof(struct dqblk)); ret = 1; break; case sizeof(struct dqblk): /* OK */ ret = 1; break; default: /* ERROR */ syslog(LOG_WARNING, "read error: %s: %m", filename); close(fd); ret = 0; goto out; } close(fd); } out: unlock_fsq(); return ret; } /* * Check to see if a particular quota is to be enabled. * Comes from quota.c, NetBSD 0.9 */ int hasquota(struct statfs *fst, char **uqfnamep, char **gqfnamep) { static char buf[MAXPATHLEN], ubuf[MAXPATHLEN], gbuf[MAXPATHLEN]; struct stat sb; int qcnt = 0; /* * From quota.c: * We only support the default path to the * on disk quota files. */ snprintf(buf, sizeof(buf), "%s/%s.%s", fst->f_mntonname, QUOTAOPSNAME, qfextension[USRQUOTA] ); if (stat(buf, &sb) == 0) { snprintf(ubuf, sizeof(ubuf), "%s/%s.%s", fst->f_mntonname, QUOTAFILENAME, qfextension[USRQUOTA]); *uqfnamep = ubuf; qcnt++; } snprintf(buf, sizeof(buf), "%s/%s.%s", fst->f_mntonname, QUOTAOPSNAME, qfextension[GRPQUOTA] ); if (stat(buf, &sb) == 0) { snprintf(gbuf, sizeof(gbuf), "%s/%s.%s", fst->f_mntonname, QUOTAFILENAME, qfextension[GRPQUOTA]); *gqfnamep = gbuf; qcnt++; } return qcnt; } /* functions for locking/unlocking the file system quota list */ void lock_fsq(void) { int error = pthread_mutex_lock(&fsq_mutex); if (error) { syslog(LOG_ERR, "mutex lock failed: %s (%d)", strerror(error), error); } } void unlock_fsq(void) { int error = pthread_mutex_unlock(&fsq_mutex); if (error) { syslog(LOG_ERR, "mutex unlock failed: %s (%d)", strerror(error), error); } } /* functions for adding/deleting entries from the file system quota list */ static void fsadd(struct statfs *fst) { struct fsq_stat *fs = NULL, *fs2; char *uqfpathname = NULL, *gqfpathname = NULL; struct stat st; if (strcmp(fst->f_fstypename, "hfs") && strcmp(fst->f_fstypename, "ufs")) { return; } if (!hasquota(fst, &uqfpathname, &gqfpathname)) { return; } fs = (struct fsq_stat *) malloc(sizeof(*fs)); if (fs == NULL) { syslog(LOG_ERR, "can't malloc: %m"); return; } bzero(fs, sizeof(*fs)); fs->mountdir = strdup(fst->f_mntonname); if (fs->mountdir == NULL) { syslog(LOG_ERR, "can't strdup: %m"); goto failed; } if (uqfpathname) { fs->uqfpathname = strdup(uqfpathname); if (fs->uqfpathname == NULL) { syslog(LOG_ERR, "can't strdup: %m"); goto failed; } } if (gqfpathname) { fs->gqfpathname = strdup(gqfpathname); if (fs->gqfpathname == NULL) { syslog(LOG_ERR, "can't strdup: %m"); goto failed; } } if (stat(fst->f_mntonname, &st)) { goto failed; } fs->st_dev = st.st_dev; fs->fsid.val[0] = fst->f_fsid.val[0]; fs->fsid.val[1] = fst->f_fsid.val[1]; /* insert it into the list by st_dev order */ TAILQ_FOREACH(fs2, &fsqhead, chain) { if (fs->st_dev < fs2->st_dev) { break; } } if (fs2) { TAILQ_INSERT_BEFORE(fs2, fs, chain); } else { TAILQ_INSERT_TAIL(&fsqhead, fs, chain); } return; failed: if (fs->gqfpathname) { free(fs->gqfpathname); } if (fs->uqfpathname) { free(fs->uqfpathname); } if (fs->mountdir) { free(fs->mountdir); } free(fs); return; } static void fsdel(struct statfs *fst) { struct fsq_stat *fs; TAILQ_FOREACH(fs, &fsqhead, chain) { if ((fs->fsid.val[0] != fst->f_fsid.val[0]) || (fs->fsid.val[1] != fst->f_fsid.val[1])) { continue; } if (strcmp(fs->mountdir, fst->f_mntonname)) { continue; } break; } if (!fs) { return; } TAILQ_REMOVE(&fsqhead, fs, chain); if (fs->gqfpathname) { free(fs->gqfpathname); } if (fs->uqfpathname) { free(fs->uqfpathname); } if (fs->mountdir) { free(fs->mountdir); } free(fs); } /* * code to monitor list of mounts */ static struct statfs *sfs[2]; static int size[2], cnt[2], cur, lastfscnt; #define PREV ((cur + 1) & 1) static int sfscmp(const void *arg1, const void *arg2) { const struct statfs *sfs1 = arg1; const struct statfs *sfs2 = arg2; return strcmp(sfs1->f_mntonname, sfs2->f_mntonname); } static void get_mounts(void) { cur = (cur + 1) % 2; while (size[cur] < (lastfscnt = getfsstat(sfs[cur], size[cur] * sizeof(struct statfs), MNT_NOWAIT))) { free(sfs[cur]); size[cur] = lastfscnt + 32; sfs[cur] = malloc(size[cur] * sizeof(struct statfs)); if (!sfs[cur]) { err(1, "no memory"); } } cnt[cur] = lastfscnt; qsort(sfs[cur], cnt[cur], sizeof(struct statfs), sfscmp); } void check_mounts(void) { int i, j, cmp; lock_fsq(); get_mounts(); for (i = j = 0; (i < cnt[PREV]) && (j < cnt[cur]);) { cmp = sfscmp(&sfs[PREV][i], &sfs[cur][j]); if (!cmp) { i++; j++; continue; } if (cmp < 0) { /* file system no longer mounted */ DEBUG("- %s\n", sfs[PREV][i].f_mntonname); fsdel(&sfs[PREV][i]); i++; } if (cmp > 0) { /* file system mounted */ DEBUG("+ %s\n", sfs[cur][j].f_mntonname); fsadd(&sfs[cur][j]); j++; } } while (i < cnt[PREV]) { /* file system no longer mounted */ DEBUG("- %s\n", sfs[PREV][i].f_mntonname); fsdel(&sfs[PREV][i]); i++; } while (j < cnt[cur]) { /* file system mounted */ DEBUG("+ %s\n", sfs[cur][j].f_mntonname); fsadd(&sfs[cur][j]); j++; } unlock_fsq(); } /* * read the NFS server values from nfs.conf */ int config_read(struct nfs_conf_server *conf) { FILE *f; size_t len, linenum = 0; char *line, *p, *key, *value; long val; if (!(f = fopen(_PATH_NFS_CONF, "r"))) { if (errno != ENOENT) { syslog(LOG_WARNING, "%s", _PATH_NFS_CONF); } return 1; } for (; (line = fparseln(f, &len, &linenum, NULL, 0)); free(line)) { if (len <= 0) { continue; } /* trim trailing whitespace */ p = line + len - 1; while ((p > line) && isspace(*p)) { *p-- = '\0'; } /* find key start */ key = line; while (isspace(*key)) { key++; } /* find equals/value */ value = p = strchr(line, '='); if (p) { /* trim trailing whitespace on key */ do { *p-- = '\0'; } while ((p > line) && isspace(*p)); } /* find value start */ if (value) { do { value++; } while (isspace(*value)); } /* all server keys start with "nfs.server." */ if (strncmp(key, "nfs.server.", 11)) { DEBUG("%4ld %s=%s\n", linenum, key, value ? value : ""); continue; } val = !value ? 1 : strtol(value, NULL, 0); DEBUG("%4ld %s=%s (%d)\n", linenum, key, value ? value : "", val); if (!strcmp(key, "nfs.server.rquota.port")) { if (value && val) { conf->rquota_port = (int) val; } } else if (!strcmp(key, "nfs.server.rquota.tcp")) { conf->tcp = (int) val; } else if (!strcmp(key, "nfs.server.rquota.udp")) { conf->udp = (int) val; } else if (!strcmp(key, "nfs.server.verbose")) { conf->verbose = (int) val; } else { DEBUG("ignoring unknown config value: %4ld %s=%s\n", linenum, key, value ? value : ""); } } fclose(f); return 0; }
482f11b90d9ebb41aabf2e5ce6cd83fef99bc2f9
e6da5a3210800cdfde59f3bbb7986ff3fc878598
/src/backend/contrib/pgcrypto/internal-sha2.c
10a1e979ad13c29eafe11f791acc7879d5407798
[ "BSD-3-Clause", "PostgreSQL", "LicenseRef-scancode-unknown-license-reference", "BSD-2-Clause" ]
permissive
Tencent/TBase
b66f13583ce6cd02ee5d453e2ce5a3a61e8b8f13
7cf7f8afbcab7290538ad5e65893561710be3dfa
refs/heads/master
2023-09-04T03:27:38.289238
2023-03-09T12:02:41
2023-03-09T12:18:46
220,177,733
1,433
283
NOASSERTION
2023-07-31T07:31:58
2019-11-07T07:34:03
C
UTF-8
C
false
false
9,928
c
internal-sha2.c
/* * Tencent is pleased to support the open source community by making TBase available. * * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. * * TBase is licensed under the BSD 3-Clause License, except for the third-party component listed below. * * A copy of the BSD 3-Clause License is included in this file. * * Other dependencies and licenses: * * Open Source Software Licensed Under the PostgreSQL License: * -------------------------------------------------------------------- * 1. Postgres-XL XL9_5_STABLE * Portions Copyright (c) 2015-2016, 2ndQuadrant Ltd * Portions Copyright (c) 2012-2015, TransLattice, Inc. * Portions Copyright (c) 2010-2017, Postgres-XC Development Group * Portions Copyright (c) 1996-2015, The PostgreSQL Global Development Group * Portions Copyright (c) 1994, The Regents of the University of California * * Terms of the PostgreSQL License: * -------------------------------------------------------------------- * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without a written agreement * is hereby granted, provided that the above copyright notice and this * paragraph and the following two paragraphs appear in all copies. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * * Terms of the BSD 3-Clause License: * -------------------------------------------------------------------- * 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. * * 3. Neither the name of THL A29 Limited nor the names of its contributors may be used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS * 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. * */ /* * internal.c * Wrapper for builtin functions * * Copyright (c) 2001 Marko Kreen * 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. * * contrib/pgcrypto/internal-sha2.c */ #include "postgres.h" #include <time.h> #include "contrib/pgcrypto/px.h" #include "contrib/pgcrypto/sha2.h" void init_sha224(PX_MD *h); void init_sha256(PX_MD *h); void init_sha384(PX_MD *h); void init_sha512(PX_MD *h); /* SHA224 */ static unsigned int_sha224_len(PX_MD *h) { return SHA224_DIGEST_LENGTH; } static unsigned int_sha224_block_len(PX_MD *h) { return SHA224_BLOCK_LENGTH; } static void int_sha224_update(PX_MD *h, const uint8 *data, unsigned dlen) { SHA224_CTX *ctx = (SHA224_CTX *) h->p.ptr; SHA224_Update(ctx, data, dlen); } static void int_sha224_reset(PX_MD *h) { SHA224_CTX *ctx = (SHA224_CTX *) h->p.ptr; SHA224_Init(ctx); } static void int_sha224_finish(PX_MD *h, uint8 *dst) { SHA224_CTX *ctx = (SHA224_CTX *) h->p.ptr; SHA224_Final(dst, ctx); } static void int_sha224_free(PX_MD *h) { SHA224_CTX *ctx = (SHA224_CTX *) h->p.ptr; crypt_memset(ctx, 0, sizeof(*ctx)); crypt_free(ctx); crypt_free(h); } /* SHA256 */ static unsigned int_sha256_len(PX_MD *h) { return SHA256_DIGEST_LENGTH; } static unsigned int_sha256_block_len(PX_MD *h) { return SHA256_BLOCK_LENGTH; } static void int_sha256_update(PX_MD *h, const uint8 *data, unsigned dlen) { SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr; SHA256_Update(ctx, data, dlen); } static void int_sha256_reset(PX_MD *h) { SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr; SHA256_Init(ctx); } static void int_sha256_finish(PX_MD *h, uint8 *dst) { SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr; SHA256_Final(dst, ctx); } static void int_sha256_free(PX_MD *h) { SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr; crypt_memset(ctx, 0, sizeof(*ctx)); crypt_free(ctx); crypt_free(h); } /* SHA384 */ static unsigned int_sha384_len(PX_MD *h) { return SHA384_DIGEST_LENGTH; } static unsigned int_sha384_block_len(PX_MD *h) { return SHA384_BLOCK_LENGTH; } static void int_sha384_update(PX_MD *h, const uint8 *data, unsigned dlen) { SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr; SHA384_Update(ctx, data, dlen); } static void int_sha384_reset(PX_MD *h) { SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr; SHA384_Init(ctx); } static void int_sha384_finish(PX_MD *h, uint8 *dst) { SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr; SHA384_Final(dst, ctx); } static void int_sha384_free(PX_MD *h) { SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr; crypt_memset(ctx, 0, sizeof(*ctx)); crypt_free(ctx); crypt_free(h); } /* SHA512 */ static unsigned int_sha512_len(PX_MD *h) { return SHA512_DIGEST_LENGTH; } static unsigned int_sha512_block_len(PX_MD *h) { return SHA512_BLOCK_LENGTH; } static void int_sha512_update(PX_MD *h, const uint8 *data, unsigned dlen) { SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr; SHA512_Update(ctx, data, dlen); } static void int_sha512_reset(PX_MD *h) { SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr; SHA512_Init(ctx); } static void int_sha512_finish(PX_MD *h, uint8 *dst) { SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr; SHA512_Final(dst, ctx); } static void int_sha512_free(PX_MD *h) { SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr; crypt_memset(ctx, 0, sizeof(*ctx)); crypt_free(ctx); crypt_free(h); } /* init functions */ void init_sha224(PX_MD *md) { SHA224_CTX *ctx; ctx = crypt_alloc(sizeof(*ctx)); memset(ctx, 0, sizeof(*ctx)); md->p.ptr = ctx; md->result_size = int_sha224_len; md->block_size = int_sha224_block_len; md->reset = int_sha224_reset; md->update = int_sha224_update; md->finish = int_sha224_finish; md->free = int_sha224_free; md->reset(md); } void init_sha256(PX_MD *md) { SHA256_CTX *ctx; ctx = crypt_alloc(sizeof(*ctx)); memset(ctx, 0, sizeof(*ctx)); md->p.ptr = ctx; md->result_size = int_sha256_len; md->block_size = int_sha256_block_len; md->reset = int_sha256_reset; md->update = int_sha256_update; md->finish = int_sha256_finish; md->free = int_sha256_free; md->reset(md); } void init_sha384(PX_MD *md) { SHA384_CTX *ctx; ctx = crypt_alloc(sizeof(*ctx)); memset(ctx, 0, sizeof(*ctx)); md->p.ptr = ctx; md->result_size = int_sha384_len; md->block_size = int_sha384_block_len; md->reset = int_sha384_reset; md->update = int_sha384_update; md->finish = int_sha384_finish; md->free = int_sha384_free; md->reset(md); } void init_sha512(PX_MD *md) { SHA512_CTX *ctx; ctx = crypt_alloc(sizeof(*ctx)); memset(ctx, 0, sizeof(*ctx)); md->p.ptr = ctx; md->result_size = int_sha512_len; md->block_size = int_sha512_block_len; md->reset = int_sha512_reset; md->update = int_sha512_update; md->finish = int_sha512_finish; md->free = int_sha512_free; md->reset(md); }
44e64405dee965ee009db1cb9150c78b4313b1bb
88ae8695987ada722184307301e221e1ba3cc2fa
/third_party/libaom/source/libaom/aom_dsp/x86/highbd_variance_sse2.c
e897aab645803f8ca5ea2c3f4468f742e7782d2e
[ "BSD-3-Clause", "BSD-2-Clause", "Apache-2.0", "LGPL-2.0-or-later", "MIT", "GPL-1.0-or-later" ]
permissive
iridium-browser/iridium-browser
71d9c5ff76e014e6900b825f67389ab0ccd01329
5ee297f53dc7f8e70183031cff62f37b0f19d25f
refs/heads/master
2023-08-03T16:44:16.844552
2023-07-20T15:17:00
2023-07-23T16:09:30
220,016,632
341
40
BSD-3-Clause
2021-08-13T13:54:45
2019-11-06T14:32:31
null
UTF-8
C
false
false
39,742
c
highbd_variance_sse2.c
/* * Copyright (c) 2016, Alliance for Open Media. All rights reserved * * This source code is subject to the terms of the BSD 2 Clause License and * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License * was not distributed with this source code in the LICENSE file, you can * obtain it at www.aomedia.org/license/software. If the Alliance for Open * Media Patent License 1.0 was not distributed with this source code in the * PATENTS file, you can obtain it at www.aomedia.org/license/patent. */ #include <assert.h> #include <emmintrin.h> // SSE2 #include "config/aom_config.h" #include "config/aom_dsp_rtcd.h" #include "aom_dsp/x86/synonyms.h" #include "aom_ports/mem.h" #include "av1/common/filter.h" #include "av1/common/reconinter.h" typedef uint32_t (*high_variance_fn_t)(const uint16_t *src, int src_stride, const uint16_t *ref, int ref_stride, uint32_t *sse, int *sum); uint32_t aom_highbd_calc8x8var_sse2(const uint16_t *src, int src_stride, const uint16_t *ref, int ref_stride, uint32_t *sse, int *sum); uint32_t aom_highbd_calc16x16var_sse2(const uint16_t *src, int src_stride, const uint16_t *ref, int ref_stride, uint32_t *sse, int *sum); static void highbd_8_variance_sse2(const uint16_t *src, int src_stride, const uint16_t *ref, int ref_stride, int w, int h, uint32_t *sse, int *sum, high_variance_fn_t var_fn, int block_size) { int i, j; *sse = 0; *sum = 0; for (i = 0; i < h; i += block_size) { for (j = 0; j < w; j += block_size) { unsigned int sse0; int sum0; var_fn(src + src_stride * i + j, src_stride, ref + ref_stride * i + j, ref_stride, &sse0, &sum0); *sse += sse0; *sum += sum0; } } } static void highbd_10_variance_sse2(const uint16_t *src, int src_stride, const uint16_t *ref, int ref_stride, int w, int h, uint32_t *sse, int *sum, high_variance_fn_t var_fn, int block_size) { int i, j; uint64_t sse_long = 0; int32_t sum_long = 0; for (i = 0; i < h; i += block_size) { for (j = 0; j < w; j += block_size) { unsigned int sse0; int sum0; var_fn(src + src_stride * i + j, src_stride, ref + ref_stride * i + j, ref_stride, &sse0, &sum0); sse_long += sse0; sum_long += sum0; } } *sum = ROUND_POWER_OF_TWO(sum_long, 2); *sse = (uint32_t)ROUND_POWER_OF_TWO(sse_long, 4); } static void highbd_12_variance_sse2(const uint16_t *src, int src_stride, const uint16_t *ref, int ref_stride, int w, int h, uint32_t *sse, int *sum, high_variance_fn_t var_fn, int block_size) { int i, j; uint64_t sse_long = 0; int32_t sum_long = 0; for (i = 0; i < h; i += block_size) { for (j = 0; j < w; j += block_size) { unsigned int sse0; int sum0; var_fn(src + src_stride * i + j, src_stride, ref + ref_stride * i + j, ref_stride, &sse0, &sum0); sse_long += sse0; sum_long += sum0; } } *sum = ROUND_POWER_OF_TWO(sum_long, 4); *sse = (uint32_t)ROUND_POWER_OF_TWO(sse_long, 8); } #define VAR_FN(w, h, block_size, shift) \ uint32_t aom_highbd_8_variance##w##x##h##_sse2( \ const uint8_t *src8, int src_stride, const uint8_t *ref8, \ int ref_stride, uint32_t *sse) { \ int sum; \ uint16_t *src = CONVERT_TO_SHORTPTR(src8); \ uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \ highbd_8_variance_sse2( \ src, src_stride, ref, ref_stride, w, h, sse, &sum, \ aom_highbd_calc##block_size##x##block_size##var_sse2, block_size); \ return *sse - (uint32_t)(((int64_t)sum * sum) >> shift); \ } \ \ uint32_t aom_highbd_10_variance##w##x##h##_sse2( \ const uint8_t *src8, int src_stride, const uint8_t *ref8, \ int ref_stride, uint32_t *sse) { \ int sum; \ int64_t var; \ uint16_t *src = CONVERT_TO_SHORTPTR(src8); \ uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \ highbd_10_variance_sse2( \ src, src_stride, ref, ref_stride, w, h, sse, &sum, \ aom_highbd_calc##block_size##x##block_size##var_sse2, block_size); \ var = (int64_t)(*sse) - (((int64_t)sum * sum) >> shift); \ return (var >= 0) ? (uint32_t)var : 0; \ } \ \ uint32_t aom_highbd_12_variance##w##x##h##_sse2( \ const uint8_t *src8, int src_stride, const uint8_t *ref8, \ int ref_stride, uint32_t *sse) { \ int sum; \ int64_t var; \ uint16_t *src = CONVERT_TO_SHORTPTR(src8); \ uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \ highbd_12_variance_sse2( \ src, src_stride, ref, ref_stride, w, h, sse, &sum, \ aom_highbd_calc##block_size##x##block_size##var_sse2, block_size); \ var = (int64_t)(*sse) - (((int64_t)sum * sum) >> shift); \ return (var >= 0) ? (uint32_t)var : 0; \ } VAR_FN(128, 128, 16, 14) VAR_FN(128, 64, 16, 13) VAR_FN(64, 128, 16, 13) VAR_FN(64, 64, 16, 12) VAR_FN(64, 32, 16, 11) VAR_FN(32, 64, 16, 11) VAR_FN(32, 32, 16, 10) VAR_FN(32, 16, 16, 9) VAR_FN(16, 32, 16, 9) VAR_FN(16, 16, 16, 8) VAR_FN(16, 8, 8, 7) VAR_FN(8, 16, 8, 7) VAR_FN(8, 8, 8, 6) VAR_FN(8, 32, 8, 8) VAR_FN(32, 8, 8, 8) VAR_FN(16, 64, 16, 10) VAR_FN(64, 16, 16, 10) #undef VAR_FN unsigned int aom_highbd_8_mse16x16_sse2(const uint8_t *src8, int src_stride, const uint8_t *ref8, int ref_stride, unsigned int *sse) { int sum; uint16_t *src = CONVERT_TO_SHORTPTR(src8); uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); highbd_8_variance_sse2(src, src_stride, ref, ref_stride, 16, 16, sse, &sum, aom_highbd_calc16x16var_sse2, 16); return *sse; } unsigned int aom_highbd_10_mse16x16_sse2(const uint8_t *src8, int src_stride, const uint8_t *ref8, int ref_stride, unsigned int *sse) { int sum; uint16_t *src = CONVERT_TO_SHORTPTR(src8); uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); highbd_10_variance_sse2(src, src_stride, ref, ref_stride, 16, 16, sse, &sum, aom_highbd_calc16x16var_sse2, 16); return *sse; } unsigned int aom_highbd_12_mse16x16_sse2(const uint8_t *src8, int src_stride, const uint8_t *ref8, int ref_stride, unsigned int *sse) { int sum; uint16_t *src = CONVERT_TO_SHORTPTR(src8); uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); highbd_12_variance_sse2(src, src_stride, ref, ref_stride, 16, 16, sse, &sum, aom_highbd_calc16x16var_sse2, 16); return *sse; } unsigned int aom_highbd_8_mse8x8_sse2(const uint8_t *src8, int src_stride, const uint8_t *ref8, int ref_stride, unsigned int *sse) { int sum; uint16_t *src = CONVERT_TO_SHORTPTR(src8); uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); highbd_8_variance_sse2(src, src_stride, ref, ref_stride, 8, 8, sse, &sum, aom_highbd_calc8x8var_sse2, 8); return *sse; } unsigned int aom_highbd_10_mse8x8_sse2(const uint8_t *src8, int src_stride, const uint8_t *ref8, int ref_stride, unsigned int *sse) { int sum; uint16_t *src = CONVERT_TO_SHORTPTR(src8); uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); highbd_10_variance_sse2(src, src_stride, ref, ref_stride, 8, 8, sse, &sum, aom_highbd_calc8x8var_sse2, 8); return *sse; } unsigned int aom_highbd_12_mse8x8_sse2(const uint8_t *src8, int src_stride, const uint8_t *ref8, int ref_stride, unsigned int *sse) { int sum; uint16_t *src = CONVERT_TO_SHORTPTR(src8); uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); highbd_12_variance_sse2(src, src_stride, ref, ref_stride, 8, 8, sse, &sum, aom_highbd_calc8x8var_sse2, 8); return *sse; } // The 2 unused parameters are place holders for PIC enabled build. // These definitions are for functions defined in // highbd_subpel_variance_impl_sse2.asm #define DECL(w, opt) \ int aom_highbd_sub_pixel_variance##w##xh_##opt( \ const uint16_t *src, ptrdiff_t src_stride, int x_offset, int y_offset, \ const uint16_t *dst, ptrdiff_t dst_stride, int height, \ unsigned int *sse, void *unused0, void *unused); #define DECLS(opt) \ DECL(8, opt) \ DECL(16, opt) DECLS(sse2) #undef DECLS #undef DECL #define FN(w, h, wf, wlog2, hlog2, opt, cast) \ uint32_t aom_highbd_8_sub_pixel_variance##w##x##h##_##opt( \ const uint8_t *src8, int src_stride, int x_offset, int y_offset, \ const uint8_t *dst8, int dst_stride, uint32_t *sse_ptr) { \ uint16_t *src = CONVERT_TO_SHORTPTR(src8); \ uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); \ int se = 0; \ unsigned int sse = 0; \ unsigned int sse2; \ int row_rep = (w > 64) ? 2 : 1; \ for (int wd_64 = 0; wd_64 < row_rep; wd_64++) { \ src += wd_64 * 64; \ dst += wd_64 * 64; \ int se2 = aom_highbd_sub_pixel_variance##wf##xh_##opt( \ src, src_stride, x_offset, y_offset, dst, dst_stride, h, &sse2, \ NULL, NULL); \ se += se2; \ sse += sse2; \ if (w > wf) { \ se2 = aom_highbd_sub_pixel_variance##wf##xh_##opt( \ src + wf, src_stride, x_offset, y_offset, dst + wf, dst_stride, h, \ &sse2, NULL, NULL); \ se += se2; \ sse += sse2; \ if (w > wf * 2) { \ se2 = aom_highbd_sub_pixel_variance##wf##xh_##opt( \ src + 2 * wf, src_stride, x_offset, y_offset, dst + 2 * wf, \ dst_stride, h, &sse2, NULL, NULL); \ se += se2; \ sse += sse2; \ se2 = aom_highbd_sub_pixel_variance##wf##xh_##opt( \ src + 3 * wf, src_stride, x_offset, y_offset, dst + 3 * wf, \ dst_stride, h, &sse2, NULL, NULL); \ se += se2; \ sse += sse2; \ } \ } \ } \ *sse_ptr = sse; \ return sse - (uint32_t)((cast se * se) >> (wlog2 + hlog2)); \ } \ \ uint32_t aom_highbd_10_sub_pixel_variance##w##x##h##_##opt( \ const uint8_t *src8, int src_stride, int x_offset, int y_offset, \ const uint8_t *dst8, int dst_stride, uint32_t *sse_ptr) { \ int64_t var; \ uint32_t sse; \ uint64_t long_sse = 0; \ uint16_t *src = CONVERT_TO_SHORTPTR(src8); \ uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); \ int se = 0; \ int row_rep = (w > 64) ? 2 : 1; \ for (int wd_64 = 0; wd_64 < row_rep; wd_64++) { \ src += wd_64 * 64; \ dst += wd_64 * 64; \ int se2 = aom_highbd_sub_pixel_variance##wf##xh_##opt( \ src, src_stride, x_offset, y_offset, dst, dst_stride, h, &sse, NULL, \ NULL); \ se += se2; \ long_sse += sse; \ if (w > wf) { \ uint32_t sse2; \ se2 = aom_highbd_sub_pixel_variance##wf##xh_##opt( \ src + wf, src_stride, x_offset, y_offset, dst + wf, dst_stride, h, \ &sse2, NULL, NULL); \ se += se2; \ long_sse += sse2; \ if (w > wf * 2) { \ se2 = aom_highbd_sub_pixel_variance##wf##xh_##opt( \ src + 2 * wf, src_stride, x_offset, y_offset, dst + 2 * wf, \ dst_stride, h, &sse2, NULL, NULL); \ se += se2; \ long_sse += sse2; \ se2 = aom_highbd_sub_pixel_variance##wf##xh_##opt( \ src + 3 * wf, src_stride, x_offset, y_offset, dst + 3 * wf, \ dst_stride, h, &sse2, NULL, NULL); \ se += se2; \ long_sse += sse2; \ } \ } \ } \ se = ROUND_POWER_OF_TWO(se, 2); \ sse = (uint32_t)ROUND_POWER_OF_TWO(long_sse, 4); \ *sse_ptr = sse; \ var = (int64_t)(sse) - ((cast se * se) >> (wlog2 + hlog2)); \ return (var >= 0) ? (uint32_t)var : 0; \ } \ \ uint32_t aom_highbd_12_sub_pixel_variance##w##x##h##_##opt( \ const uint8_t *src8, int src_stride, int x_offset, int y_offset, \ const uint8_t *dst8, int dst_stride, uint32_t *sse_ptr) { \ int start_row; \ uint32_t sse; \ int se = 0; \ int64_t var; \ uint64_t long_sse = 0; \ uint16_t *src = CONVERT_TO_SHORTPTR(src8); \ uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); \ int row_rep = (w > 64) ? 2 : 1; \ for (start_row = 0; start_row < h; start_row += 16) { \ uint32_t sse2; \ int height = h - start_row < 16 ? h - start_row : 16; \ uint16_t *src_tmp = src + (start_row * src_stride); \ uint16_t *dst_tmp = dst + (start_row * dst_stride); \ for (int wd_64 = 0; wd_64 < row_rep; wd_64++) { \ src_tmp += wd_64 * 64; \ dst_tmp += wd_64 * 64; \ int se2 = aom_highbd_sub_pixel_variance##wf##xh_##opt( \ src_tmp, src_stride, x_offset, y_offset, dst_tmp, dst_stride, \ height, &sse2, NULL, NULL); \ se += se2; \ long_sse += sse2; \ if (w > wf) { \ se2 = aom_highbd_sub_pixel_variance##wf##xh_##opt( \ src_tmp + wf, src_stride, x_offset, y_offset, dst_tmp + wf, \ dst_stride, height, &sse2, NULL, NULL); \ se += se2; \ long_sse += sse2; \ if (w > wf * 2) { \ se2 = aom_highbd_sub_pixel_variance##wf##xh_##opt( \ src_tmp + 2 * wf, src_stride, x_offset, y_offset, \ dst_tmp + 2 * wf, dst_stride, height, &sse2, NULL, NULL); \ se += se2; \ long_sse += sse2; \ se2 = aom_highbd_sub_pixel_variance##wf##xh_##opt( \ src_tmp + 3 * wf, src_stride, x_offset, y_offset, \ dst_tmp + 3 * wf, dst_stride, height, &sse2, NULL, NULL); \ se += se2; \ long_sse += sse2; \ } \ } \ } \ } \ se = ROUND_POWER_OF_TWO(se, 4); \ sse = (uint32_t)ROUND_POWER_OF_TWO(long_sse, 8); \ *sse_ptr = sse; \ var = (int64_t)(sse) - ((cast se * se) >> (wlog2 + hlog2)); \ return (var >= 0) ? (uint32_t)var : 0; \ } #define FNS(opt) \ FN(128, 128, 16, 7, 7, opt, (int64_t)) \ FN(128, 64, 16, 7, 6, opt, (int64_t)) \ FN(64, 128, 16, 6, 7, opt, (int64_t)) \ FN(64, 64, 16, 6, 6, opt, (int64_t)) \ FN(64, 32, 16, 6, 5, opt, (int64_t)) \ FN(32, 64, 16, 5, 6, opt, (int64_t)) \ FN(32, 32, 16, 5, 5, opt, (int64_t)) \ FN(32, 16, 16, 5, 4, opt, (int64_t)) \ FN(16, 32, 16, 4, 5, opt, (int64_t)) \ FN(16, 16, 16, 4, 4, opt, (int64_t)) \ FN(16, 8, 16, 4, 3, opt, (int64_t)) \ FN(8, 16, 8, 3, 4, opt, (int64_t)) \ FN(8, 8, 8, 3, 3, opt, (int64_t)) \ FN(8, 4, 8, 3, 2, opt, (int64_t)) \ FN(16, 4, 16, 4, 2, opt, (int64_t)) \ FN(8, 32, 8, 3, 5, opt, (int64_t)) \ FN(32, 8, 16, 5, 3, opt, (int64_t)) \ FN(16, 64, 16, 4, 6, opt, (int64_t)) \ FN(64, 16, 16, 6, 4, opt, (int64_t)) FNS(sse2) #undef FNS #undef FN // The 2 unused parameters are place holders for PIC enabled build. #define DECL(w, opt) \ int aom_highbd_sub_pixel_avg_variance##w##xh_##opt( \ const uint16_t *src, ptrdiff_t src_stride, int x_offset, int y_offset, \ const uint16_t *dst, ptrdiff_t dst_stride, const uint16_t *sec, \ ptrdiff_t sec_stride, int height, unsigned int *sse, void *unused0, \ void *unused); #define DECLS(opt) \ DECL(16, opt) \ DECL(8, opt) DECLS(sse2) #undef DECL #undef DECLS #define FN(w, h, wf, wlog2, hlog2, opt, cast) \ uint32_t aom_highbd_8_sub_pixel_avg_variance##w##x##h##_##opt( \ const uint8_t *src8, int src_stride, int x_offset, int y_offset, \ const uint8_t *dst8, int dst_stride, uint32_t *sse_ptr, \ const uint8_t *sec8) { \ uint32_t sse; \ uint16_t *src = CONVERT_TO_SHORTPTR(src8); \ uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); \ uint16_t *sec = CONVERT_TO_SHORTPTR(sec8); \ int se = aom_highbd_sub_pixel_avg_variance##wf##xh_##opt( \ src, src_stride, x_offset, y_offset, dst, dst_stride, sec, w, h, &sse, \ NULL, NULL); \ if (w > wf) { \ uint32_t sse2; \ int se2 = aom_highbd_sub_pixel_avg_variance##wf##xh_##opt( \ src + wf, src_stride, x_offset, y_offset, dst + wf, dst_stride, \ sec + wf, w, h, &sse2, NULL, NULL); \ se += se2; \ sse += sse2; \ if (w > wf * 2) { \ se2 = aom_highbd_sub_pixel_avg_variance##wf##xh_##opt( \ src + 2 * wf, src_stride, x_offset, y_offset, dst + 2 * wf, \ dst_stride, sec + 2 * wf, w, h, &sse2, NULL, NULL); \ se += se2; \ sse += sse2; \ se2 = aom_highbd_sub_pixel_avg_variance##wf##xh_##opt( \ src + 3 * wf, src_stride, x_offset, y_offset, dst + 3 * wf, \ dst_stride, sec + 3 * wf, w, h, &sse2, NULL, NULL); \ se += se2; \ sse += sse2; \ } \ } \ *sse_ptr = sse; \ return sse - (uint32_t)((cast se * se) >> (wlog2 + hlog2)); \ } \ \ uint32_t aom_highbd_10_sub_pixel_avg_variance##w##x##h##_##opt( \ const uint8_t *src8, int src_stride, int x_offset, int y_offset, \ const uint8_t *dst8, int dst_stride, uint32_t *sse_ptr, \ const uint8_t *sec8) { \ int64_t var; \ uint32_t sse; \ uint16_t *src = CONVERT_TO_SHORTPTR(src8); \ uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); \ uint16_t *sec = CONVERT_TO_SHORTPTR(sec8); \ int se = aom_highbd_sub_pixel_avg_variance##wf##xh_##opt( \ src, src_stride, x_offset, y_offset, dst, dst_stride, sec, w, h, &sse, \ NULL, NULL); \ if (w > wf) { \ uint32_t sse2; \ int se2 = aom_highbd_sub_pixel_avg_variance##wf##xh_##opt( \ src + wf, src_stride, x_offset, y_offset, dst + wf, dst_stride, \ sec + wf, w, h, &sse2, NULL, NULL); \ se += se2; \ sse += sse2; \ if (w > wf * 2) { \ se2 = aom_highbd_sub_pixel_avg_variance##wf##xh_##opt( \ src + 2 * wf, src_stride, x_offset, y_offset, dst + 2 * wf, \ dst_stride, sec + 2 * wf, w, h, &sse2, NULL, NULL); \ se += se2; \ sse += sse2; \ se2 = aom_highbd_sub_pixel_avg_variance##wf##xh_##opt( \ src + 3 * wf, src_stride, x_offset, y_offset, dst + 3 * wf, \ dst_stride, sec + 3 * wf, w, h, &sse2, NULL, NULL); \ se += se2; \ sse += sse2; \ } \ } \ se = ROUND_POWER_OF_TWO(se, 2); \ sse = ROUND_POWER_OF_TWO(sse, 4); \ *sse_ptr = sse; \ var = (int64_t)(sse) - ((cast se * se) >> (wlog2 + hlog2)); \ return (var >= 0) ? (uint32_t)var : 0; \ } \ \ uint32_t aom_highbd_12_sub_pixel_avg_variance##w##x##h##_##opt( \ const uint8_t *src8, int src_stride, int x_offset, int y_offset, \ const uint8_t *dst8, int dst_stride, uint32_t *sse_ptr, \ const uint8_t *sec8) { \ int start_row; \ int64_t var; \ uint32_t sse; \ int se = 0; \ uint64_t long_sse = 0; \ uint16_t *src = CONVERT_TO_SHORTPTR(src8); \ uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); \ uint16_t *sec = CONVERT_TO_SHORTPTR(sec8); \ for (start_row = 0; start_row < h; start_row += 16) { \ uint32_t sse2; \ int height = h - start_row < 16 ? h - start_row : 16; \ int se2 = aom_highbd_sub_pixel_avg_variance##wf##xh_##opt( \ src + (start_row * src_stride), src_stride, x_offset, y_offset, \ dst + (start_row * dst_stride), dst_stride, sec + (start_row * w), \ w, height, &sse2, NULL, NULL); \ se += se2; \ long_sse += sse2; \ if (w > wf) { \ se2 = aom_highbd_sub_pixel_avg_variance##wf##xh_##opt( \ src + wf + (start_row * src_stride), src_stride, x_offset, \ y_offset, dst + wf + (start_row * dst_stride), dst_stride, \ sec + wf + (start_row * w), w, height, &sse2, NULL, NULL); \ se += se2; \ long_sse += sse2; \ if (w > wf * 2) { \ se2 = aom_highbd_sub_pixel_avg_variance##wf##xh_##opt( \ src + 2 * wf + (start_row * src_stride), src_stride, x_offset, \ y_offset, dst + 2 * wf + (start_row * dst_stride), dst_stride, \ sec + 2 * wf + (start_row * w), w, height, &sse2, NULL, NULL); \ se += se2; \ long_sse += sse2; \ se2 = aom_highbd_sub_pixel_avg_variance##wf##xh_##opt( \ src + 3 * wf + (start_row * src_stride), src_stride, x_offset, \ y_offset, dst + 3 * wf + (start_row * dst_stride), dst_stride, \ sec + 3 * wf + (start_row * w), w, height, &sse2, NULL, NULL); \ se += se2; \ long_sse += sse2; \ } \ } \ } \ se = ROUND_POWER_OF_TWO(se, 4); \ sse = (uint32_t)ROUND_POWER_OF_TWO(long_sse, 8); \ *sse_ptr = sse; \ var = (int64_t)(sse) - ((cast se * se) >> (wlog2 + hlog2)); \ return (var >= 0) ? (uint32_t)var : 0; \ } #define FNS(opt) \ FN(64, 64, 16, 6, 6, opt, (int64_t)) \ FN(64, 32, 16, 6, 5, opt, (int64_t)) \ FN(32, 64, 16, 5, 6, opt, (int64_t)) \ FN(32, 32, 16, 5, 5, opt, (int64_t)) \ FN(32, 16, 16, 5, 4, opt, (int64_t)) \ FN(16, 32, 16, 4, 5, opt, (int64_t)) \ FN(16, 16, 16, 4, 4, opt, (int64_t)) \ FN(16, 8, 16, 4, 3, opt, (int64_t)) \ FN(8, 16, 8, 3, 4, opt, (int64_t)) \ FN(8, 8, 8, 3, 3, opt, (int64_t)) \ FN(8, 4, 8, 3, 2, opt, (int64_t)) \ FN(16, 4, 16, 4, 2, opt, (int64_t)) \ FN(8, 32, 8, 3, 5, opt, (int64_t)) \ FN(32, 8, 16, 5, 3, opt, (int64_t)) \ FN(16, 64, 16, 4, 6, opt, (int64_t)) \ FN(64, 16, 16, 6, 4, opt, (int64_t)) FNS(sse2) #undef FNS #undef FN static INLINE void highbd_compute_dist_wtd_comp_avg(__m128i *p0, __m128i *p1, const __m128i *w0, const __m128i *w1, const __m128i *r, void *const result) { assert(DIST_PRECISION_BITS <= 4); __m128i mult0 = _mm_mullo_epi16(*p0, *w0); __m128i mult1 = _mm_mullo_epi16(*p1, *w1); __m128i sum = _mm_adds_epu16(mult0, mult1); __m128i round = _mm_adds_epu16(sum, *r); __m128i shift = _mm_srli_epi16(round, DIST_PRECISION_BITS); xx_storeu_128(result, shift); } void aom_highbd_dist_wtd_comp_avg_pred_sse2( uint8_t *comp_pred8, const uint8_t *pred8, int width, int height, const uint8_t *ref8, int ref_stride, const DIST_WTD_COMP_PARAMS *jcp_param) { int i; const int16_t wt0 = (int16_t)jcp_param->fwd_offset; const int16_t wt1 = (int16_t)jcp_param->bck_offset; const __m128i w0 = _mm_set1_epi16(wt0); const __m128i w1 = _mm_set1_epi16(wt1); const int16_t round = (int16_t)((1 << DIST_PRECISION_BITS) >> 1); const __m128i r = _mm_set1_epi16(round); uint16_t *pred = CONVERT_TO_SHORTPTR(pred8); uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); uint16_t *comp_pred = CONVERT_TO_SHORTPTR(comp_pred8); if (width >= 8) { // Read 8 pixels one row at a time assert(!(width & 7)); for (i = 0; i < height; ++i) { int j; for (j = 0; j < width; j += 8) { __m128i p0 = xx_loadu_128(ref); __m128i p1 = xx_loadu_128(pred); highbd_compute_dist_wtd_comp_avg(&p0, &p1, &w0, &w1, &r, comp_pred); comp_pred += 8; pred += 8; ref += 8; } ref += ref_stride - width; } } else { // Read 4 pixels two rows at a time assert(!(width & 3)); for (i = 0; i < height; i += 2) { __m128i p0_0 = xx_loadl_64(ref + 0 * ref_stride); __m128i p0_1 = xx_loadl_64(ref + 1 * ref_stride); __m128i p0 = _mm_unpacklo_epi64(p0_0, p0_1); __m128i p1 = xx_loadu_128(pred); highbd_compute_dist_wtd_comp_avg(&p0, &p1, &w0, &w1, &r, comp_pred); comp_pred += 8; pred += 8; ref += 2 * ref_stride; } } } uint64_t aom_mse_4xh_16bit_highbd_sse2(uint16_t *dst, int dstride, uint16_t *src, int sstride, int h) { uint64_t sum = 0; __m128i reg0_4x16, reg1_4x16; __m128i src_8x16; __m128i dst_8x16; __m128i res0_4x32, res1_4x32, res0_4x64, res1_4x64, res2_4x64, res3_4x64; __m128i sub_result_8x16; const __m128i zeros = _mm_setzero_si128(); __m128i square_result = _mm_setzero_si128(); for (int i = 0; i < h; i += 2) { reg0_4x16 = _mm_loadl_epi64((__m128i const *)(&dst[(i + 0) * dstride])); reg1_4x16 = _mm_loadl_epi64((__m128i const *)(&dst[(i + 1) * dstride])); dst_8x16 = _mm_unpacklo_epi64(reg0_4x16, reg1_4x16); reg0_4x16 = _mm_loadl_epi64((__m128i const *)(&src[(i + 0) * sstride])); reg1_4x16 = _mm_loadl_epi64((__m128i const *)(&src[(i + 1) * sstride])); src_8x16 = _mm_unpacklo_epi64(reg0_4x16, reg1_4x16); sub_result_8x16 = _mm_sub_epi16(src_8x16, dst_8x16); res0_4x32 = _mm_unpacklo_epi16(sub_result_8x16, zeros); res1_4x32 = _mm_unpackhi_epi16(sub_result_8x16, zeros); res0_4x32 = _mm_madd_epi16(res0_4x32, res0_4x32); res1_4x32 = _mm_madd_epi16(res1_4x32, res1_4x32); res0_4x64 = _mm_unpacklo_epi32(res0_4x32, zeros); res1_4x64 = _mm_unpackhi_epi32(res0_4x32, zeros); res2_4x64 = _mm_unpacklo_epi32(res1_4x32, zeros); res3_4x64 = _mm_unpackhi_epi32(res1_4x32, zeros); square_result = _mm_add_epi64( square_result, _mm_add_epi64( _mm_add_epi64(_mm_add_epi64(res0_4x64, res1_4x64), res2_4x64), res3_4x64)); } const __m128i sum_1x64 = _mm_add_epi64(square_result, _mm_srli_si128(square_result, 8)); xx_storel_64(&sum, sum_1x64); return sum; } uint64_t aom_mse_8xh_16bit_highbd_sse2(uint16_t *dst, int dstride, uint16_t *src, int sstride, int h) { uint64_t sum = 0; __m128i src_8x16; __m128i dst_8x16; __m128i res0_4x32, res1_4x32, res0_4x64, res1_4x64, res2_4x64, res3_4x64; __m128i sub_result_8x16; const __m128i zeros = _mm_setzero_si128(); __m128i square_result = _mm_setzero_si128(); for (int i = 0; i < h; i++) { dst_8x16 = _mm_loadu_si128((__m128i *)&dst[i * dstride]); src_8x16 = _mm_loadu_si128((__m128i *)&src[i * sstride]); sub_result_8x16 = _mm_sub_epi16(src_8x16, dst_8x16); res0_4x32 = _mm_unpacklo_epi16(sub_result_8x16, zeros); res1_4x32 = _mm_unpackhi_epi16(sub_result_8x16, zeros); res0_4x32 = _mm_madd_epi16(res0_4x32, res0_4x32); res1_4x32 = _mm_madd_epi16(res1_4x32, res1_4x32); res0_4x64 = _mm_unpacklo_epi32(res0_4x32, zeros); res1_4x64 = _mm_unpackhi_epi32(res0_4x32, zeros); res2_4x64 = _mm_unpacklo_epi32(res1_4x32, zeros); res3_4x64 = _mm_unpackhi_epi32(res1_4x32, zeros); square_result = _mm_add_epi64( square_result, _mm_add_epi64( _mm_add_epi64(_mm_add_epi64(res0_4x64, res1_4x64), res2_4x64), res3_4x64)); } const __m128i sum_1x64 = _mm_add_epi64(square_result, _mm_srli_si128(square_result, 8)); xx_storel_64(&sum, sum_1x64); return sum; } uint64_t aom_mse_wxh_16bit_highbd_sse2(uint16_t *dst, int dstride, uint16_t *src, int sstride, int w, int h) { assert((w == 8 || w == 4) && (h == 8 || h == 4) && "w=8/4 and h=8/4 must satisfy"); switch (w) { case 4: return aom_mse_4xh_16bit_highbd_sse2(dst, dstride, src, sstride, h); case 8: return aom_mse_8xh_16bit_highbd_sse2(dst, dstride, src, sstride, h); default: assert(0 && "unsupported width"); return -1; } }
2b52481e9ed97759ea9eb85214ca934ea35e115f
065e86c9923692fe68f45c3de1888a29eb609f42
/qat_hw_dsa.h
10dc05e9671da93c7371cc1e807b420cf11ecdac
[ "BSD-3-Clause", "Apache-2.0", "ISC", "LicenseRef-scancode-openssl", "LicenseRef-scancode-ssleay-windows", "OpenSSL", "MIT" ]
permissive
intel/QAT_Engine
000a099a37d38ad174faea4b84ac54f8afef8800
a5a0bfe2c7cdb1aa8f6168e8ad7f25423359650d
refs/heads/master
2023-09-01T12:27:11.668274
2023-08-22T14:12:53
2023-08-23T09:02:17
48,074,518
302
123
BSD-3-Clause
2023-08-23T09:02:18
2015-12-15T23:15:52
C
UTF-8
C
false
false
2,813
h
qat_hw_dsa.h
/* ==================================================================== * * * BSD LICENSE * * Copyright(c) 2016-2023 Intel Corporation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 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. * * Neither the name of Intel Corporation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "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 COPYRIGHT * OWNER OR CONTRIBUTORS 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. * * *==================================================================== */ /***************************************************************************** * @file qat_hw_dsa.h * * This file provides an interface for DSA operation * *****************************************************************************/ #ifndef QAT_HW_DSA_H # define QAT_HW_DSA_H # include <openssl/dsa.h> /* Qat engine DSA methods declaration */ DSA_METHOD *qat_get_DSA_methods(void); void qat_free_DSA_methods(void); # ifndef DISABLE_QAT_HW_DSA int qat_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); DSA_SIG *qat_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); int qat_dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); int qat_dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, DSA *dsa); int qat_dsa_init(DSA *dsa); int qat_dsa_finish(DSA *dsa); # endif #endif /* QAT_HW_DSA_H */
307825549e112ded76e0a2a4a11bd1ae46514912
5a921a79279fc5597e155c3833b1ecc230ab1831
/include/cglm/call/mat2x3.h
c70bbf63a002c4179a6e399394e2cd3009c57e7f
[ "MIT" ]
permissive
recp/cglm
fd233721ea8b215990e60c29ebf7b9b10af49e59
f496146bce3ac33e6a13a65baeb30d36d1e9bbfb
refs/heads/master
2023-09-04T07:49:30.193832
2023-08-30T10:03:16
2023-08-30T10:03:16
67,952,038
1,947
260
MIT
2023-09-06T21:17:35
2016-09-11T20:15:35
C
UTF-8
C
false
false
750
h
mat2x3.h
/* * Copyright (c), Recep Aslantas. * * MIT License (MIT), http://opensource.org/licenses/MIT * Full license can be found in the LICENSE file */ #ifndef cglmc_mat2x3_h #define cglmc_mat2x3_h #ifdef __cplusplus extern "C" { #endif #include "../cglm.h" CGLM_EXPORT void glmc_mat2x3_copy(mat2x3 mat, mat2x3 dest); CGLM_EXPORT void glmc_mat2x3_zero(mat2x3 mat); CGLM_EXPORT void glmc_mat2x3_make(float * __restrict src, mat2x3 dest); CGLM_EXPORT void glmc_mat2x3_mul(mat2x3 m1, mat3x2 m2, mat2 dest); CGLM_EXPORT void glmc_mat2x3_mulv(mat2x3 m, vec3 v, vec2 dest); CGLM_EXPORT void glmc_mat2x3_transpose(mat2x3 m, mat3x2 dest); CGLM_EXPORT void glmc_mat2x3_scale(mat2x3 m, float s); #ifdef __cplusplus } #endif #endif /* cglmc_mat2x3_h */
54675117a2a974689789c77bb0e507f2e3f8a730
f247b3f8637b9ebbef044e301fcd399422214da1
/src/test/resources/testmodule.c
4c443c602037afadd7058b311ff9f55bdd6ac880
[ "MIT" ]
permissive
redis/jedis
9273f8f011a9fd0846f9bd1a921b6323c339fa79
c920bb371ebc471268bd11a45fc791a7e04e4228
refs/heads/master
2023-08-30T20:52:16.141044
2023-08-30T11:16:39
2023-08-30T11:16:39
715,605
2,285
798
MIT
2023-09-14T11:42:14
2010-06-11T13:04:43
Java
UTF-8
C
false
false
587
c
testmodule.c
#include "redismodule.h" #include <stdlib.h> int HelloworldRand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { RedisModule_ReplyWithLongLong(ctx,rand()); return REDISMODULE_OK; } int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { if (RedisModule_Init(ctx,"testmodule",1,REDISMODULE_APIVER_1) == REDISMODULE_ERR) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx,"testmodule.simple", HelloworldRand_RedisCommand, "readonly",0,0,0) == REDISMODULE_ERR) return REDISMODULE_ERR; }
5a0283b0eda4db40a91c54dfd58e49a9cdef9270
7f6c235b0598353549959c18f69eefd20b766907
/libsrc/target/srr/srr/rtapeg.c
61bac1742a86ca029b8553b643bb462efeacef4d
[ "ClArtistic" ]
permissive
z88dk/z88dk
46dfd4905f36d99333173cadd0a660839befc9f0
8b07f37cc43c5d9ffe69b563c80763491d8faff7
refs/heads/master
2023-09-04T19:29:49.254958
2023-09-03T20:51:24
2023-09-03T20:51:24
54,035,569
820
263
NOASSERTION
2023-09-05T11:09:04
2016-03-16T13:48:16
Assembly
UTF-8
C
false
false
606
c
rtapeg.c
/*======================================================= Reads standard Exidy tape as in 'rtape' but then chains to the execution address on the tape header. NO return values (of course!) */ #include <stdlib.h> #include <string.h> #include <sorcerer.h> void rtapeg(char *name, int unit, int addr) { char monbuf[50]; /* sprintf(monbuf,"LOG %s %x %x",name,unit,addr); return monitor(monbuf); */ char parm[6]; strcpy(monbuf, "LOG "); strcat(monbuf, name); strcat(monbuf, " 1 "); itoa(addr,parm,16); strcat(monbuf, parm); monitor(monbuf); }
b7c6789ab00f5504520ed0ea5d5b672e0f60e110
35806cf316f378a8ca98c0e244d149e052b1248d
/src/cmd/vl/v.out.h
feef7a888a4c7baa03a47c8da4582ad3cc22e2fd
[ "LicenseRef-scancode-google-patent-license-golang", "BSD-3-Clause" ]
permissive
gomini/go-mips32
337000fe20d8c35e24245d3a9d205defddedad65
56b0efd6bad0c9554b5670fa6c3641282dd4d570
refs/heads/dev.github
2023-03-10T01:34:51.544213
2023-02-20T22:40:56
2023-02-20T22:40:56
43,116,287
155
52
BSD-3-Clause
2023-02-20T22:40:57
2015-09-25T07:30:35
Go
UTF-8
C
false
false
2,472
h
v.out.h
enum { NSNAME = 8, NSYM = 50, NREG = 32, NFREG = 32, }; #include "../ld/textflag.h" enum { REGZERO = 0, REGSP = 29, REGLINK = 31, REGRET = 1, REGARG = -1, REGRT1 = 1, REGRT2 = 2, REGMIN = 3, REGENV = 7, REGMAX = 24, REGEXT = 30, REGG = REGEXT-0, REGTMP = 25, FREGRET = 0, FREGMIN = 4, FREGMAX = 22, FREGEXT = 22, FREGZERO = 24, FREGHALF = 26, FREGONE = 28, FREGTWO = 30, }; enum { BIG = 32766, NSCHED = 20, }; enum { FOLL = 1<<0, LABEL = 1<<1, LEAF = 1<<2, SYNC = 1<<3, BRANCH = 1<<4, LOAD = 1<<5, FCMP = 1<<6, NOSCHED = 1<<7, }; enum { C_NONE, C_REG, C_FREG, C_FCREG, C_MREG, C_HI, C_LO, C_ZCON, C_SCON, C_ADD0CON, C_AND0CON, C_ADDCON, C_ANDCON, C_UCON, C_LCON, C_SACON, C_SECON, C_LACON, C_LECON, C_SBRA, C_LBRA, C_SAUTO, C_SEXT, C_LAUTO, C_LEXT, C_ZOREG, C_SOREG, C_LOREG, C_GOK, C_NCLASS, }; enum as { AXXX, AABSD, AABSF, AADD, AADDD, AADDF, AADDU, AAND, ABEQ, ABFPF, ABFPT, ABGEZ, ABGEZAL, ABGTZ, ABLEZ, ABLTZ, ABLTZAL, ABNE, ABREAK, ACMPEQD, ACMPEQF, ACMPGED, ACMPGEF, ACMPGTD, ACMPGTF, ADIV, ADIVD, ADIVF, ADIVU, AJAL, AJMP, AMOVB, AMOVBU, AMOVD, AMOVDF, AMOVDW, AMOVF, AMOVFD, AMOVFW, AMOVH, AMOVHU, AMOVW, AMOVWD, AMOVWF, AMOVWL, AMOVWR, AMUL, AMULD, AMULF, AMULU, ANEGD, ANEGF, ANOR, AOR, AREM, AREMU, ARET, ASGT, ASGTU, ASLL, ASRA, ASRL, ASUB, ASUBD, ASUBF, ASUBU, ASYSCALL, ATLBP, ATLBR, ATLBWI, ATLBWR, AXOR, AERET, APREF, ALL, ASC, AMAD, AMADU, AMUL32, AMSUB, AMSUBU, AROTR, AMOVZ, AMOVN, ACLZ, ACLO, ASEB, ASEH, AWSBH, ADATA, AGLOBL, AGOK, AHISTORY, ANAME, ANOP, ATEXT, AWORD, AEND, ADYNT_, AINIT_, ASIGNAME, AUNDEF, AUSEFIELD, ATYPE, AFUNCDATA, APCDATA, ACHECKNIL, AVARDEF, AVARKILL, ADUFFCOPY, ADUFFZERO, ALAST, }; enum { D_GOK = 0, D_NONE = 1, D_BRANCH = (D_NONE+1), D_OREG = (D_NONE+2), D_CONST = (D_NONE+7), D_FCONST = (D_NONE+8), D_SCONST = (D_NONE+9), D_REG = (D_NONE+12), D_FREG = (D_NONE+13), D_FCREG = (D_NONE+14), D_MREG = (D_NONE+15), D_FILE = (D_NONE+16), D_OCONST = (D_NONE+17), D_FILE1 = (D_NONE+18), D_HI = (D_NONE+10), D_LO = (D_NONE+11), D_VCONST = (D_NONE+19), D_ADDR = (D_NONE + 22), D_CONST2 = (D_NONE+23), D_EXTERN = (D_NONE+3), D_STATIC = (D_NONE+4), D_AUTO = (D_NONE+5), D_PARAM = (D_NONE+6), }; #define SYMDEF "__.GOSYMDEF"
db99ae867a08c7c349e3692ead31867d02dbccc7
9de0cec678bc4a3bec2b4adabef9f39ff5b4afac
/PWGLF/RESONANCES/macros/lego_train/old/AddRsnToManagerRho.C
009388b07f4866f1a79e8036c8b52422e4ece1e3
[]
permissive
alisw/AliPhysics
91bf1bd01ab2af656a25ff10b25e618a63667d3e
5df28b2b415e78e81273b0d9bf5c1b99feda3348
refs/heads/master
2023-08-31T20:41:44.927176
2023-08-31T14:51:12
2023-08-31T14:51:12
61,661,378
129
1,150
BSD-3-Clause
2023-09-14T18:48:45
2016-06-21T19:31:29
C++
UTF-8
C
false
false
892
c
AddRsnToManagerRho.C
#ifndef __CINT__ #endif Bool_t AddRsnToManagerRho(TList *listRsn) { // This will use AddRsnPairs<Name>.C // and for cuts AddRsnDaughterCuts<CutName>.C // and <opt> string is passed to AddRsnDaughterCuts<CutName>.C // so you can control different cut settings // string "<Name>:mon" means that it will add monitoring histograms from cuts // Note : for now you have to set gRsnUseMiniPackage = 0 to have mon histograms // listRsn->Add(new TNamed("<Name>:mon","<CutName>:<opt>")); // default NSigma -> TPC=3 and TOF=3 listRsn->Add(new TNamed("Rho","RhoNsigma")); // // qualityonly // listRsn->Add(new TNamed("Rho","RhoNsigma:qualityonly")); // // // TPC only (Nsigma=1.5) // listRsn->Add(new TNamed("Rho","RhoNsigma:PiTPCnsig15")); // // // TOF only (NSigma=2.0) // listRsn->Add(new TNamed("Rho","RhoNsigma:PiTOFnsig20")); return kTRUE; }
3ca42aa64d54d44c22b7f484cf738a27352b4f58
a1d5df246d39000f30a1d128bc53d2f0fbbb3250
/BREN/INC/FWPROTO.H
93c212a9a9b85ac2ad5303a1d0e8ce27a9dfbfad
[ "MIT" ]
permissive
microsoft/Microsoft-3D-Movie-Maker
0873a4a5bef74792f5c787b9661fe7d8d0fabe5a
104b2653e68046c2f6373186169f281006db35b1
refs/heads/main
2022-05-07T21:09:40.479649
2022-05-04T04:12:08
2022-05-04T04:12:08
481,732,253
3,544
251
null
null
null
null
UTF-8
C
false
false
33,926
h
FWPROTO.H
/* * Copyright (c) 1993-1995 by Argonaut Technologies Limited. All rights reserved. * * $Id: fwproto.h 1.42 1995/06/30 16:08:49 sam Exp $ * $Locker: sam $ * * Function prototypes for brender framework */ #ifndef _FWPROTO_H_ #define _FWPROTO_H_ #ifdef __cplusplus extern "C" { #endif #ifndef _NO_PROTOTYPES /** ** Fixed Point **/ /* result = abs(a) */ br_fixed_ls BR_ASM_CALL BrFixedAbs(br_fixed_ls a); /* result = a*b */ br_fixed_ls BR_ASM_CALL BrFixedMul(br_fixed_ls a, br_fixed_ls b); /* result = a*b + c*d */ br_fixed_ls BR_ASM_CALL BrFixedMac2(br_fixed_ls a, br_fixed_ls b, br_fixed_ls c, br_fixed_ls d); /* result = a*b + c*d + e*f */ br_fixed_ls BR_ASM_CALL BrFixedMac3(br_fixed_ls a, br_fixed_ls b, br_fixed_ls c, br_fixed_ls d, br_fixed_ls e, br_fixed_ls f); /* result = a*b + c*d + e*f + g*h */ br_fixed_ls BR_ASM_CALL BrFixedMac4(br_fixed_ls a, br_fixed_ls b, br_fixed_ls c, br_fixed_ls d, br_fixed_ls e, br_fixed_ls f, br_fixed_ls g, br_fixed_ls h); /* result = a*a */ br_fixed_ls BR_ASM_CALL BrFixedSqr(br_fixed_ls a); /* result = a*a + b*b */ br_fixed_ls BR_ASM_CALL BrFixedSqr2(br_fixed_ls a, br_fixed_ls b); /* result = a*a + b*b + c*c */ br_fixed_ls BR_ASM_CALL BrFixedSqr3(br_fixed_ls a, br_fixed_ls b, br_fixed_ls c); /* result = a*a + b*b + c*c + d*d */ br_fixed_ls BR_ASM_CALL BrFixedSqr4(br_fixed_ls a, br_fixed_ls b, br_fixed_ls c, br_fixed_ls d); /* result = sqrt(a*a + b*b) */ br_fixed_ls BR_ASM_CALL BrFixedLength2(br_fixed_ls a, br_fixed_ls b); /* result = sqrt(a*a + b*b + c*c) */ br_fixed_ls BR_ASM_CALL BrFixedLength3(br_fixed_ls a, br_fixed_ls b, br_fixed_ls c); /* result = sqrt(a*a + b*b + c*c + d*d) */ br_fixed_ls BR_ASM_CALL BrFixedLength4(br_fixed_ls a, br_fixed_ls b, br_fixed_ls c, br_fixed_ls d); /* result = 1/sqrt(a*a + b*b) (low precision) */ br_fixed_ls BR_ASM_CALL BrFixedRLength2(br_fixed_ls a, br_fixed_ls b); /* result = 1/sqrt(a*a + b*b + c*c) (low precision) */ br_fixed_ls BR_ASM_CALL BrFixedRLength3(br_fixed_ls a, br_fixed_ls b, br_fixed_ls c); /* result = 1/sqrt(a*a + b*b + c*c + d*d) (low precision) */ br_fixed_ls BR_ASM_CALL BrFixedRLength4(br_fixed_ls a, br_fixed_ls b, br_fixed_ls c, br_fixed_ls d); /* result = a/b */ br_fixed_ls BR_ASM_CALL BrFixedDiv(br_fixed_ls a, br_fixed_ls b); /* result = a/b * 2^31 */ br_fixed_ls BR_ASM_CALL BrFixedDivF(br_fixed_ls a, br_fixed_ls b); /* result = a/b (rounded towards 0) */ br_fixed_ls BR_ASM_CALL BrFixedDivR(br_fixed_ls a, br_fixed_ls b); /* result = a*b/c */ br_fixed_ls BR_ASM_CALL BrFixedMulDiv(br_fixed_ls a, br_fixed_ls b, br_fixed_ls c); /* result = (a*b + c*d)/e */ br_fixed_ls BR_ASM_CALL BrFixedMac2Div(br_fixed_ls a, br_fixed_ls b, br_fixed_ls c, br_fixed_ls d, br_fixed_ls e); /* result = (a*b + c*d + e*f)/g */ br_fixed_ls BR_ASM_CALL BrFixedMac3Div(br_fixed_ls a, br_fixed_ls b, br_fixed_ls c, br_fixed_ls d, br_fixed_ls e, br_fixed_ls f, br_fixed_ls g); /* result = (a*b + c*d + e*f + g*h)/i */ br_fixed_ls BR_ASM_CALL BrFixedMac4Div(br_fixed_ls a, br_fixed_ls b, br_fixed_ls c, br_fixed_ls d, br_fixed_ls e, br_fixed_ls f, br_fixed_ls g, br_fixed_ls h, br_fixed_ls i); /* result = 1.0/a */ br_fixed_ls BR_ASM_CALL BrFixedRcp(br_fixed_ls a); /* * Various combinations whith fractions */ /* result = a*b + c*d - a & c are fractions */ br_fixed_ls BR_ASM_CALL BrFixedFMac2(br_fixed_lsf a, br_fixed_ls b, br_fixed_lsf c, br_fixed_ls d); /* result = a*b + c*d + e*f - a,c & e are fractions */ br_fixed_ls BR_ASM_CALL BrFixedFMac3(br_fixed_lsf a, br_fixed_ls b, br_fixed_lsf c, br_fixed_ls d, br_fixed_lsf e, br_fixed_ls f); /* result = a*b + c*d + e*f + g*h (a,c,e,g are fractions) */ br_fixed_ls BR_ASM_CALL BrFixedFMac4(br_fixed_ls a, br_fixed_ls b, br_fixed_ls c, br_fixed_ls d, br_fixed_ls e, br_fixed_ls f, br_fixed_ls g, br_fixed_ls h); /* * Misc. support functions */ br_fixed_ls BR_ASM_CALL BrFixedSin(br_angle a); br_fixed_ls BR_ASM_CALL BrFixedCos(br_angle a); br_angle BR_ASM_CALL BrFixedASin(br_fixed_ls s); br_angle BR_ASM_CALL BrFixedACos(br_fixed_ls c); br_angle BR_ASM_CALL BrFixedATan2(br_fixed_ls x, br_fixed_ls y); br_angle BR_ASM_CALL BrFixedATan2Fast(br_fixed_ls x, br_fixed_ls y); br_fixed_ls BR_PUBLIC_ENTRY BrFixedSqrt(br_fixed_ls a); br_fixed_ls BR_PUBLIC_ENTRY BrFixedPow(br_fixed_ls a,br_fixed_ls b); /* * Integer sqrt functions */ br_uint_32 BR_ASM_CALL BrSqrt(br_uint_32 a); br_uint_32 BR_ASM_CALL BrFastSqrt(br_uint_32 a); br_uint_32 BR_ASM_CALL BrFastRSqrt(br_uint_32 a); /* * Optional inline fixed point maths */ #ifndef NO_PROTOTYPES #if INLINE_FIXED #ifdef __GNUC__ #include "g386ifix.h" #endif #ifdef __WATCOMC__ #include "wtcifix.h" #endif #ifdef _MSC_VER #include "mscifix.h" #endif #endif #endif /* * Setup */ void BR_PUBLIC_ENTRY BrBegin(void); void BR_PUBLIC_ENTRY BrEnd(void); /* * XXX - All the Add/Remove/Find/Count/Enum calls could ( when !(DEBUG | PARANOID)) * be #defined in terms of the core Registry fns. with appropriate casts. */ /* * Material Handling */ br_material * BR_PUBLIC_ENTRY BrMaterialAdd(br_material *material); br_material * BR_PUBLIC_ENTRY BrMaterialRemove(br_material *material); br_material * BR_PUBLIC_ENTRY BrMaterialFind(char *pattern); typedef br_material * BR_CALLBACK br_material_find_cbfn(char *name); br_material_find_cbfn * BR_PUBLIC_ENTRY BrMaterialFindHook(br_material_find_cbfn *hook); br_uint_32 BR_PUBLIC_ENTRY BrMaterialAddMany(br_material **items, int n); br_uint_32 BR_PUBLIC_ENTRY BrMaterialRemoveMany(br_material **items, int n); br_uint_32 BR_PUBLIC_ENTRY BrMaterialFindMany(char *pattern, br_material **items, int max); br_uint_32 BR_PUBLIC_ENTRY BrMaterialCount(char *pattern); typedef br_uint_32 BR_CALLBACK br_material_enum_cbfn(br_material *item, void *arg); br_uint_32 BR_PUBLIC_ENTRY BrMaterialEnum(char *pattern, br_material_enum_cbfn *callback, void *arg); void BR_PUBLIC_ENTRY BrMaterialUpdate(br_material *material, br_uint_16 flags); br_material * BR_PUBLIC_ENTRY BrMaterialAllocate(char *name); void BR_PUBLIC_ENTRY BrMaterialFree(br_material *m); /* * Model Handling */ br_model * BR_PUBLIC_ENTRY BrModelAdd(br_model *model); br_model * BR_PUBLIC_ENTRY BrModelRemove(br_model *model); br_model * BR_PUBLIC_ENTRY BrModelFind(char *pattern); typedef br_model * BR_CALLBACK br_model_find_cbfn(char *name); br_model_find_cbfn * BR_PUBLIC_ENTRY BrModelFindHook(br_model_find_cbfn *hook); br_uint_32 BR_PUBLIC_ENTRY BrModelAddMany(br_model **items, int n); br_uint_32 BR_PUBLIC_ENTRY BrModelRemoveMany(br_model **items, int n); br_uint_32 BR_PUBLIC_ENTRY BrModelFindMany(char *pattern, br_model **items, int max); br_uint_32 BR_PUBLIC_ENTRY BrModelCount(char *pattern); typedef br_uint_32 BR_CALLBACK br_model_enum_cbfn(br_model *item, void *arg); br_uint_32 BR_PUBLIC_ENTRY BrModelEnum(char *pattern, br_model_enum_cbfn *callback, void *arg); void BR_PUBLIC_ENTRY BrModelUpdate(br_model *model, br_uint_16 flags); void BR_PUBLIC_ENTRY BrModelApplyMap(br_model *model,int map_type, br_matrix34 *xform); br_matrix34 * BR_PUBLIC_ENTRY BrModelFitMap(br_model *model, int axis_0, int axis_1, br_matrix34 *transform); br_model * BR_PUBLIC_ENTRY BrModelAllocate(char *name, int nvertices, int nfaces); void BR_PUBLIC_ENTRY BrModelFree(br_model *m); /* * Texture handling */ br_pixelmap * BR_PUBLIC_ENTRY BrMapAdd(br_pixelmap *pixelmap); br_pixelmap * BR_PUBLIC_ENTRY BrMapRemove(br_pixelmap *pixelmap); br_pixelmap * BR_PUBLIC_ENTRY BrMapFind(char *pattern); typedef br_pixelmap * BR_CALLBACK br_map_find_cbfn(char *name); br_map_find_cbfn * BR_PUBLIC_ENTRY BrMapFindHook(br_map_find_cbfn *hook); br_uint_32 BR_PUBLIC_ENTRY BrMapAddMany(br_pixelmap **items, int n); br_uint_32 BR_PUBLIC_ENTRY BrMapRemoveMany(br_pixelmap **items, int n); br_uint_32 BR_PUBLIC_ENTRY BrMapFindMany(char *pattern, br_pixelmap **items, int max); br_uint_32 BR_PUBLIC_ENTRY BrMapCount(char *pattern); typedef br_uint_32 BR_CALLBACK br_map_enum_cbfn(br_pixelmap *item, void *arg); br_uint_32 BR_PUBLIC_ENTRY BrMapEnum(char *pattern, br_map_enum_cbfn *callback, void *arg); void BR_PUBLIC_ENTRY BrMapUpdate(br_pixelmap *item, br_uint_16 flags); /* * Table handling */ br_pixelmap * BR_PUBLIC_ENTRY BrTableAdd(br_pixelmap *pixelmap); br_pixelmap * BR_PUBLIC_ENTRY BrTableRemove(br_pixelmap *pixelmap); br_pixelmap * BR_PUBLIC_ENTRY BrTableFind(char *pattern); typedef br_pixelmap * BR_CALLBACK br_table_find_cbfn(char *name); br_table_find_cbfn *BR_PUBLIC_ENTRY BrTableFindHook(br_table_find_cbfn *hook); br_uint_32 BR_PUBLIC_ENTRY BrTableAddMany(br_pixelmap **items, int n); br_uint_32 BR_PUBLIC_ENTRY BrTableRemoveMany(br_pixelmap **items, int n); br_uint_32 BR_PUBLIC_ENTRY BrTableFindMany(char *pattern, br_pixelmap **items, int max); br_uint_32 BR_PUBLIC_ENTRY BrTableCount(char *pattern); typedef br_uint_32 BR_CALLBACK br_table_enum_cbfn(br_pixelmap *item, void *arg); br_uint_32 BR_PUBLIC_ENTRY BrTableEnum(char *pattern, br_table_enum_cbfn *callback, void *arg); void BR_PUBLIC_ENTRY BrTableUpdate(br_pixelmap *item, br_uint_16 flags); /* * Resource class handling */ br_resource_class * BR_PUBLIC_ENTRY BrResClassAdd(br_resource_class *pixelmap); br_resource_class * BR_PUBLIC_ENTRY BrResClassRemove(br_resource_class *pixelmap); br_resource_class * BR_PUBLIC_ENTRY BrResClassFind(char *pattern); typedef br_resource_class * BR_CALLBACK br_resclass_find_cbfn(char *name); br_resclass_find_cbfn *BR_PUBLIC_ENTRY BrResClassFindHook(br_resclass_find_cbfn *hook); br_uint_32 BR_PUBLIC_ENTRY BrResClassAddMany(br_resource_class **items, int n); br_uint_32 BR_PUBLIC_ENTRY BrResClassRemoveMany(br_resource_class **items, int n); br_uint_32 BR_PUBLIC_ENTRY BrResClassFindMany(char *pattern, br_resource_class **items, int max); br_uint_32 BR_PUBLIC_ENTRY BrResClassCount(char *pattern); typedef br_uint_32 BR_CALLBACK br_resclass_enum_cbfn(br_resource_class *item, void *arg); br_uint_32 BR_PUBLIC_ENTRY BrResClassEnum(char *pattern, br_resclass_enum_cbfn *callback, void *arg); /* * Actor Handling */ typedef br_uint_32 BR_CALLBACK br_actor_enum_cbfn(br_actor *mat, void *arg); br_uint_32 BR_PUBLIC_ENTRY BrActorEnum(br_actor *parent, br_actor_enum_cbfn *callback , void *arg); br_actor * BR_PUBLIC_ENTRY BrActorAdd(br_actor *parent, br_actor *a); br_actor * BR_PUBLIC_ENTRY BrActorRemove(br_actor *a); void BR_PUBLIC_ENTRY BrActorRelink(br_actor *parent,br_actor *actor); br_uint_8 BR_PUBLIC_ENTRY BrActorToActorMatrix34(br_matrix34 *m, br_actor *a, br_actor *b); void BR_PUBLIC_ENTRY BrActorToScreenMatrix4(br_matrix4 *m, br_actor *a, br_actor *camera); br_actor * BR_PUBLIC_ENTRY BrActorAllocate(br_uint_8 actor_type, void * type_data); void BR_PUBLIC_ENTRY BrActorFree(br_actor *a); br_uint_32 BR_PUBLIC_ENTRY BrActorSearchMany(br_actor *root, char *pattern, br_actor **actors, int max); br_actor * BR_PUBLIC_ENTRY BrActorSearch(br_actor *root, char *pattern); br_bounds * BR_PUBLIC_ENTRY BrActorToBounds( br_bounds *b, br_actor *ap); br_matrix34 * BR_PUBLIC_ENTRY BrBoundsToMatrix34( br_matrix34 *mat, br_bounds *bounds); /* * Pixelmap management */ br_pixelmap * BR_PUBLIC_ENTRY BrPixelmapAllocate(br_uint_8 type,br_uint_16 w,br_uint_16 h, void *pixels, int flags); br_pixelmap * BR_PUBLIC_ENTRY BrPixelmapAllocateSub(br_pixelmap *pm, br_uint_16 x, br_uint_16 y, br_uint_16 w, br_uint_16 h); void BR_PUBLIC_ENTRY BrPixelmapFree(br_pixelmap *pm); br_pixelmap * BR_PUBLIC_ENTRY BrPixelmapMatch(br_pixelmap *src, br_uint_8 match_type); br_pixelmap * BR_PUBLIC_ENTRY BrPixelmapClone(br_pixelmap *src); br_uint_16 BR_PUBLIC_ENTRY BrPixelmapPixelSize(br_pixelmap *pm); br_uint_16 BR_PUBLIC_ENTRY BrPixelmapChannels(br_pixelmap *pm); /* * Pixelmap operations */ void BR_PUBLIC_ENTRY BrPixelmapFill(br_pixelmap *dst, br_uint_32 colour); void BR_PUBLIC_ENTRY BrPixelmapRectangle(br_pixelmap *dst,br_int_16 x,br_int_16 y,br_uint_16 w,br_uint_16 h,br_uint_32 colour); void BR_PUBLIC_ENTRY BrPixelmapRectangle2(br_pixelmap *dst,br_int_16 x,br_int_16 y,br_uint_16 w,br_uint_16 h,br_uint_32 colour1, br_uint_32 colour2); void BR_PUBLIC_ENTRY BrPixelmapRectangleCopy(br_pixelmap *dst,br_int_16 dx,br_int_16 dy,br_pixelmap *src,br_int_16 sx,br_int_16 sy,br_uint_16 w,br_uint_16 h); void BR_PUBLIC_ENTRY BrPixelmapRectangleFill(br_pixelmap *dst,br_int_16 x,br_int_16 y,br_uint_16 w,br_uint_16 h,br_uint_32 colour); void BR_PUBLIC_ENTRY BrPixelmapDirtyRectangleCopy(br_pixelmap *dst,br_pixelmap *src,br_int_16 x,br_int_16 y,br_uint_16 w,br_uint_16 h); void BR_PUBLIC_ENTRY BrPixelmapDirtyRectangleFill(br_pixelmap *dst,br_int_16 x,br_int_16 y,br_uint_16 w,br_uint_16 h,br_uint_32 colour); void BR_PUBLIC_ENTRY BrPixelmapPixelSet(br_pixelmap *dst,br_int_16 x,br_int_16 y,br_uint_32 colour); br_uint_32 BR_PUBLIC_ENTRY BrPixelmapPixelGet(br_pixelmap *dst,br_int_16 x,br_int_16 y); void BR_PUBLIC_ENTRY BrPixelmapCopy(br_pixelmap *dst,br_pixelmap *src); void BR_PUBLIC_ENTRY BrPixelmapLine(br_pixelmap *dst,br_int_16 x1, br_int_16 y1, br_int_16 x2, br_int_16 y2, br_uint_32 colour); void BR_PUBLIC_ENTRY BrPixelmapText(br_pixelmap *dst, br_int_16 x, br_int_16 y,br_uint_32 colour, br_font *font, char *text); void BR_PUBLIC_ENTRY BrPixelmapTextF(br_pixelmap *dst,br_int_16 x, br_int_16 y,br_uint_32 colour, br_font *font, char *fmt,...); void BR_PUBLIC_ENTRY BrPixelmapCopyBits(br_pixelmap *dst, br_int_16 x,br_int_16 y, br_uint_8 *src,br_uint_16 s_stride, br_uint_16 start_bit,br_uint_16 end_bit, br_uint_16 nrows,br_uint_32 colour); br_uint_16 BR_PUBLIC_ENTRY BrPixelmapTextWidth(br_pixelmap *dst, br_font *font, char *text); br_uint_16 BR_PUBLIC_ENTRY BrPixelmapTextHeight(br_pixelmap *dst, br_font *font); void BR_PUBLIC_ENTRY BrPixelmapDoubleBuffer(br_pixelmap *dst,br_pixelmap *src); /* * Backwards compatibility */ #define BrPixelmapPlot BrPixelmapPixelSet /* * File operations */ br_model * BR_PUBLIC_ENTRY BrModelLoad(char *filename); br_uint_32 BR_PUBLIC_ENTRY BrModelSave(char *filename,br_model *model); br_uint_32 BR_PUBLIC_ENTRY BrModelLoadMany(char *filename,br_model **models,br_uint_16 num); br_uint_32 BR_PUBLIC_ENTRY BrModelSaveMany(char *filename,br_model **models,br_uint_16 num); br_material * BR_PUBLIC_ENTRY BrMaterialLoad(char *filename); br_uint_32 BR_PUBLIC_ENTRY BrMaterialSave(char *filename,br_material *material); br_uint_32 BR_PUBLIC_ENTRY BrMaterialLoadMany(char *filename,br_material **materials,br_uint_16 num); br_uint_32 BR_PUBLIC_ENTRY BrMaterialSaveMany(char *filename,br_material **materials,br_uint_16 num); br_pixelmap * BR_PUBLIC_ENTRY BrPixelmapLoad(char *filename); br_uint_32 BR_PUBLIC_ENTRY BrPixelmapSave(char *filename,br_pixelmap *pixelmap); br_uint_32 BR_PUBLIC_ENTRY BrPixelmapLoadMany(char *filename,br_pixelmap **pixelmaps,br_uint_16 num); br_uint_32 BR_PUBLIC_ENTRY BrPixelmapSaveMany(char *filename,br_pixelmap **pixelmaps,br_uint_16 num); br_actor * BR_PUBLIC_ENTRY BrActorLoad(char *filename); br_uint_32 BR_PUBLIC_ENTRY BrActorSave(char *filename, br_actor *actor); br_uint_32 BR_PUBLIC_ENTRY BrActorLoadMany(char *filename,br_actor **actors,br_uint_16 num); br_uint_32 BR_PUBLIC_ENTRY BrActorSaveMany(char *filename,br_actor **actors,br_uint_16 num); /* * Lights */ void BR_PUBLIC_ENTRY BrLightEnable(br_actor *l); void BR_PUBLIC_ENTRY BrLightDisable(br_actor *l); /* * Environment */ br_actor * BR_PUBLIC_ENTRY BrEnvironmentSet(br_actor *a); /* * Clip planes */ void BR_PUBLIC_ENTRY BrClipPlaneEnable(br_actor *cp); void BR_PUBLIC_ENTRY BrClipPlaneDisable(br_actor *cp); /* * 3x4 Matrix ops. */ void BR_PUBLIC_ENTRY BrMatrix34Copy(br_matrix34 *A, br_matrix34 *b); void BR_PUBLIC_ENTRY BrMatrix34Mul(br_matrix34 *A, br_matrix34 *B, br_matrix34 *C); void BR_PUBLIC_ENTRY BrMatrix34Pre(br_matrix34 *mat , br_matrix34 *A); void BR_PUBLIC_ENTRY BrMatrix34Post(br_matrix34 *mat , br_matrix34 *A); void BR_PUBLIC_ENTRY BrMatrix34Identity(br_matrix34 *mat); void BR_PUBLIC_ENTRY BrMatrix34RotateX(br_matrix34 *mat, br_angle rx); void BR_PUBLIC_ENTRY BrMatrix34PreRotateX(br_matrix34 *mat, br_angle rx); void BR_PUBLIC_ENTRY BrMatrix34PostRotateX(br_matrix34 *mat, br_angle rx); void BR_PUBLIC_ENTRY BrMatrix34RotateY(br_matrix34 *mat, br_angle ry); void BR_PUBLIC_ENTRY BrMatrix34PreRotateY(br_matrix34 *mat, br_angle ry); void BR_PUBLIC_ENTRY BrMatrix34PostRotateY(br_matrix34 *mat, br_angle ry); void BR_PUBLIC_ENTRY BrMatrix34RotateZ(br_matrix34 *mat, br_angle rz); void BR_PUBLIC_ENTRY BrMatrix34PreRotateZ(br_matrix34 *mat, br_angle rz); void BR_PUBLIC_ENTRY BrMatrix34PostRotateZ(br_matrix34 *mat, br_angle rz); void BR_PUBLIC_ENTRY BrMatrix34Rotate(br_matrix34 *mat, br_angle r, br_vector3 *axis); void BR_PUBLIC_ENTRY BrMatrix34PreRotate(br_matrix34 *mat, br_angle r, br_vector3 *axis); void BR_PUBLIC_ENTRY BrMatrix34PostRotate(br_matrix34 *mat, br_angle r, br_vector3 *axis); void BR_PUBLIC_ENTRY BrMatrix34Translate(br_matrix34 *mat, br_scalar x, br_scalar y, br_scalar z); void BR_PUBLIC_ENTRY BrMatrix34PreTranslate(br_matrix34 *mat, br_scalar x, br_scalar y, br_scalar z); void BR_PUBLIC_ENTRY BrMatrix34PostTranslate(br_matrix34 *mat, br_scalar x, br_scalar y, br_scalar z); void BR_PUBLIC_ENTRY BrMatrix34Scale(br_matrix34 *mat, br_scalar sx, br_scalar sy, br_scalar sz); void BR_PUBLIC_ENTRY BrMatrix34PreScale(br_matrix34 *mat, br_scalar sx, br_scalar sy, br_scalar sz); void BR_PUBLIC_ENTRY BrMatrix34PostScale(br_matrix34 *mat, br_scalar sx, br_scalar sy, br_scalar sz); void BR_PUBLIC_ENTRY BrMatrix34ShearX(br_matrix34 *mat, br_scalar sy, br_scalar sz); void BR_PUBLIC_ENTRY BrMatrix34PreShearX(br_matrix34 *mat, br_scalar sy, br_scalar sz); void BR_PUBLIC_ENTRY BrMatrix34PostShearX(br_matrix34 *mat, br_scalar sy, br_scalar sz); void BR_PUBLIC_ENTRY BrMatrix34ShearY(br_matrix34 *mat, br_scalar sx, br_scalar sz); void BR_PUBLIC_ENTRY BrMatrix34PreShearY(br_matrix34 *mat, br_scalar sx, br_scalar sz); void BR_PUBLIC_ENTRY BrMatrix34PostShearY(br_matrix34 *mat, br_scalar sx, br_scalar sz); void BR_PUBLIC_ENTRY BrMatrix34ShearZ(br_matrix34 *mat, br_scalar sx, br_scalar sy); void BR_PUBLIC_ENTRY BrMatrix34PreShearZ(br_matrix34 *mat, br_scalar sx, br_scalar sy); void BR_PUBLIC_ENTRY BrMatrix34PostShearZ(br_matrix34 *mat, br_scalar sx, br_scalar sy); void BR_PUBLIC_ENTRY BrMatrix34ApplyV(br_vector3 *A, br_vector3 *B, br_matrix34 *C); void BR_PUBLIC_ENTRY BrMatrix34ApplyP(br_vector3 *A, br_vector3 *B, br_matrix34 *C); void BR_PUBLIC_ENTRY BrMatrix34Apply(br_vector3 *A, br_vector4 *B, br_matrix34 *C); void BR_PUBLIC_ENTRY BrMatrix34TApplyV(br_vector3 *A, br_vector3 *B, br_matrix34 *C); void BR_PUBLIC_ENTRY BrMatrix34TApplyP(br_vector3 *A, br_vector3 *B, br_matrix34 *C); void BR_PUBLIC_ENTRY BrMatrix34TApply(br_vector4 *A, br_vector4 *B, br_matrix34 *C); br_scalar BR_PUBLIC_ENTRY BrMatrix34Inverse(br_matrix34 *out, br_matrix34 *in); void BR_PUBLIC_ENTRY BrMatrix34LPInverse(br_matrix34 *A, br_matrix34 *B); void BR_PUBLIC_ENTRY BrMatrix34LPNormalise(br_matrix34 *A, br_matrix34 *B); void BR_PUBLIC_ENTRY BrMatrix34RollingBall(br_matrix34 *mat, int dx,int dy, int radius); /* * 4x4 Matrix ops. */ void BR_PUBLIC_ENTRY BrMatrix4Copy(br_matrix4 *A, br_matrix4 *B); void BR_PUBLIC_ENTRY BrMatrix4Mul(br_matrix4 *A, br_matrix4 *B, br_matrix4 *C); void BR_PUBLIC_ENTRY BrMatrix4Identity(br_matrix4 *mat); void BR_PUBLIC_ENTRY BrMatrix4Scale(br_matrix4 *mat, br_scalar sx, br_scalar sy, br_scalar sz); br_scalar BR_PUBLIC_ENTRY BrMatrix4Inverse(br_matrix4 *A, br_matrix4 *B); void BR_PUBLIC_ENTRY BrMatrix4Adjoint(br_matrix4 *A, br_matrix4 *B); br_scalar BR_PUBLIC_ENTRY BrMatrix4Determinant(br_matrix4 *mat); void BR_PUBLIC_ENTRY BrMatrix4Perspective(br_matrix4 *mat, br_angle field_of_view, br_scalar aspect, br_scalar hither, br_scalar yon); void BR_PUBLIC_ENTRY BrMatrix4ApplyV(br_vector4 *A, br_vector3 *B, br_matrix4 *C); void BR_PUBLIC_ENTRY BrMatrix4ApplyP(br_vector4 *A, br_vector3 *B, br_matrix4 *C); void BR_PUBLIC_ENTRY BrMatrix4Apply(br_vector4 *A, br_vector4 *B, br_matrix4 *C); void BR_PUBLIC_ENTRY BrMatrix4TApplyV(br_vector4 *A, br_vector3 *B, br_matrix4 *C); void BR_PUBLIC_ENTRY BrMatrix4TApplyP(br_vector4 *A, br_vector3 *B, br_matrix4 *C); void BR_PUBLIC_ENTRY BrMatrix4TApply(br_vector4 *A, br_vector4 *B, br_matrix4 *C); void BR_PUBLIC_ENTRY BrMatrix4Pre34(br_matrix4 *A, br_matrix34 *B); void BR_PUBLIC_ENTRY BrMatrix4Copy34(br_matrix4 *A, br_matrix34 *B); void BR_PUBLIC_ENTRY BrMatrix34Copy4(br_matrix34 *A, br_matrix4 *B); /** ** 2D Vectors **/ void BR_PUBLIC_ENTRY BrVector2Copy(br_vector2 *v1,br_vector2 * v2); void BR_PUBLIC_ENTRY BrVector2Set(br_vector2 *v1, br_scalar s1, br_scalar s2); void BR_PUBLIC_ENTRY BrVector2SetInt(br_vector2 *v1, int i1, int i2); void BR_PUBLIC_ENTRY BrVector2SetFloat(br_vector2 *v1, float f1, float f2); void BR_PUBLIC_ENTRY BrVector2Negate(br_vector2 *v1, br_vector2 *v2); void BR_PUBLIC_ENTRY BrVector2Add(br_vector2 *v1, br_vector2 *v2, br_vector2 *v3); void BR_PUBLIC_ENTRY BrVector2Accumulate(br_vector2 *v1, br_vector2 *v2); void BR_PUBLIC_ENTRY BrVector2Sub(br_vector2 *v1, br_vector2 *v2, br_vector2 *v3); void BR_PUBLIC_ENTRY BrVector2Scale(br_vector2 *v1, br_vector2 *v2, br_scalar s); void BR_PUBLIC_ENTRY BrVector2InvScale(br_vector2 *v1, br_vector2 *v2, br_scalar s); br_scalar BR_PUBLIC_ENTRY BrVector2Dot(br_vector2 *v1, br_vector2 *v2); br_scalar BR_PUBLIC_ENTRY BrVector2Length(br_vector2 *v1); br_scalar BR_PUBLIC_ENTRY BrVector2LengthSquared(br_vector2 *v1); /** ** 3D VECTORS **/ void BR_PUBLIC_ENTRY BrVector3Copy(br_vector3 *v1, br_vector2 *v2); void BR_PUBLIC_ENTRY BrVector3Set(br_vector3 *v1, br_scalar s1, br_scalar s2, br_scalar s3); void BR_PUBLIC_ENTRY BrVector3SetInt(br_vector3 *v1, int i1, int i2, int i3); void BR_PUBLIC_ENTRY BrVector3SetFloat(br_vector3 *v1, float f1, float f2, float f3); void BR_PUBLIC_ENTRY BrVector3Negate(br_vector3 *v1,br_vector3 *v2); void BR_PUBLIC_ENTRY BrVector3Add(br_vector3 *v1, br_vector3 *v2, br_vector3 *v3); void BR_PUBLIC_ENTRY BrVector3Accumulate(br_vector3 *v1, br_vector3 *v2); void BR_PUBLIC_ENTRY BrVector3Sub(br_vector3 *v1, br_vector3 *v2, br_vector3 *v3); void BR_PUBLIC_ENTRY BrVector3Scale(br_vector3 *v1, br_vector3 *v2, br_scalar s); void BR_PUBLIC_ENTRY BrVector3InvScale(br_vector3 *v1, br_vector3 *v2, br_scalar s); br_scalar BR_PUBLIC_ENTRY BrVector3Dot(br_vector3 *v1, br_vector3 *v2); void BR_PUBLIC_ENTRY BrVector3Cross(br_vector3 *v1,br_vector3 *v2,br_vector3 *v3); br_scalar BR_PUBLIC_ENTRY BrVector3Length(br_vector3 *v1); br_scalar BR_PUBLIC_ENTRY BrVector3LengthSquared(br_vector3 *v1); void BR_PUBLIC_ENTRY BrVector3Normalise(br_vector3 *v1,br_vector3 *v2); void BR_PUBLIC_ENTRY BrVector3NormaliseQuick(br_vector3 *v1,br_vector3 *v2); void BR_PUBLIC_ENTRY BrVector3NormaliseLP(br_vector3 *v1,br_vector3 *v2); /* * 2D vectors */ void BR_PUBLIC_ENTRY BrVector2Normalise(br_vector2 *v1,br_vector2 *v2); /** ** 4D Vectors **/ br_scalar BR_PUBLIC_ENTRY BrVector4Dot(br_vector4 *v1, br_vector4 *v2); void BR_PUBLIC_ENTRY BrVector4Copy(br_vector4 *v1, br_vector4 *v2); /* * Euler Angles */ br_matrix34 * BR_PUBLIC_ENTRY BrEulerToMatrix34(br_matrix34 *mat,br_euler *euler); br_euler * BR_PUBLIC_ENTRY BrMatrix34ToEuler(br_euler *euler,br_matrix34 *mat); br_matrix4 * BR_PUBLIC_ENTRY BrEulerToMatrix4(br_matrix4 *mat,br_euler *src); br_euler * BR_PUBLIC_ENTRY BrMatrix4ToEuler(br_euler *dest,br_matrix4 *mat); br_quat * BR_PUBLIC_ENTRY BrEulerToQuat(br_quat *quat,br_euler *euler); br_euler * BR_PUBLIC_ENTRY BrQuatToEuler(br_euler *euler,br_quat *quat); /* * Quaternions */ br_quat * BR_PUBLIC_ENTRY BrQuatMul(br_quat *q,br_quat *l,br_quat *r); br_quat * BR_PUBLIC_ENTRY BrQuatNormalise(br_quat *q,br_quat *qq); br_quat * BR_PUBLIC_ENTRY BrQuatInvert(br_quat *q,br_quat *qq); br_quat * BR_PUBLIC_ENTRY BrQuatSlerp(br_quat *q,br_quat *l,br_quat *r,br_scalar t, br_int_16 spins); br_matrix34 * BR_PUBLIC_ENTRY BrQuatToMatrix34(br_matrix34 *mat,br_quat *q); br_quat * BR_PUBLIC_ENTRY BrMatrix34ToQuat(br_quat *q,br_matrix34 *mat); br_matrix4 * BR_PUBLIC_ENTRY BrQuatToMatrix4(br_matrix4 *mat,br_quat *q); br_quat * BR_PUBLIC_ENTRY BrMatrix4ToQuat(br_quat *q,br_matrix4 *mat); /* * Block pool allocator */ br_pool * BR_PUBLIC_ENTRY BrPoolAllocate(int block_size, int chunk_size, br_uint_8 mem_type); void BR_PUBLIC_ENTRY BrPoolFree(br_pool *pool); void * BR_PUBLIC_ENTRY BrPoolBlockAllocate(struct br_pool *pool); void BR_PUBLIC_ENTRY BrPoolBlockFree(struct br_pool *pool,void *block); void BR_PUBLIC_ENTRY BrPoolEmpty(struct br_pool *pool); /* * Transforms */ void BR_PUBLIC_ENTRY BrTransformToMatrix34(br_matrix34 *mat,br_transform *xform); void BR_PUBLIC_ENTRY BrMatrix34ToTransform(br_transform *xform,br_matrix34 *mat); void BR_PUBLIC_ENTRY BrTransformToTransform(br_transform *dest,br_transform *src); void BR_PUBLIC_ENTRY BrMatrix34PreTransform(br_matrix34 *mat,br_transform *xform); void BR_PUBLIC_ENTRY BrMatrix34PostTransform(br_matrix34 *mat,br_transform *xform); void BR_PUBLIC_ENTRY BrMatrix4PreTransform(br_matrix4 *mat,br_transform *xform); /* * 2x3 Matrix ops. */ void BR_PUBLIC_ENTRY BrMatrix23Copy(br_matrix23 *A, br_matrix23 *b); void BR_PUBLIC_ENTRY BrMatrix23Mul(br_matrix23 *A, br_matrix23 *B, br_matrix23 *C); void BR_PUBLIC_ENTRY BrMatrix23Pre(br_matrix23 *mat , br_matrix23 *A); void BR_PUBLIC_ENTRY BrMatrix23Post(br_matrix23 *mat , br_matrix23 *A); void BR_PUBLIC_ENTRY BrMatrix23Identity(br_matrix23 *mat); void BR_PUBLIC_ENTRY BrMatrix23Rotate(br_matrix23 *mat, br_angle rz); void BR_PUBLIC_ENTRY BrMatrix23PreRotate(br_matrix23 *mat, br_angle rz); void BR_PUBLIC_ENTRY BrMatrix23PostRotate(br_matrix23 *mat, br_angle rz); void BR_PUBLIC_ENTRY BrMatrix23Translate(br_matrix23 *mat, br_scalar x, br_scalar y); void BR_PUBLIC_ENTRY BrMatrix23PreTranslate(br_matrix23 *mat, br_scalar x, br_scalar y); void BR_PUBLIC_ENTRY BrMatrix23PostTranslate(br_matrix23 *mat, br_scalar x, br_scalar y); void BR_PUBLIC_ENTRY BrMatrix23Scale(br_matrix23 *mat, br_scalar sx, br_scalar sy); void BR_PUBLIC_ENTRY BrMatrix23PreScale(br_matrix23 *mat, br_scalar sx, br_scalar sy); void BR_PUBLIC_ENTRY BrMatrix23PostScale(br_matrix23 *mat, br_scalar sx, br_scalar sy); void BR_PUBLIC_ENTRY BrMatrix23ShearX(br_matrix23 *mat, br_scalar sy); void BR_PUBLIC_ENTRY BrMatrix23PreShearX(br_matrix23 *mat, br_scalar sy); void BR_PUBLIC_ENTRY BrMatrix23PostShearX(br_matrix23 *mat, br_scalar sy); void BR_PUBLIC_ENTRY BrMatrix23ShearY(br_matrix23 *mat, br_scalar sx); void BR_PUBLIC_ENTRY BrMatrix23PreShearY(br_matrix23 *mat, br_scalar sx); void BR_PUBLIC_ENTRY BrMatrix23PostShearY(br_matrix23 *mat, br_scalar sx); void BR_PUBLIC_ENTRY BrMatrix23ApplyV(br_vector2 *A, br_vector2 *B, br_matrix23 *C); void BR_PUBLIC_ENTRY BrMatrix23ApplyP(br_vector2 *A, br_vector2 *B, br_matrix23 *C); void BR_PUBLIC_ENTRY BrMatrix23TApplyV(br_vector2 *A, br_vector2 *B, br_matrix23 *C); void BR_PUBLIC_ENTRY BrMatrix23TApplyP(br_vector2 *A, br_vector2 *B, br_matrix23 *C); br_scalar BR_PUBLIC_ENTRY BrMatrix23Inverse(br_matrix23 *out, br_matrix23 *in); void BR_PUBLIC_ENTRY BrMatrix23LPInverse(br_matrix23 *A, br_matrix23 *B); void BR_PUBLIC_ENTRY BrMatrix23LPNormalise(br_matrix23 *A, br_matrix23 *B); /* * Backwards compatibility */ #define BrMatrix34Transform BrTransformToMatrix34 #define BrTransformTransfer BrTransformToTransform /* * Picking */ typedef int BR_CALLBACK br_pick2d_cbfn( br_actor *a, br_model *model, br_material *material, br_vector3 *ray_pos, br_vector3 *ray_dir, br_scalar t_near, br_scalar t_far, void *arg); int BR_PUBLIC_ENTRY BrScenePick2D( br_actor *world, br_actor *camera, br_pixelmap *viewport, int pick_x, int pick_y, br_pick2d_cbfn *callback, void *arg ); typedef int BR_CALLBACK br_pick3d_cbfn( br_actor *a, br_model *model, br_material *material, br_matrix34 *transform, br_bounds *bounds, void *arg); int BR_PUBLIC_ENTRY BrScenePick3D( br_actor *world, br_actor *actor, br_bounds *bounds, br_pick3d_cbfn *callback, void *arg ); typedef int BR_CALLBACK br_modelpick2d_cbfn( br_model *model, br_material *material, br_vector3 *ray_pos, br_vector3 *ray_dir, br_scalar t, int face, int edge, int vertex, br_vector3 *p, br_vector2 *map, void *arg); int BR_PUBLIC_ENTRY BrModelPick2D( br_model *model, br_material *material, br_vector3 *ray_pos, br_vector3 *ray_dir, br_scalar t_near, br_scalar t_far, br_modelpick2d_cbfn *callback, void *arg); /* * Custom calback support */ br_uint_8 BR_PUBLIC_ENTRY BrOnScreenCheck(br_bounds *bounds); br_uint_8 BR_PUBLIC_ENTRY BrOriginToScreenXY(br_vector2 *screen); br_uint_32 BR_PUBLIC_ENTRY BrOriginToScreenXYZO(br_vector3 *screen); br_uint_8 BR_PUBLIC_ENTRY BrPointToScreenXY(br_vector2 *screen, br_vector3 *point); br_uint_32 BR_PUBLIC_ENTRY BrPointToScreenXYZO(br_vector3 *screen, br_vector3 *point); void BR_PUBLIC_ENTRY BrPointToScreenXYMany(br_vector2 *screens, br_vector3 *points, br_uint_32 npoints); void BR_PUBLIC_ENTRY BrPointToScreenXYZOMany(br_vector3 *screens, br_uint_32 *outcodes, br_vector3 *points, br_uint_32 npoints); void BR_PUBLIC_ENTRY BrSceneModelLight(br_model *model, br_material *default_material, br_actor *root, br_actor *a); /* * Byte swapping */ typedef float br_float; br_uint_32 BR_PUBLIC_ENTRY BrSwap32(br_uint_32 l); br_uint_16 BR_PUBLIC_ENTRY BrSwap16(br_uint_16 s); br_float BR_PUBLIC_ENTRY BrSwapFloat(br_float f); void *BR_PUBLIC_ENTRY BrSwapBlock(void *block, int count, int size); /* * Misc. support */ typedef int BR_CALLBACK br_qsort_cbfn(const void *, const void *); void BR_PUBLIC_ENTRY BrQsort(void *basep, unsigned int nelems, unsigned int size, br_qsort_cbfn *comp); /* * Diagnostic generation */ void BR_PUBLIC_ENTRY BrFailure(char *s,...); void BR_PUBLIC_ENTRY BrWarning(char *s,...); void BR_PUBLIC_ENTRY BrFatal(char *name, int line, char *s,...); void BR_PUBLIC_ENTRY _BrAssert(char *condition, char *file, unsigned line); void BR_PUBLIC_ENTRY _BrUAssert(char *condition, char *file, unsigned line); /* * Set new handlers */ br_diaghandler * BR_PUBLIC_ENTRY BrDiagHandlerSet(br_diaghandler *newdh); br_filesystem * BR_PUBLIC_ENTRY BrFilesystemSet(br_filesystem *newfs); br_allocator * BR_PUBLIC_ENTRY BrAllocatorSet(br_allocator *newal); /* * Backwards compatibility */ #define BrErrorHandlerSet BrDiagHandlerSet /* * Generic file IO */ br_uint_32 BR_PUBLIC_ENTRY BrFileAttributes(void); void * BR_PUBLIC_ENTRY BrFileOpenRead(char *name, br_size_t n_magics, br_mode_test_cbfn *mode_test, int *mode_result); void * BR_PUBLIC_ENTRY BrFileOpenWrite(char *name, int text); void BR_PUBLIC_ENTRY BrFileClose(void *f); int BR_PUBLIC_ENTRY BrFileEof(void *f); int BR_PUBLIC_ENTRY BrFileGetChar(void *f); void BR_PUBLIC_ENTRY BrFilePutChar(int c, void *f); int BR_PUBLIC_ENTRY BrFileRead(void *buf, int size, int n,void *f); int BR_PUBLIC_ENTRY BrFileWrite(void *buf, int size, int n, void *f); int BR_PUBLIC_ENTRY BrFileGetLine(char *buf, br_size_t buf_len, void * f); void BR_PUBLIC_ENTRY BrFilePutLine(char *buf, void * f); void BR_PUBLIC_ENTRY BrFileAdvance(long int count, void *f); int BR_PUBLIC_ENTRY BrFilePrintf(void *f, char *fmt, ...); /* * Data file output type (one of BR_FS_MODE_xxx) */ int BR_PUBLIC_ENTRY BrWriteModeSet(int text); /* * Generic memory allocation */ void * BR_PUBLIC_ENTRY BrMemAllocate(br_size_t size, br_uint_8 type); void BR_PUBLIC_ENTRY BrMemFree(void *block); br_size_t BR_PUBLIC_ENTRY BrMemInquire(br_uint_8 type); char * BR_PUBLIC_ENTRY BrMemStrDup(char *str); void * BR_PUBLIC_ENTRY BrMemCalloc(int nelems, br_size_t size, br_uint_8 type); /* * Resource allocation */ void * BR_PUBLIC_ENTRY BrResAllocate(void *vparent, br_size_t size, int res_class); void BR_PUBLIC_ENTRY BrResFree(void *vres); char * BR_PUBLIC_ENTRY BrResStrDup(void *vparent, char *str); void * BR_PUBLIC_ENTRY BrResAdd(void *vparent, void *vres); void * BR_PUBLIC_ENTRY BrResRemove(void *vres); br_uint_8 BR_PUBLIC_ENTRY BrResClass(void * vres); br_uint_32 BR_PUBLIC_ENTRY BrResSize(void *vres); br_uint_32 BR_PUBLIC_ENTRY BrResSizeTotal(void *vres); typedef br_uint_32 BR_CALLBACK br_resenum_cbfn(void *vres, void *arg); br_uint_32 BR_PUBLIC_ENTRY BrResChildEnum(void *vres, br_resenum_cbfn *callback, void *arg); /* * Block operations */ void BR_ASM_CALL BrBlockFill(void *dest_ptr, int value, int dwords); void BR_ASM_CALL BrBlockCopy(void *dest_ptr, void *src_ptr, int dwords); #if BR_HAS_FAR void BR_ASM_CALL BrFarBlockCopy(void __far *dest_ptr, void *src_ptr, int dwords); #endif /* * Scratchpad buffer allocation - Currenty, only one allocation * may be outstanding at any time */ void *BR_PUBLIC_ENTRY BrScratchAllocate(br_size_t size); void BR_PUBLIC_ENTRY BrScratchFree(void *scratch); br_size_t BR_PUBLIC_ENTRY BrScratchInquire(void); void BR_PUBLIC_ENTRY BrScratchFlush(void); /* * Utility "FindFailed" callbacks that can be used to automaticaly load * models/materials/maps/tables from the filesystem */ br_pixelmap * BR_CALLBACK BrMapFindFailedLoad(char *name); br_pixelmap * BR_CALLBACK BrTableFindFailedLoad(char *name); br_model * BR_CALLBACK BrModelFindFailedLoad(char *name); br_material * BR_CALLBACK BrMaterialFindFailedLoad(char *name); /* * Backwards comaptibility */ #define BrModelPrepare BrModelUpdate #define BrMaterialPrepare BrMaterialUpdate #define BrMapPrepare BrMapUpdate #define BrTablePrepare BrTableUpdate /* * Error retrieval */ br_error BR_PUBLIC_ENTRY BrGetLastError(void **valuep); #endif /* _NO_PROTOTYPES */ #ifdef __cplusplus }; #endif #endif
e6aaf925704efe80894763627c1b122390db771a
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/drivers/net/wireless/bcmdhd/dhd_flowring.c
bb15e0a6a01a81472be126edf9a217488203f9e0
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "LicenseRef-scancode-warranty-disclaimer", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
22,047
c
dhd_flowring.c
/* * Broadcom Dongle Host Driver (DHD), Flow ring specific code at top level * $Copyright Open Broadcom Corporation$ * * $Id: dhd_flowrings.c jaganlv $ */ #include <typedefs.h> #include <bcmutils.h> #include <bcmendian.h> #include <bcmdevs.h> #include <proto/ethernet.h> #include <proto/bcmevent.h> #include <dngl_stats.h> #include <dhd.h> #include <dhd_flowring.h> #include <dhd_bus.h> #include <dhd_proto.h> #include <dhd_dbg.h> #include <proto/802.1d.h> #include <pcie_core.h> #include <bcmmsgbuf.h> #include <dhd_pcie.h> static INLINE uint16 dhd_flowid_alloc(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio, char *sa, char *da); static INLINE int dhd_flowid_lookup(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio, char *sa, char *da, uint16 *flowid); int BCMFASTPATH dhd_flow_queue_overflow(flow_queue_t *queue, void *pkt); #define FLOW_QUEUE_PKT_NEXT(p) PKTLINK(p) #define FLOW_QUEUE_PKT_SETNEXT(p, x) PKTSETLINK((p), (x)) const uint8 prio2ac[8] = { 0, 1, 1, 0, 2, 2, 3, 3 }; const uint8 prio2tid[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; int BCMFASTPATH dhd_flow_queue_overflow(flow_queue_t *queue, void *pkt) { return BCME_NORESOURCE; } /* Flow ring's queue management functions */ void /* Initialize a flow ring's queue */ dhd_flow_queue_init(dhd_pub_t *dhdp, flow_queue_t *queue, int max) { ASSERT((queue != NULL) && (max > 0)); dll_init(&queue->list); queue->head = queue->tail = NULL; queue->len = 0; queue->max = max - 1; queue->failures = 0U; queue->cb = &dhd_flow_queue_overflow; } void /* Register an enqueue overflow callback handler */ dhd_flow_queue_register(flow_queue_t *queue, flow_queue_cb_t cb) { ASSERT(queue != NULL); queue->cb = cb; } int BCMFASTPATH /* Enqueue a packet in a flow ring's queue */ dhd_flow_queue_enqueue(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt) { int ret = BCME_OK; ASSERT(queue != NULL); if (queue->len >= queue->max) { queue->failures++; ret = (*queue->cb)(queue, pkt); goto done; } if (queue->head) { FLOW_QUEUE_PKT_SETNEXT(queue->tail, pkt); } else { queue->head = pkt; } FLOW_QUEUE_PKT_SETNEXT(pkt, NULL); queue->tail = pkt; /* at tail */ queue->len++; done: return ret; } void * BCMFASTPATH /* Dequeue a packet from a flow ring's queue, from head */ dhd_flow_queue_dequeue(dhd_pub_t *dhdp, flow_queue_t *queue) { void * pkt; ASSERT(queue != NULL); pkt = queue->head; /* from head */ if (pkt == NULL) { ASSERT((queue->len == 0) && (queue->tail == NULL)); goto done; } queue->head = FLOW_QUEUE_PKT_NEXT(pkt); if (queue->head == NULL) queue->tail = NULL; queue->len--; FLOW_QUEUE_PKT_SETNEXT(pkt, NULL); /* dettach packet from queue */ done: return pkt; } void BCMFASTPATH /* Reinsert a dequeued packet back at the head */ dhd_flow_queue_reinsert(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt) { if (queue->head == NULL) { queue->tail = pkt; } FLOW_QUEUE_PKT_SETNEXT(pkt, queue->head); queue->head = pkt; queue->len++; } /* Init Flow Ring specific data structures */ int dhd_flow_rings_init(dhd_pub_t *dhdp, uint32 num_flow_rings) { uint32 idx; uint32 flow_ring_table_sz; uint32 if_flow_lkup_sz; void * flowid_allocator; flow_ring_table_t *flow_ring_table; if_flow_lkup_t *if_flow_lkup = NULL; #ifdef PCIE_TX_DEFERRAL uint32 count; #endif void *lock = NULL; unsigned long flags; DHD_INFO(("%s\n", __FUNCTION__)); /* Construct a 16bit flow1d allocator */ flowid_allocator = id16_map_init(dhdp->osh, num_flow_rings - FLOW_RING_COMMON, FLOWID_RESERVED); if (flowid_allocator == NULL) { DHD_ERROR(("%s: flowid allocator init failure\n", __FUNCTION__)); return BCME_NOMEM; } /* Allocate a flow ring table, comprising of requested number of rings */ flow_ring_table_sz = (num_flow_rings * sizeof(flow_ring_node_t)); flow_ring_table = (flow_ring_table_t *)MALLOC(dhdp->osh, flow_ring_table_sz); if (flow_ring_table == NULL) { DHD_ERROR(("%s: flow ring table alloc failure\n", __FUNCTION__)); goto fail; } /* Initialize flow ring table state */ bzero((uchar *)flow_ring_table, flow_ring_table_sz); for (idx = 0; idx < num_flow_rings; idx++) { flow_ring_table[idx].status = FLOW_RING_STATUS_CLOSED; flow_ring_table[idx].flowid = (uint16)idx; flow_ring_table[idx].lock = dhd_os_spin_lock_init(dhdp->osh); if (flow_ring_table[idx].lock == NULL) { DHD_ERROR(("%s: Failed to init spinlock for queue!\n", __FUNCTION__)); goto fail; } dll_init(&flow_ring_table[idx].list); /* Initialize the per flow ring backup queue */ dhd_flow_queue_init(dhdp, &flow_ring_table[idx].queue, FLOW_RING_QUEUE_THRESHOLD); } /* Allocate per interface hash table */ if_flow_lkup_sz = sizeof(if_flow_lkup_t) * DHD_MAX_IFS; if_flow_lkup = (if_flow_lkup_t *)DHD_OS_PREALLOC(dhdp, DHD_PREALLOC_IF_FLOW_LKUP, if_flow_lkup_sz); if (if_flow_lkup == NULL) { DHD_ERROR(("%s: if flow lkup alloc failure\n", __FUNCTION__)); goto fail; } /* Initialize per interface hash table */ bzero((uchar *)if_flow_lkup, if_flow_lkup_sz); for (idx = 0; idx < DHD_MAX_IFS; idx++) { int hash_ix; if_flow_lkup[idx].status = 0; if_flow_lkup[idx].role = 0; for (hash_ix = 0; hash_ix < DHD_FLOWRING_HASH_SIZE; hash_ix++) if_flow_lkup[idx].fl_hash[hash_ix] = NULL; } #ifdef PCIE_TX_DEFERRAL count = BITS_TO_LONGS(num_flow_rings); dhdp->bus->delete_flow_map = kzalloc(count, GFP_ATOMIC); if (!dhdp->bus->delete_flow_map) { DHD_ERROR(("%s: delete_flow_map alloc failure\n", __FUNCTION__)); goto fail; } #endif lock = dhd_os_spin_lock_init(dhdp->osh); if (lock == NULL) goto fail; dhdp->flow_prio_map_type = DHD_FLOW_PRIO_AC_MAP; bcopy(prio2ac, dhdp->flow_prio_map, sizeof(uint8) * NUMPRIO); /* Now populate into dhd pub */ DHD_FLOWID_LOCK(lock, flags); dhdp->num_flow_rings = num_flow_rings; dhdp->flowid_allocator = (void *)flowid_allocator; dhdp->flow_ring_table = (void *)flow_ring_table; dhdp->if_flow_lkup = (void *)if_flow_lkup; dhdp->flowid_lock = lock; DHD_FLOWID_UNLOCK(lock, flags); DHD_INFO(("%s done\n", __FUNCTION__)); return BCME_OK; fail: #ifdef PCIE_TX_DEFERRAL if (dhdp->bus->delete_flow_map) kfree(dhdp->bus->delete_flow_map); #endif /* Destruct the per interface flow lkup table */ if (dhdp->if_flow_lkup != NULL) { DHD_OS_PREFREE(dhdp, if_flow_lkup, if_flow_lkup_sz); } if (flow_ring_table != NULL) { for (idx = 0; idx < num_flow_rings; idx++) { if (flow_ring_table[idx].lock != NULL) dhd_os_spin_lock_deinit(dhdp->osh, flow_ring_table[idx].lock); } MFREE(dhdp->osh, flow_ring_table, flow_ring_table_sz); } id16_map_fini(dhdp->osh, flowid_allocator); return BCME_NOMEM; } /* Deinit Flow Ring specific data structures */ void dhd_flow_rings_deinit(dhd_pub_t *dhdp) { uint16 idx; uint32 flow_ring_table_sz; uint32 if_flow_lkup_sz; flow_ring_table_t *flow_ring_table; unsigned long flags; void *lock; DHD_INFO(("dhd_flow_rings_deinit\n")); if (dhdp->flow_ring_table != NULL) { ASSERT(dhdp->num_flow_rings > 0); DHD_FLOWID_LOCK(dhdp->flowid_lock, flags); flow_ring_table = (flow_ring_table_t *)dhdp->flow_ring_table; dhdp->flow_ring_table = NULL; DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags); for (idx = 0; idx < dhdp->num_flow_rings; idx++) { if (flow_ring_table[idx].active) { dhd_bus_clean_flow_ring(dhdp->bus, &flow_ring_table[idx]); } ASSERT(flow_queue_empty(&flow_ring_table[idx].queue)); /* Deinit flow ring queue locks before destroying flow ring table */ dhd_os_spin_lock_deinit(dhdp->osh, flow_ring_table[idx].lock); flow_ring_table[idx].lock = NULL; } /* Destruct the flow ring table */ flow_ring_table_sz = dhdp->num_flow_rings * sizeof(flow_ring_table_t); MFREE(dhdp->osh, flow_ring_table, flow_ring_table_sz); } DHD_FLOWID_LOCK(dhdp->flowid_lock, flags); /* Destruct the per interface flow lkup table */ if (dhdp->if_flow_lkup != NULL) { if_flow_lkup_sz = sizeof(if_flow_lkup_t) * DHD_MAX_IFS; bzero(dhdp->if_flow_lkup, sizeof(if_flow_lkup_sz)); DHD_OS_PREFREE(dhdp, dhdp->if_flow_lkup, if_flow_lkup_sz); dhdp->if_flow_lkup = NULL; } #ifdef PCIE_TX_DEFERRAL if (dhdp->bus->delete_flow_map) kfree(dhdp->bus->delete_flow_map); #endif /* Destruct the flowid allocator */ if (dhdp->flowid_allocator != NULL) dhdp->flowid_allocator = id16_map_fini(dhdp->osh, dhdp->flowid_allocator); dhdp->num_flow_rings = 0U; lock = dhdp->flowid_lock; dhdp->flowid_lock = NULL; DHD_FLOWID_UNLOCK(lock, flags); dhd_os_spin_lock_deinit(dhdp->osh, lock); } uint8 dhd_flow_rings_ifindex2role(dhd_pub_t *dhdp, uint8 ifindex) { if_flow_lkup_t *if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup; ASSERT(if_flow_lkup); return if_flow_lkup[ifindex].role; } #ifdef WLTDLS bool is_tdls_destination(dhd_pub_t *dhdp, uint8 *da) { tdls_peer_node_t *cur = dhdp->peer_tbl.node; while (cur != NULL) { if (!memcmp(da, cur->addr, ETHER_ADDR_LEN)) { return TRUE; } cur = cur->next; } return FALSE; } #endif /* WLTDLS */ /* For a given interface, search the hash table for a matching flow */ uint16 dhd_flowid_find(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio, char *sa, char *da) { int hash; bool ismcast = FALSE; flow_hash_info_t *cur; if_flow_lkup_t *if_flow_lkup; unsigned long flags; DHD_FLOWID_LOCK(dhdp->flowid_lock, flags); if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup; if (DHD_IF_ROLE_STA(if_flow_lkup[ifindex].role)) { #ifdef WLTDLS if (dhdp->peer_tbl.tdls_peer_count && !(ETHER_ISMULTI(da)) && is_tdls_destination(dhdp, da)) { hash = DHD_FLOWRING_HASHINDEX(da, prio); cur = if_flow_lkup[ifindex].fl_hash[hash]; while (cur != NULL) { if (!memcmp(cur->flow_info.da, da, ETHER_ADDR_LEN)) { DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags); return cur->flowid; } cur = cur->next; } DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags); return FLOWID_INVALID; } #endif /* WLTDLS */ cur = if_flow_lkup[ifindex].fl_hash[prio]; if (cur) { DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags); return cur->flowid; } } else { if (ETHER_ISMULTI(da)) { ismcast = TRUE; hash = 0; } else { hash = DHD_FLOWRING_HASHINDEX(da, prio); } cur = if_flow_lkup[ifindex].fl_hash[hash]; while (cur) { if ((ismcast && ETHER_ISMULTI(cur->flow_info.da)) || (!memcmp(cur->flow_info.da, da, ETHER_ADDR_LEN) && (cur->flow_info.tid == prio))) { DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags); return cur->flowid; } cur = cur->next; } } DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags); return FLOWID_INVALID; } /* Allocate Flow ID */ static INLINE uint16 dhd_flowid_alloc(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio, char *sa, char *da) { flow_hash_info_t *fl_hash_node, *cur; if_flow_lkup_t *if_flow_lkup; int hash; uint16 flowid; unsigned long flags; fl_hash_node = (flow_hash_info_t *) MALLOC(dhdp->osh, sizeof(flow_hash_info_t)); memcpy(fl_hash_node->flow_info.da, da, sizeof(fl_hash_node->flow_info.da)); DHD_FLOWID_LOCK(dhdp->flowid_lock, flags); ASSERT(dhdp->flowid_allocator != NULL); flowid = id16_map_alloc(dhdp->flowid_allocator); DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags); if (flowid == FLOWID_INVALID) { MFREE(dhdp->osh, fl_hash_node, sizeof(flow_hash_info_t)); DHD_ERROR(("%s: cannot get free flowid \n", __FUNCTION__)); return FLOWID_INVALID; } fl_hash_node->flowid = flowid; fl_hash_node->flow_info.tid = prio; fl_hash_node->flow_info.ifindex = ifindex; fl_hash_node->next = NULL; DHD_FLOWID_LOCK(dhdp->flowid_lock, flags); if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup; if (DHD_IF_ROLE_STA(if_flow_lkup[ifindex].role)) { /* For STA non TDLS dest we allocate entry based on prio only */ #ifdef WLTDLS if (dhdp->peer_tbl.tdls_peer_count && (is_tdls_destination(dhdp, da))) { hash = DHD_FLOWRING_HASHINDEX(da, prio); cur = if_flow_lkup[ifindex].fl_hash[hash]; if (cur) { while (cur->next) { cur = cur->next; } cur->next = fl_hash_node; } else { if_flow_lkup[ifindex].fl_hash[hash] = fl_hash_node; } } else #endif /* WLTDLS */ if_flow_lkup[ifindex].fl_hash[prio] = fl_hash_node; } else { /* For bcast/mcast assign first slot in in interface */ hash = ETHER_ISMULTI(da) ? 0 : DHD_FLOWRING_HASHINDEX(da, prio); cur = if_flow_lkup[ifindex].fl_hash[hash]; if (cur) { while (cur->next) { cur = cur->next; } cur->next = fl_hash_node; } else if_flow_lkup[ifindex].fl_hash[hash] = fl_hash_node; } DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags); DHD_INFO(("%s: allocated flowid %d\n", __FUNCTION__, fl_hash_node->flowid)); return fl_hash_node->flowid; } /* Get flow ring ID, if not present try to create one */ static INLINE int dhd_flowid_lookup(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio, char *sa, char *da, uint16 *flowid) { uint16 id; flow_ring_node_t *flow_ring_node; flow_ring_table_t *flow_ring_table; unsigned long flags; DHD_INFO(("%s\n", __FUNCTION__)); if (!dhdp->flow_ring_table) return BCME_ERROR; flow_ring_table = (flow_ring_table_t *)dhdp->flow_ring_table; id = dhd_flowid_find(dhdp, ifindex, prio, sa, da); if (id == FLOWID_INVALID) { if_flow_lkup_t *if_flow_lkup; if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup; if (!if_flow_lkup[ifindex].status) return BCME_ERROR; id = dhd_flowid_alloc(dhdp, ifindex, prio, sa, da); if (id == FLOWID_INVALID) { DHD_ERROR(("%s: alloc flowid ifindex %u status %u\n", __FUNCTION__, ifindex, if_flow_lkup[ifindex].status)); return BCME_ERROR; } /* register this flowid in dhd_pub */ dhd_add_flowid(dhdp, ifindex, prio, da, id); } ASSERT(id < dhdp->num_flow_rings); flow_ring_node = (flow_ring_node_t *) &flow_ring_table[id]; DHD_FLOWRING_LOCK(flow_ring_node->lock, flags); if (flow_ring_node->active) { DHD_FLOWRING_UNLOCK(flow_ring_node->lock, flags); *flowid = id; return BCME_OK; } /* Init Flow info */ memcpy(flow_ring_node->flow_info.sa, sa, sizeof(flow_ring_node->flow_info.sa)); memcpy(flow_ring_node->flow_info.da, da, sizeof(flow_ring_node->flow_info.da)); flow_ring_node->flow_info.tid = prio; flow_ring_node->flow_info.ifindex = ifindex; flow_ring_node->active = TRUE; flow_ring_node->status = FLOW_RING_STATUS_PENDING; DHD_FLOWRING_UNLOCK(flow_ring_node->lock, flags); DHD_FLOWID_LOCK(dhdp->flowid_lock, flags); dll_prepend(&dhdp->bus->const_flowring, &flow_ring_node->list); DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags); /* Create and inform device about the new flow */ if (dhd_bus_flow_ring_create_request(dhdp->bus, (void *)flow_ring_node) != BCME_OK) { DHD_ERROR(("%s: create error %d\n", __FUNCTION__, id)); return BCME_ERROR; } *flowid = id; return BCME_OK; } /* Update flowid information on the packet */ int BCMFASTPATH dhd_flowid_update(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio, void *pktbuf) { uint8 *pktdata = (uint8 *)PKTDATA(dhdp->osh, pktbuf); struct ether_header *eh = (struct ether_header *)pktdata; uint16 flowid; if (dhd_bus_is_txmode_push(dhdp->bus)) return BCME_OK; ASSERT(ifindex < DHD_MAX_IFS); if (ifindex >= DHD_MAX_IFS) { return BCME_BADARG; } if (!dhdp->flowid_allocator) { DHD_ERROR(("%s: Flow ring not intited yet \n", __FUNCTION__)); return BCME_ERROR; } if (dhd_flowid_lookup(dhdp, ifindex, prio, eh->ether_shost, eh->ether_dhost, &flowid) != BCME_OK) { return BCME_ERROR; } DHD_INFO(("%s: prio %d flowid %d\n", __FUNCTION__, prio, flowid)); /* Tag the packet with flowid */ DHD_PKTTAG_SET_FLOWID((dhd_pkttag_fr_t *)PKTTAG(pktbuf), flowid); return BCME_OK; } void dhd_flowid_free(dhd_pub_t *dhdp, uint8 ifindex, uint16 flowid) { int hashix; bool found = FALSE; flow_hash_info_t *cur, *prev; if_flow_lkup_t *if_flow_lkup; unsigned long flags; DHD_FLOWID_LOCK(dhdp->flowid_lock, flags); if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup; for (hashix = 0; hashix < DHD_FLOWRING_HASH_SIZE; hashix++) { cur = if_flow_lkup[ifindex].fl_hash[hashix]; if (cur) { if (cur->flowid == flowid) { found = TRUE; } prev = NULL; while (!found && cur) { if (cur->flowid == flowid) { found = TRUE; break; } prev = cur; cur = cur->next; } if (found) { if (!prev) { if_flow_lkup[ifindex].fl_hash[hashix] = cur->next; } else { prev->next = cur->next; } /* deregister flowid from dhd_pub. */ dhd_del_flowid(dhdp, ifindex, flowid); id16_map_free(dhdp->flowid_allocator, flowid); DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags); MFREE(dhdp->osh, cur, sizeof(flow_hash_info_t)); return; } } } DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags); DHD_ERROR(("%s: could not free flow ring hash entry flowid %d\n", __FUNCTION__, flowid)); } /* Delete all Flow rings assocaited with the given Interface */ void dhd_flow_rings_delete(dhd_pub_t *dhdp, uint8 ifindex) { uint32 id; flow_ring_table_t *flow_ring_table; DHD_INFO(("%s: ifindex %u\n", __FUNCTION__, ifindex)); ASSERT(ifindex < DHD_MAX_IFS); if (ifindex >= DHD_MAX_IFS) return; if (!dhdp->flow_ring_table) return; flow_ring_table = (flow_ring_table_t *)dhdp->flow_ring_table; for (id = 0; id < dhdp->num_flow_rings; id++) { if (flow_ring_table[id].active && (flow_ring_table[id].flow_info.ifindex == ifindex) && (flow_ring_table[id].status != FLOW_RING_STATUS_DELETE_PENDING)) { DHD_INFO(("%s: deleting flowid %d\n", __FUNCTION__, flow_ring_table[id].flowid)); dhd_bus_flow_ring_delete_request(dhdp->bus, (void *) &flow_ring_table[id]); } } } /* Delete flow/s for given peer address */ void dhd_flow_rings_delete_for_peer(dhd_pub_t *dhdp, uint8 ifindex, char *addr) { uint32 id; flow_ring_table_t *flow_ring_table; DHD_ERROR(("%s: ifindex %u\n", __FUNCTION__, ifindex)); ASSERT(ifindex < DHD_MAX_IFS); if (ifindex >= DHD_MAX_IFS) return; if (!dhdp->flow_ring_table) return; flow_ring_table = (flow_ring_table_t *)dhdp->flow_ring_table; for (id = 0; id < dhdp->num_flow_rings; id++) { if (flow_ring_table[id].active && (flow_ring_table[id].flow_info.ifindex == ifindex) && (!memcmp(flow_ring_table[id].flow_info.da, addr, ETHER_ADDR_LEN)) && (flow_ring_table[id].status != FLOW_RING_STATUS_DELETE_PENDING)) { DHD_INFO(("%s: deleting flowid %d\n", __FUNCTION__, flow_ring_table[id].flowid)); dhd_bus_flow_ring_delete_request(dhdp->bus, (void *) &flow_ring_table[id]); } } } /* Handle Interface ADD, DEL operations */ void dhd_update_interface_flow_info(dhd_pub_t *dhdp, uint8 ifindex, uint8 op, uint8 role) { if_flow_lkup_t *if_flow_lkup; unsigned long flags; ASSERT(ifindex < DHD_MAX_IFS); if (ifindex >= DHD_MAX_IFS) return; DHD_INFO(("%s: ifindex %u op %u role is %u \n", __FUNCTION__, ifindex, op, role)); if (!dhdp->flowid_allocator) { DHD_ERROR(("%s: Flow ring not intited yet \n", __FUNCTION__)); return; } DHD_FLOWID_LOCK(dhdp->flowid_lock, flags); if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup; if (op == WLC_E_IF_ADD || op == WLC_E_IF_CHANGE) { if_flow_lkup[ifindex].role = role; if (!(DHD_IF_ROLE_STA(role))) { if_flow_lkup[ifindex].status = TRUE; DHD_INFO(("%s: Mcast Flow ring for ifindex %d role is %d \n", __FUNCTION__, ifindex, role)); /* Create Mcast Flow */ } } else if (op == WLC_E_IF_DEL) { if_flow_lkup[ifindex].status = FALSE; DHD_INFO(("%s: cleanup all Flow rings for ifindex %d role is %d \n", __FUNCTION__, ifindex, role)); } DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags); } /* Handle a STA interface link status update */ int dhd_update_interface_link_status(dhd_pub_t *dhdp, uint8 ifindex, uint8 status) { if_flow_lkup_t *if_flow_lkup; unsigned long flags; ASSERT(ifindex < DHD_MAX_IFS); if (ifindex >= DHD_MAX_IFS) return BCME_BADARG; DHD_INFO(("%s: ifindex %d status %d\n", __FUNCTION__, ifindex, status)); DHD_FLOWID_LOCK(dhdp->flowid_lock, flags); if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup; if (DHD_IF_ROLE_STA(if_flow_lkup[ifindex].role)) { if (status) if_flow_lkup[ifindex].status = TRUE; else if_flow_lkup[ifindex].status = FALSE; } DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags); return BCME_OK; } /* Update flow priority mapping */ int dhd_update_flow_prio_map(dhd_pub_t *dhdp, uint8 map) { uint16 flowid; flow_ring_node_t *flow_ring_node; if (map > DHD_FLOW_PRIO_TID_MAP) return BCME_BADOPTION; /* Check if we need to change prio map */ if (map == dhdp->flow_prio_map_type) return BCME_OK; /* If any ring is active we cannot change priority mapping for flow rings */ for (flowid = 0; flowid < dhdp->num_flow_rings; flowid++) { flow_ring_node = DHD_FLOW_RING(dhdp, flowid); if (flow_ring_node->active) return BCME_EPERM; } /* Infor firmware about new mapping type */ if (BCME_OK != dhd_flow_prio_map(dhdp, &map, TRUE)) return BCME_ERROR; /* update internal structures */ dhdp->flow_prio_map_type = map; if (dhdp->flow_prio_map_type == DHD_FLOW_PRIO_TID_MAP) bcopy(prio2tid, dhdp->flow_prio_map, sizeof(uint8) * NUMPRIO); else bcopy(prio2ac, dhdp->flow_prio_map, sizeof(uint8) * NUMPRIO); return BCME_OK; } /* Set/Get flwo ring priority map */ int dhd_flow_prio_map(dhd_pub_t *dhd, uint8 *map, bool set) { uint8 iovbuf[24]; if (!set) { bcm_mkiovar("bus:fl_prio_map", NULL, 0, (char*)iovbuf, sizeof(iovbuf)); if (dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, iovbuf, sizeof(iovbuf), FALSE, 0) < 0) { DHD_ERROR(("%s: failed to get fl_prio_map\n", __FUNCTION__)); return BCME_ERROR; } *map = iovbuf[0]; return BCME_OK; } bcm_mkiovar("bus:fl_prio_map", (char *)map, 4, (char*)iovbuf, sizeof(iovbuf)); if (dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0) < 0) { DHD_ERROR(("%s: failed to set fl_prio_map \n", __FUNCTION__)); return BCME_ERROR; } return BCME_OK; }
768b7343374536bdcf0da629217a77c391ae4752
fa2ab8259f2ace71e0e6d58546cc097e03b863b0
/bundle.h
cf3eef4f3d0940e0cc3654bb2bed50fadf96c972
[]
no_license
taviso/lotusdrv
72f2de8aa570f75031e6bd2b36577dfcba71d7ad
fb6ebcafc44e3917e62390f5ed60f1066ff0da6f
refs/heads/master
2023-07-26T00:48:46.255373
2022-05-21T21:01:25
2022-05-21T21:01:25
343,472,612
143
2
null
2022-05-21T21:01:26
2021-03-01T15:55:49
C
UTF-8
C
false
false
91
h
bundle.h
#ifndef __BUNDLE_H #define __BUNDLE_H int ParseConfig(struct BDLHDR far *bdlptr); #endif
f56c56e3d801f1f32a30c1616efcdb854a726d7a
0cc343d927d5db6693006018986715c43acab961
/examples/linking/include_paths/sub1/sub2/header.h
626e141973d3cf3ea679cc86621bf96a81c91c49
[ "MIT" ]
permissive
verifast/verifast
ec0101fc4a69bd33c5f66be4444169c4e060ead8
d152da790c7ebf72ce616533a6c83082629adbdb
refs/heads/master
2023-08-25T00:13:51.464802
2023-08-13T10:00:00
2023-08-13T10:00:00
14,519,163
325
64
NOASSERTION
2023-08-10T21:16:08
2013-11-19T08:57:02
OCaml
UTF-8
C
false
false
94
h
header.h
//@ predicate unsound() = false; void func(); //@ requires true; //@ ensures unsound();
20eb7c835410b656b38c7fe3f37fabdbd7bb90a0
4578be5ff20640cd0940faa27901489daa471ffe
/S03 - Estrutura de Dados/2015.2 - Ernani Leite/Listas/Lista_02_Estruturas/Q_04/caixa.c
3ab5d0f9c13b6f88c5d11b5a6429f940462e2d93
[]
no_license
CAECOMP/provas
cd31c48a912ad5e73f5bf8b826db40cf895f46b1
3f5eb4ec63fc91ad2c2e4ae6e5b3ac87c09ca916
refs/heads/master
2023-07-07T11:53:38.798374
2023-04-27T03:13:57
2023-04-27T03:13:57
55,001,094
125
83
null
2023-07-04T21:21:05
2016-03-29T18:38:41
HTML
ISO-8859-1
C
false
false
3,017
c
caixa.c
#include <stdio.h> #include <stdlib.h> #include "caixa.h" void lerCaixa(Caixa *ptr){ printf("Digite a situacao:(x-Ocupado, *-apagado)\n"); getchar(); scanf("%c", &ptr->situacao); printf("Digite a data:(Dia mes ano)\n"); scanf("%d", &ptr->data.dia); scanf("%d", &ptr->data.mes); scanf("%d", &ptr->data.ano); printf("Digite o tipo de lancamento:(D-Despesa e R-Receita)\n"); getchar(); scanf("%c", &ptr->tipo); printf("Digite o valor:(R$)\n "); scanf("%f", &ptr->valor); } void mostraLista(Caixa *ptr, int dimensao){ int i; for(i = 0; i < dimensao; i++){ printf("\n------------------------\n"); printf("Caixa %d\n", i); mostrarCaixa(ptr+i); printf("\n------------------------\n"); } } int recordVector(const char *filename, Caixa *ptr, int dim){ FILE *output; if((output = fopen(filename, "ab")) == NULL){ return FALSE; } fwrite((Caixa *)ptr, sizeof(Caixa), dim, output); fclose(output); return TRUE; } void mostrarCaixa(Caixa *ptr){ printf("Situação: %c\n", ptr->situacao); printf("Data %d/%d/%d\n", ptr->data.dia, ptr->data.mes, ptr->data.ano); } int retornaDimensao(const char *filename) { char ch; int i = 0; FILE *fd; if ((fd = fopen(filename, "rb")) == NULL) { printf("O arquivo não pode ser aberto"); return 0; } while (!feof(fd)) { ch = getc(fd); i++; } fclose(fd); return i/sizeof(Caixa); } int loadVector(const char *filename, Caixa *ptr, int dim){ FILE *input; if((input = fopen(filename, "rb")) == NULL){ return FALSE; } fread((Caixa *)ptr, sizeof(Caixa), dim, input); fclose(input); return TRUE; } void lerLista(Caixa *ptr, int dimensao){ int i; for(i = 0; i < dimensao; i++){ printf("Ler caixa %d:\n", i); lerCaixa(ptr+i); } } void relatorio(Caixa *ptr, int dimensao){ int i; int despesasJaneiro = 0; float saldo = 0; float valor = 0; float valorReceita = 0; float valorDespesa = 0; float valorAno = 0; float despesas = 0; float receitas = 0; for(i = 0; i < dimensao; i++){ if((ptr+i)->data.mes <= 3 && (ptr+i)->data.ano <= 2005){ if((ptr+i)->tipo == 'D') despesas += (ptr+i)->valor; if((ptr+i)->tipo == 'R') receitas += (ptr+i)->valor; } if((ptr+i)->data.ano == 2005){ if((ptr+i)->tipo == 'R') valorReceita += (ptr+i)->valor; if((ptr+i)->tipo == 'D'){ valorDespesa += (ptr+i)->valor; if((ptr+i)->data.mes == 1) despesasJaneiro++; } } } valor = receitas - despesas; printf("A quantidade de lançamentos do tipo despesa realizados no mês de janeiro de 2005: %d\n",despesasJaneiro); printf("A soma dos lançamentos de despesa %.2f, de receita %.2f realizados no ano de 2005\n", valorDespesa, valorReceita); printf("Saldo de janeiro de 2005: %.2f\n", valor); }
147d6fe779f754e18cbd57fde1f9d1a3c4dd75c7
79d343002bb63a44f8ab0dbac0c9f4ec54078c3a
/lib/libc/include/m68k-linux-musl/bits/user.h
a18c06ced3bf93b4c1f6d8a7da369bd59223b0fb
[ "MIT" ]
permissive
ziglang/zig
4aa75d8d3bcc9e39bf61d265fd84b7f005623fc5
f4c9e19bc3213c2bc7e03d7b06d7129882f39f6c
refs/heads/master
2023-08-31T13:16:45.980913
2023-08-31T05:50:29
2023-08-31T05:50:29
40,276,274
25,560
2,399
MIT
2023-09-14T21:09:50
2015-08-06T00:51:28
Zig
UTF-8
C
false
false
877
h
user.h
#undef __WORDSIZE #define __WORDSIZE 32 struct user_m68kfp_struct { unsigned long fpregs[24], fpcntl[3]; }; struct user_regs_struct { long d1, d2, d3, d4, d5, d6, d7; long a0, a1, a2, a3, a4, a5, a6; long d0, usp, orig_d0; short stkadj, sr; long pc; short fmtvec, __pad; }; struct user { struct user_regs_struct regs; int u_fpvalid; struct user_m68kfp_struct m68kfp; unsigned long u_tsize, u_dsize, u_ssize, start_code, start_stack; long signal; int reserved; unsigned long u_ar0; struct user_m68kfp_struct *u_fpstate; unsigned long magic; char u_comm[32]; }; #define ELF_NGREG 20 typedef unsigned long elf_greg_t; typedef elf_greg_t elf_gregset_t[ELF_NGREG]; typedef struct user_m68kfp_struct elf_fpregset_t; #define NBPG 4096 #define UPAGES 1 #define HOST_TEXT_START_ADDR (u.start_code) #define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG)
be69eace2b8305e51f2e8fdad4157de512d56766
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/drivers/staging/vme/devices/vme_pio2_cntr.c
6335471faa3687f4adba5a3fd6f67ed079172f66
[ "LicenseRef-scancode-free-unknown", "Apache-2.0", "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
1,706
c
vme_pio2_cntr.c
/* * GE PIO2 Counter Driver * * Author: Martyn Welch <martyn.welch@ge.com> * Copyright 2009 GE Intelligent Platforms Embedded Systems, Inc. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * The PIO-2 has 6 counters, currently this code just disables the interrupts * and leaves them alone. * */ #include <linux/device.h> #include <linux/types.h> #include <linux/gpio.h> #include <linux/vme.h> #include "vme_pio2.h" static int pio2_cntr_irq_set(struct pio2_card *card, int id) { int retval; u8 data; data = PIO2_CNTR_SC_DEV[id] | PIO2_CNTR_RW_BOTH | card->cntr[id].mode; retval = vme_master_write(card->window, &data, 1, PIO2_CNTR_CTRL[id]); if (retval < 0) return retval; data = card->cntr[id].count & 0xFF; retval = vme_master_write(card->window, &data, 1, PIO2_CNTR_DATA[id]); if (retval < 0) return retval; data = (card->cntr[id].count >> 8) & 0xFF; retval = vme_master_write(card->window, &data, 1, PIO2_CNTR_DATA[id]); if (retval < 0) return retval; return 0; } int pio2_cntr_reset(struct pio2_card *card) { int i, retval = 0; u8 reg; /* Clear down all timers */ for (i = 0; i < 6; i++) { card->cntr[i].mode = PIO2_CNTR_MODE5; card->cntr[i].count = 0; retval = pio2_cntr_irq_set(card, i); if (retval < 0) return retval; } /* Ensure all counter interrupts are cleared */ do { retval = vme_master_read(card->window, &reg, 1, PIO2_REGS_INT_STAT_CNTR); if (retval < 0) return retval; } while (reg != 0); return retval; }
aadae0d31d56a7b2745e46b26d9f97a556cd6957
e910318d01528d82040507a49eeeb8dade45b31f
/ports/stm32/boards/stm32h7xx_hal_conf_base.h
c07ae93e37e04e2802a95b9b9ec5b111093d05b5
[ "MIT" ]
permissive
pfalcon/pycopy
e844480a5e5cd463530328889daed2ba87552b8a
3ac90ae9c3c6bbebfba9cada2d37025e35c62796
refs/heads/pfalcon
2023-08-30T09:39:52.290147
2022-09-08T16:42:38
2022-09-08T16:42:38
15,507,576
753
71
MIT
2021-05-08T04:59:21
2013-12-29T11:38:47
C
UTF-8
C
false
false
3,551
h
stm32h7xx_hal_conf_base.h
/* * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * * Copyright (c) 2019 Damien P. George * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #ifndef MICROPY_INCLUDED_STM32H7XX_HAL_CONF_BASE_H #define MICROPY_INCLUDED_STM32H7XX_HAL_CONF_BASE_H // Include various HAL modules for convenience #include "stm32h7xx_hal_dma.h" #include "stm32h7xx_hal_mdma.h" #include "stm32h7xx_hal_adc.h" #include "stm32h7xx_hal_cortex.h" #include "stm32h7xx_hal_crc.h" #include "stm32h7xx_hal_dac.h" #include "stm32h7xx_hal_dcmi.h" #include "stm32h7xx_hal_fdcan.h" #include "stm32h7xx_hal_flash.h" #include "stm32h7xx_hal_gpio.h" #include "stm32h7xx_hal_hash.h" #include "stm32h7xx_hal_hcd.h" #include "stm32h7xx_hal_i2c.h" #include "stm32h7xx_hal_i2s.h" #include "stm32h7xx_hal_iwdg.h" #include "stm32h7xx_hal_pcd.h" #include "stm32h7xx_hal_pwr.h" #include "stm32h7xx_hal_rcc.h" #include "stm32h7xx_hal_rtc.h" #include "stm32h7xx_hal_sd.h" #include "stm32h7xx_hal_sdram.h" #include "stm32h7xx_hal_spi.h" #include "stm32h7xx_hal_tim.h" #include "stm32h7xx_hal_uart.h" #include "stm32h7xx_hal_usart.h" #include "stm32h7xx_hal_wwdg.h" #include "stm32h7xx_ll_adc.h" #include "stm32h7xx_ll_pwr.h" #include "stm32h7xx_ll_rtc.h" #include "stm32h7xx_ll_usart.h" // Enable various HAL modules #define HAL_ADC_MODULE_ENABLED #define HAL_CORTEX_MODULE_ENABLED #define HAL_CRC_MODULE_ENABLED #define HAL_DAC_MODULE_ENABLED #define HAL_DCMI_MODULE_ENABLED #define HAL_DMA_MODULE_ENABLED #define HAL_FDCAN_MODULE_ENABLED #define HAL_FLASH_MODULE_ENABLED #define HAL_GPIO_MODULE_ENABLED #define HAL_HASH_MODULE_ENABLED #define HAL_HCD_MODULE_ENABLED #define HAL_I2C_MODULE_ENABLED #define HAL_I2S_MODULE_ENABLED #define HAL_IWDG_MODULE_ENABLED #define HAL_PCD_MODULE_ENABLED #define HAL_PWR_MODULE_ENABLED #define HAL_RCC_MODULE_ENABLED #define HAL_RTC_MODULE_ENABLED #define HAL_SD_MODULE_ENABLED #define HAL_SDRAM_MODULE_ENABLED #define HAL_SPI_MODULE_ENABLED #define HAL_TIM_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED #define HAL_USART_MODULE_ENABLED #define HAL_WWDG_MODULE_ENABLED // Oscillator values in Hz #define CSI_VALUE (4000000) #define HSI_VALUE (64000000) // SysTick has the highest priority #define TICK_INT_PRIORITY (0x00) // Miscellaneous HAL settings #define USE_RTOS 0 #define USE_SD_TRANSCEIVER 0 #define USE_SPI_CRC 1 // HAL parameter assertions are disabled #define assert_param(expr) ((void)0) #endif // MICROPY_INCLUDED_STM32H7XX_HAL_CONF_BASE_H
ed6d5fba155a50e0ec9f3aab5fce4ce143878cec
78297bc868d588dd7a16cfea059ef7365ba18622
/lib/api/include/irods/subStructFileReaddir.h
c5ed0e9fb3f5723d565886a68aac7bd03de971c8
[ "BSD-3-Clause" ]
permissive
irods/irods
ab72a41fdf05a4a905c3e3a97bb7ba3c2a6ae52d
f3ccaa842218e477395ebcf553639134433b63ee
refs/heads/main
2023-09-01T20:12:33.322002
2023-08-23T18:22:59
2023-08-31T13:41:31
14,724,975
381
167
NOASSERTION
2023-09-11T18:18:14
2013-11-26T18:10:18
C++
UTF-8
C
false
false
299
h
subStructFileReaddir.h
#ifndef SUB_STRUCT_FILE_READDIR_H__ #define SUB_STRUCT_FILE_READDIR_H__ #include "irods/rodsType.h" #include "irods/rcConnect.h" #include "irods/subStructFileRead.h" int rcSubStructFileReaddir( rcComm_t *conn, subStructFileFdOprInp_t *subStructFileReaddirInp, rodsDirent_t **rodsDirent ); #endif
358030263924742368c96fec93cb5284407e9c8d
59864cbd213b5da6f50d6255b0a021564b3d5bd4
/challenges/WordCompletion/pov_1/pov.c
aea49760f3873a5ecfa01bd3dff4c45f33c988f7
[ "MIT", "BSD-3-Clause", "LicenseRef-scancode-unknown", "BSD-2-Clause" ]
permissive
trailofbits/cb-multios
8af96a4fbc3b34644367faa135347f88e0e0d0a3
810d7b24b1f62f56ef49b148fe155b0d0629cad2
refs/heads/master
2023-09-05T03:56:20.229403
2022-12-27T15:47:54
2022-12-27T15:47:54
41,688,943
522
133
MIT
2023-06-29T02:47:13
2015-08-31T17:04:31
C
UTF-8
C
false
false
21,505
c
pov.c
#include "libpov.h" int main(int cgc_argc, char *cgc_argv[]) { cgc_negotiate_type1(0x0, 0x0, 0); do { unsigned char *read_00000; unsigned int read_00000_len; unsigned int read_00000_ptr = 0; //**** delimited read static unsigned char read_00000_delim[] = "\x0a"; read_00000 = NULL; read_00000_len = 0; int read_00000_res = cgc_delimited_read(0, &read_00000, &read_00000_len, read_00000_delim, 1); if (read_00000_res) {} //silence unused variable warning //**** read match data static unsigned char match_00000_00000[] = "\x50\x6c\x65\x61\x73\x65\x20\x45\x6e\x74\x65\x72\x20\x61\x20\x32" "\x20\x44\x69\x67\x69\x74\x20\x4e\x75\x6d\x62\x65\x72\x0a"; read_00000_ptr += cgc_data_match(read_00000 + read_00000_ptr, read_00000_len - read_00000_ptr, match_00000_00000, 30); cgc_free(read_00000); if (read_00000_ptr) {} //silence unused variable warning if any } while (0); do { //*** writing data static unsigned char write_00000_00000[] = "\x36\x31\x0a"; static unsigned int write_00000_00000_len = 3; unsigned char *write_00000 = NULL; unsigned int write_00000_len = 0; write_00000 = cgc_append_buf(write_00000, &write_00000_len, write_00000_00000, write_00000_00000_len); if (write_00000_len > 0) { cgc_transmit_all(1, write_00000, write_00000_len); } cgc_free(write_00000); } while (0); do { unsigned char *read_00001; unsigned int read_00001_len; unsigned int read_00001_ptr = 0; //**** delimited read static unsigned char read_00001_delim[] = "\x0a"; read_00001 = NULL; read_00001_len = 0; int read_00001_res = cgc_delimited_read(0, &read_00001, &read_00001_len, read_00001_delim, 1); if (read_00001_res) {} //silence unused variable warning //**** read match data static unsigned char match_00001_00000[] = "\x57\x6f\x72\x64\x3a\x20\x5f\x61\x6d\x5f\x20\x61\x5f\x77\x61\x5f" "\x73\x20\x5f\x61\x69\x5f\x20\x6c\x5f\x66\x65\x20\x77\x61\x5f\x20" "\x6c\x5f\x6b\x65\x20\x61\x20\x5f\x6f\x78\x20\x6f\x66\x20\x63\x68" "\x5f\x63\x6f\x5f\x61\x74\x5f\x73\x2e\x0a"; read_00001_ptr += cgc_data_match(read_00001 + read_00001_ptr, read_00001_len - read_00001_ptr, match_00001_00000, 58); cgc_free(read_00001); if (read_00001_ptr) {} //silence unused variable warning if any } while (0); do { //*** writing data static unsigned char write_00001_00000[] = "\x4d\x61\x6d\x61\x20\x61\x6c\x77\x61\x79\x73\x20\x73\x61\x69\x64" "\x20\x6c\x69\x66\x65\x20\x77\x61\x73\x20\x6c\x69\x6b\x65\x20\x61" "\x20\x62\x6f\x78\x20\x6f\x66\x20\x63\x68\x6f\x63\x6f\x6c\x61\x74" "\x65\x73\x2e\x0a"; static unsigned int write_00001_00000_len = 52; unsigned char *write_00001 = NULL; unsigned int write_00001_len = 0; write_00001 = cgc_append_buf(write_00001, &write_00001_len, write_00001_00000, write_00001_00000_len); if (write_00001_len > 0) { cgc_transmit_all(1, write_00001, write_00001_len); } cgc_free(write_00001); } while (0); do { unsigned char *read_00002; unsigned int read_00002_len; unsigned int read_00002_ptr = 0; //**** delimited read static unsigned char read_00002_delim[] = "\x0a"; read_00002 = NULL; read_00002_len = 0; int read_00002_res = cgc_delimited_read(0, &read_00002, &read_00002_len, read_00002_delim, 1); if (read_00002_res) {} //silence unused variable warning //**** read match data static unsigned char match_00002_00000[] = "\x4e\x65\x78\x74\x20\x57\x6f\x72\x64\x3a\x20\x5f\x72\x5f\x65\x5f" "\x2c\x20\x66\x5f\x72\x20\x6c\x5f\x63\x5f\x20\x5f\x66\x20\x61\x20" "\x62\x5f\x74\x5f\x65\x5f\x20\x5f\x6f\x5f\x64\x2c\x20\x5f\x73\x20" "\x67\x5f\x6f\x5f\x2e\x0a"; read_00002_ptr += cgc_data_match(read_00002 + read_00002_ptr, read_00002_len - read_00002_ptr, match_00002_00000, 54); cgc_free(read_00002); if (read_00002_ptr) {} //silence unused variable warning if any } while (0); do { //*** writing data static unsigned char write_00002_00000[] = "\x47\x72\x65\x65\x64\x2c\x20\x66\x6f\x72\x20\x6c\x61\x63\x6b\x20" "\x6f\x66\x20\x61\x20\x62\x65\x74\x74\x65\x72\x20\x77\x6f\x72\x64" "\x2c\x20\x69\x73\x20\x67\x6f\x6f\x64\x2e\x0a"; static unsigned int write_00002_00000_len = 43; unsigned char *write_00002 = NULL; unsigned int write_00002_len = 0; write_00002 = cgc_append_buf(write_00002, &write_00002_len, write_00002_00000, write_00002_00000_len); if (write_00002_len > 0) { cgc_transmit_all(1, write_00002, write_00002_len); } cgc_free(write_00002); } while (0); do { unsigned char *read_00003; unsigned int read_00003_len; unsigned int read_00003_ptr = 0; //**** delimited read static unsigned char read_00003_delim[] = "\x0a"; read_00003 = NULL; read_00003_len = 0; int read_00003_res = cgc_delimited_read(0, &read_00003, &read_00003_len, read_00003_delim, 1); if (read_00003_res) {} //silence unused variable warning //**** read match data static unsigned char match_00003_00000[] = "\x4e\x65\x78\x74\x20\x57\x6f\x72\x64\x3a\x20\x5f\x6f\x62\x6f\x5f" "\x79\x20\x70\x5f\x74\x73\x20\x5f\x61\x62\x79\x20\x69\x6e\x20\x5f" "\x20\x63\x6f\x5f\x6e\x65\x72\x2e\x0a"; read_00003_ptr += cgc_data_match(read_00003 + read_00003_ptr, read_00003_len - read_00003_ptr, match_00003_00000, 41); cgc_free(read_00003); if (read_00003_ptr) {} //silence unused variable warning if any } while (0); do { //*** writing data static unsigned char write_00003_00000[] = "\x4e\x6f\x62\x6f\x64\x79\x20\x70\x75\x74\x73\x20\x42\x61\x62\x79" "\x20\x69\x6e\x20\x61\x20\x63\x6f\x72\x6e\x65\x72\x2e\x0a"; static unsigned int write_00003_00000_len = 30; unsigned char *write_00003 = NULL; unsigned int write_00003_len = 0; write_00003 = cgc_append_buf(write_00003, &write_00003_len, write_00003_00000, write_00003_00000_len); if (write_00003_len > 0) { cgc_transmit_all(1, write_00003, write_00003_len); } cgc_free(write_00003); } while (0); do { unsigned char *read_00004; unsigned int read_00004_len; unsigned int read_00004_ptr = 0; //**** delimited read static unsigned char read_00004_delim[] = "\x0a"; read_00004 = NULL; read_00004_len = 0; int read_00004_res = cgc_delimited_read(0, &read_00004, &read_00004_len, read_00004_delim, 1); if (read_00004_res) {} //silence unused variable warning //**** read match data static unsigned char match_00004_00000[] = "\x4e\x65\x78\x74\x20\x57\x6f\x72\x64\x3a\x20\x5f\x61\x79\x20\x5f" "\x68\x65\x20\x5f\x6f\x72\x63\x5f\x20\x62\x65\x20\x77\x69\x74\x5f" "\x20\x79\x6f\x5f\x2e\x0a"; read_00004_ptr += cgc_data_match(read_00004 + read_00004_ptr, read_00004_len - read_00004_ptr, match_00004_00000, 38); cgc_free(read_00004); if (read_00004_ptr) {} //silence unused variable warning if any } while (0); do { //*** writing data static unsigned char write_00004_00000[] = "\x4d\x61\x79\x20\x74\x68\x65\x20\x46\x6f\x72\x63\x65\x20\x62\x65" "\x20\x77\x69\x74\x68\x20\x79\x6f\x75\x2e\x0a"; static unsigned int write_00004_00000_len = 27; unsigned char *write_00004 = NULL; unsigned int write_00004_len = 0; write_00004 = cgc_append_buf(write_00004, &write_00004_len, write_00004_00000, write_00004_00000_len); if (write_00004_len > 0) { cgc_transmit_all(1, write_00004, write_00004_len); } cgc_free(write_00004); } while (0); do { unsigned char *read_00005; unsigned int read_00005_len; unsigned int read_00005_ptr = 0; //**** delimited read static unsigned char read_00005_delim[] = "\x0a"; read_00005 = NULL; read_00005_len = 0; int read_00005_res = cgc_delimited_read(0, &read_00005, &read_00005_len, read_00005_delim, 1); if (read_00005_res) {} //silence unused variable warning //**** read match data static unsigned char match_00005_00000[] = "\x4e\x65\x78\x74\x20\x57\x6f\x72\x64\x3a\x20\x5f\x70\x65\x6e\x20" "\x74\x68\x65\x20\x70\x6f\x64\x20\x62\x61\x79\x20\x64\x6f\x6f\x5f" "\x73\x20\x70\x5f\x65\x61\x73\x5f\x2c\x20\x48\x5f\x4c\x2e\x0a"; read_00005_ptr += cgc_data_match(read_00005 + read_00005_ptr, read_00005_len - read_00005_ptr, match_00005_00000, 47); cgc_free(read_00005); if (read_00005_ptr) {} //silence unused variable warning if any } while (0); do { //*** writing data static unsigned char write_00005_00000[] = "\x4f\x70\x65\x6e\x20\x74\x68\x65\x20\x70\x6f\x64\x20\x62\x61\x79" "\x20\x64\x6f\x6f\x72\x73\x20\x70\x6c\x65\x61\x73\x65\x2c\x20\x48" "\x41\x4c\x2e\x0a"; static unsigned int write_00005_00000_len = 36; unsigned char *write_00005 = NULL; unsigned int write_00005_len = 0; write_00005 = cgc_append_buf(write_00005, &write_00005_len, write_00005_00000, write_00005_00000_len); if (write_00005_len > 0) { cgc_transmit_all(1, write_00005, write_00005_len); } cgc_free(write_00005); } while (0); do { unsigned char *read_00006; unsigned int read_00006_len; unsigned int read_00006_ptr = 0; //**** delimited read static unsigned char read_00006_delim[] = "\x0a"; read_00006 = NULL; read_00006_len = 0; int read_00006_res = cgc_delimited_read(0, &read_00006, &read_00006_len, read_00006_delim, 1); if (read_00006_res) {} //silence unused variable warning //**** read match data static unsigned char match_00006_00000[] = "\x4e\x65\x78\x74\x20\x57\x6f\x72\x64\x3a\x20\x5f\x66\x20\x79\x5f" "\x75\x20\x62\x5f\x69\x5f\x64\x20\x69\x5f\x2c\x20\x68\x5f\x20\x5f" "\x69\x5f\x6c\x20\x63\x5f\x6d\x5f\x2e\x0a"; read_00006_ptr += cgc_data_match(read_00006 + read_00006_ptr, read_00006_len - read_00006_ptr, match_00006_00000, 42); cgc_free(read_00006); if (read_00006_ptr) {} //silence unused variable warning if any } while (0); do { //*** writing data static unsigned char write_00006_00000[] = "\x49\x66\x20\x79\x6f\x75\x20\x62\x75\x69\x6c\x64\x20\x69\x74\x2c" "\x20\x68\x65\x20\x77\x69\x6c\x6c\x20\x63\x6f\x6d\x65\x2e\x0a"; static unsigned int write_00006_00000_len = 31; unsigned char *write_00006 = NULL; unsigned int write_00006_len = 0; write_00006 = cgc_append_buf(write_00006, &write_00006_len, write_00006_00000, write_00006_00000_len); if (write_00006_len > 0) { cgc_transmit_all(1, write_00006, write_00006_len); } cgc_free(write_00006); } while (0); do { unsigned char *read_00007; unsigned int read_00007_len; unsigned int read_00007_ptr = 0; //**** delimited read static unsigned char read_00007_delim[] = "\x0a"; read_00007 = NULL; read_00007_len = 0; int read_00007_res = cgc_delimited_read(0, &read_00007, &read_00007_len, read_00007_delim, 1); if (read_00007_res) {} //silence unused variable warning //**** read match data static unsigned char match_00007_00000[] = "\x4e\x65\x78\x74\x20\x57\x6f\x72\x64\x3a\x20\x5f\x20\x6c\x6f\x5f" "\x65\x20\x74\x5f\x65\x20\x73\x5f\x65\x6c\x6c\x20\x6f\x66\x20\x5f" "\x61\x70\x61\x5f\x6d\x20\x69\x5f\x20\x74\x68\x5f\x20\x6d\x6f\x5f" "\x6e\x69\x6e\x5f\x2e\x0a"; read_00007_ptr += cgc_data_match(read_00007 + read_00007_ptr, read_00007_len - read_00007_ptr, match_00007_00000, 54); cgc_free(read_00007); if (read_00007_ptr) {} //silence unused variable warning if any } while (0); do { //*** writing data static unsigned char write_00007_00000[] = "\x49\x20\x6c\x6f\x76\x65\x20\x74\x68\x65\x20\x73\x6d\x65\x6c\x6c" "\x20\x6f\x66\x20\x6e\x61\x70\x61\x6c\x6d\x20\x69\x6e\x20\x74\x68" "\x65\x20\x6d\x6f\x72\x6e\x69\x6e\x67\x2e\x0a"; static unsigned int write_00007_00000_len = 43; unsigned char *write_00007 = NULL; unsigned int write_00007_len = 0; write_00007 = cgc_append_buf(write_00007, &write_00007_len, write_00007_00000, write_00007_00000_len); if (write_00007_len > 0) { cgc_transmit_all(1, write_00007, write_00007_len); } cgc_free(write_00007); } while (0); do { unsigned char *read_00008; unsigned int read_00008_len; unsigned int read_00008_ptr = 0; //**** delimited read static unsigned char read_00008_delim[] = "\x0a"; read_00008 = NULL; read_00008_len = 0; int read_00008_res = cgc_delimited_read(0, &read_00008, &read_00008_len, read_00008_delim, 1); if (read_00008_res) {} //silence unused variable warning //**** read match data static unsigned char match_00008_00000[] = "\x4e\x65\x78\x74\x20\x57\x6f\x72\x64\x3a\x20\x5f\x27\x6d\x20\x5f" "\x73\x20\x6d\x5f\x64\x20\x61\x5f\x20\x68\x65\x5f\x6c\x2c\x20\x5f" "\x6e\x64\x20\x5f\x27\x6d\x20\x5f\x6f\x74\x20\x5f\x6f\x69\x6e\x5f" "\x20\x74\x6f\x20\x74\x61\x6b\x5f\x20\x74\x68\x5f\x73\x20\x61\x5f" "\x79\x6d\x6f\x5f\x65\x21\x0a"; read_00008_ptr += cgc_data_match(read_00008 + read_00008_ptr, read_00008_len - read_00008_ptr, match_00008_00000, 71); cgc_free(read_00008); if (read_00008_ptr) {} //silence unused variable warning if any } while (0); do { //*** writing data static unsigned char write_00008_00000[] = "\x49\x27\x6d\x20\x61\x73\x20\x6d\x61\x64\x20\x61\x73\x20\x68\x65" "\x6c\x6c\x2c\x20\x61\x6e\x64\x20\x49\x27\x6d\x20\x6e\x6f\x74\x20" "\x67\x6f\x69\x6e\x67\x20\x74\x6f\x20\x74\x61\x6b\x65\x20\x74\x68" "\x69\x73\x20\x61\x6e\x79\x6d\x6f\x72\x65\x21\x0a"; static unsigned int write_00008_00000_len = 60; unsigned char *write_00008 = NULL; unsigned int write_00008_len = 0; write_00008 = cgc_append_buf(write_00008, &write_00008_len, write_00008_00000, write_00008_00000_len); if (write_00008_len > 0) { cgc_transmit_all(1, write_00008, write_00008_len); } cgc_free(write_00008); } while (0); do { unsigned char *read_00009; unsigned int read_00009_len; unsigned int read_00009_ptr = 0; //**** delimited read static unsigned char read_00009_delim[] = "\x0a"; read_00009 = NULL; read_00009_len = 0; int read_00009_res = cgc_delimited_read(0, &read_00009, &read_00009_len, read_00009_delim, 1); if (read_00009_res) {} //silence unused variable warning //**** read match data static unsigned char match_00009_00000[] = "\x4e\x65\x78\x74\x20\x57\x6f\x72\x64\x3a\x20\x5f\x73\x20\x69\x5f" "\x20\x5f\x61\x5f\x65\x3f\x0a"; read_00009_ptr += cgc_data_match(read_00009 + read_00009_ptr, read_00009_len - read_00009_ptr, match_00009_00000, 23); cgc_free(read_00009); if (read_00009_ptr) {} //silence unused variable warning if any } while (0); do { //*** writing data static unsigned char write_00009_00000[] = "\x49\x73\x20\x69\x74\x20\x73\x61\x66\x65\x3f\x0a"; static unsigned int write_00009_00000_len = 12; unsigned char *write_00009 = NULL; unsigned int write_00009_len = 0; write_00009 = cgc_append_buf(write_00009, &write_00009_len, write_00009_00000, write_00009_00000_len); if (write_00009_len > 0) { cgc_transmit_all(1, write_00009, write_00009_len); } cgc_free(write_00009); } while (0); do { unsigned char *read_00010; unsigned int read_00010_len; unsigned int read_00010_ptr = 0; //**** delimited read static unsigned char read_00010_delim[] = "\x0a"; read_00010 = NULL; read_00010_len = 0; int read_00010_res = cgc_delimited_read(0, &read_00010, &read_00010_len, read_00010_delim, 1); if (read_00010_res) {} //silence unused variable warning //**** read match data static unsigned char match_00010_00000[] = "\x4e\x65\x78\x74\x20\x57\x6f\x72\x64\x3a\x20\x5f\x65\x6c\x6c\x5f" "\x2c\x20\x67\x5f\x72\x67\x65\x5f\x75\x73\x2e\x0a"; read_00010_ptr += cgc_data_match(read_00010 + read_00010_ptr, read_00010_len - read_00010_ptr, match_00010_00000, 28); cgc_free(read_00010); if (read_00010_ptr) {} //silence unused variable warning if any } while (0); do { //*** writing data static unsigned char write_00010_00000[] = "\x48\x65\x6c\x6c\x6f\x2c\x20\x67\x6f\x72\x67\x65\x6f\x75\x73\x2e" "\x0a"; static unsigned int write_00010_00000_len = 17; unsigned char *write_00010 = NULL; unsigned int write_00010_len = 0; write_00010 = cgc_append_buf(write_00010, &write_00010_len, write_00010_00000, write_00010_00000_len); if (write_00010_len > 0) { cgc_transmit_all(1, write_00010, write_00010_len); } cgc_free(write_00010); } while (0); do { unsigned char *read_00011; unsigned int read_00011_len; unsigned int read_00011_ptr = 0; //**** delimited read static unsigned char read_00011_delim[] = "\x0a"; read_00011 = NULL; read_00011_len = 0; int read_00011_res = cgc_delimited_read(0, &read_00011, &read_00011_len, read_00011_delim, 1); if (read_00011_res) {} //silence unused variable warning //**** read match data static unsigned char match_00011_00000[] = "\x46\x69\x6e\x61\x6c\x20\x52\x6f\x75\x6e\x64\x2e\x20\x43\x68\x6f" "\x73\x65\x20\x61\x6e\x6f\x74\x68\x65\x72\x20\x32\x20\x64\x69\x67" "\x69\x74\x20\x6e\x75\x6d\x62\x65\x72\x0a"; read_00011_ptr += cgc_data_match(read_00011 + read_00011_ptr, read_00011_len - read_00011_ptr, match_00011_00000, 42); cgc_free(read_00011); if (read_00011_ptr) {} //silence unused variable warning if any } while (0); do { //*** writing data static unsigned char write_00011_00000[] = "\x39\x39\x0a"; static unsigned int write_00011_00000_len = 3; unsigned char *write_00011 = NULL; unsigned int write_00011_len = 0; write_00011 = cgc_append_buf(write_00011, &write_00011_len, write_00011_00000, write_00011_00000_len); if (write_00011_len > 0) { cgc_transmit_all(1, write_00011, write_00011_len); } cgc_free(write_00011); } while (0); do { unsigned char *read_00012; unsigned int read_00012_len; unsigned int read_00012_ptr = 0; //**** delimited read static unsigned char read_00012_delim[] = "\x0a"; read_00012 = NULL; read_00012_len = 0; int read_00012_res = cgc_delimited_read(0, &read_00012, &read_00012_len, read_00012_delim, 1); if (read_00012_res) {} //silence unused variable warning //**** read match data static unsigned char match_00012_00000[] = "\x5f\x68\x61\x5f\x20\x77\x5f\x27\x76\x5f\x20\x67\x5f\x74\x20\x5f" "\x65\x72\x5f\x20\x69\x5f\x20\x66\x5f\x69\x6c\x5f\x72\x65\x20\x74" "\x6f\x20\x63\x6f\x5f\x6d\x75\x5f\x69\x63\x5f\x74\x65\x2e\x0a"; read_00012_ptr += cgc_data_match(read_00012 + read_00012_ptr, read_00012_len - read_00012_ptr, match_00012_00000, 47); cgc_free(read_00012); if (read_00012_ptr) {} //silence unused variable warning if any } while (0); do { //*** writing data static unsigned char write_00012_00000[] = "\x57\x68\x61\x74\x20\x77\x65\x27\x76\x65\x20\x67\x6f\x74\x20\x68" "\x65\x72\x65\x20\x69\x73\x20\x66\x61\x69\x6c\x75\x72\x65\x20\x74" "\x6f\x20\x63\x6f\x6d\x6d\x75\x6e\x69\x63\x61\x74\x65\x2e\x0a"; static unsigned int write_00012_00000_len = 47; unsigned char *write_00012 = NULL; unsigned int write_00012_len = 0; write_00012 = cgc_append_buf(write_00012, &write_00012_len, write_00012_00000, write_00012_00000_len); if (write_00012_len > 0) { cgc_transmit_all(1, write_00012, write_00012_len); } cgc_free(write_00012); } while (0); do { unsigned char *read_00013; unsigned int read_00013_len; unsigned int read_00013_ptr = 0; //**** delimited read static unsigned char read_00013_delim[] = "\x0a"; read_00013 = NULL; read_00013_len = 0; int read_00013_res = cgc_delimited_read(0, &read_00013, &read_00013_len, read_00013_delim, 1); if (read_00013_res) {} //silence unused variable warning //**** read match data static unsigned char match_00013_00000[] = "\x59\x6f\x75\x20\x57\x69\x6e\x21\x0a"; read_00013_ptr += cgc_data_match(read_00013 + read_00013_ptr, read_00013_len - read_00013_ptr, match_00013_00000, 9); cgc_free(read_00013); if (read_00013_ptr) {} //silence unused variable warning if any } while (0); }
27346d9edad9671cb51e69a645cca2a2e0e23d49
fce81b804cae23f525a5ad4370b684bf0dc531a5
/numpy/distutils/checks/cpu_popcnt.c
813c461f05b36b52c855f31d621a23ab7ee0c642
[ "Zlib", "BSD-3-Clause", "MIT", "Apache-2.0" ]
permissive
numpy/numpy
ba2abcc1d2d46affbb6aabe5aed6407b4b57507e
dc2ff125493777a1084044e6cd6857a42ee323d4
refs/heads/main
2023-09-05T10:10:52.767363
2023-09-04T18:03:29
2023-09-04T18:03:29
908,607
25,725
11,968
BSD-3-Clause
2023-09-14T21:26:09
2010-09-13T23:02:39
Python
UTF-8
C
false
false
1,049
c
cpu_popcnt.c
#if defined(DETECT_FEATURES) && defined(__INTEL_COMPILER) /* * Unlike GCC and CLANG, Intel Compiler exposes all supported intrinsics, * whether or not the build options for those features are specified. * Therefore, we must test #definitions of CPU features when option native/host * is enabled via `--cpu-baseline` or through env vr `CFLAGS` otherwise * the test will be broken and leads to enable all possible features. */ #if !defined(__SSE4_2__) && !defined(__POPCNT__) #error "HOST/ARCH doesn't support POPCNT" #endif #endif #ifdef _MSC_VER #include <nmmintrin.h> #else #include <popcntintrin.h> #endif int main(int argc, char **argv) { // To make sure popcnt instructions are generated // and been tested against the assembler unsigned long long a = *((unsigned long long*)argv[argc-1]); unsigned int b = *((unsigned int*)argv[argc-2]); #if defined(_M_X64) || defined(__x86_64__) a = _mm_popcnt_u64(a); #endif b = _mm_popcnt_u32(b); return (int)a + b; }
4cc80f2eb504643b0fd32525123577db57d88210
aa3befea459382dc5c01c925653d54f435b3fb0f
/arch/risc-v/src/common/pgalloc.h
8619038ac7eb7ff375bd098ae04a5a9a079fb6cb
[ "MIT-open-group", "BSD-3-Clause", "HPND-sell-variant", "BSD-4-Clause-UC", "LicenseRef-scancode-warranty-disclaimer", "MIT-0", "LicenseRef-scancode-bsd-atmel", "LicenseRef-scancode-gary-s-brown", "LicenseRef-scancode-proprietary-license", "SunPro", "MIT", "LicenseRef-scancode-public-domain-disclaimer", "LicenseRef-scancode-other-permissive", "HPND", "ISC", "Apache-2.0", "LicenseRef-scancode-public-domain", "BSD-2-Clause", "GPL-1.0-or-later", "CC-BY-2.0", "CC-BY-4.0" ]
permissive
apache/nuttx
14519a7bff4a87935d94fb8fb2b19edb501c7cec
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
refs/heads/master
2023-08-25T06:55:45.822534
2023-08-23T16:03:31
2023-08-24T21:25:47
228,103,273
407
241
Apache-2.0
2023-09-14T18:26:05
2019-12-14T23:27:55
C
UTF-8
C
false
false
3,974
h
pgalloc.h
/**************************************************************************** * arch/risc-v/src/common/pgalloc.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The * ASF licenses this file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. * ****************************************************************************/ #ifndef __ARCH_RISC_V_SRC_COMMON_PGALLOC_H #define __ARCH_RISC_V_SRC_COMMON_PGALLOC_H #ifdef CONFIG_MM_PGALLOC /**************************************************************************** * Included Files ****************************************************************************/ #include <nuttx/config.h> #include <stdint.h> #include <string.h> #include "addrenv.h" /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ #ifndef CONFIG_ARCH_PGPOOL_MAPPING # error "RISC-V needs CONFIG_ARCH_PGPOOL_MAPPING" #endif /**************************************************************************** * Public Functions Prototypes ****************************************************************************/ /**************************************************************************** * Name: riscv_pgvaddr * * Description: * Get virtual address for pgpool physical address. Note: this function * is minimalistic and is only usable for kernel mappings and only tests * if the paddr is in the pgpool. For user mapped addresses this does not * work. * * Note: * To get it to work with user addresses, a manual table walk needs to be * implemented. Not too complex, but not needed for anything -> not * implemented. * * Input Parameters: * paddr - Physical pgpool address * * Return: * vaddr - Virtual address for physical address * ****************************************************************************/ #ifdef CONFIG_ARCH_PGPOOL_MAPPING static inline uintptr_t riscv_pgvaddr(uintptr_t paddr) { if (paddr >= CONFIG_ARCH_PGPOOL_PBASE && paddr < CONFIG_ARCH_PGPOOL_PEND) { return paddr - CONFIG_ARCH_PGPOOL_PBASE + CONFIG_ARCH_PGPOOL_VBASE; } return 0; } #endif /* CONFIG_ARCH_PGPOOL_MAPPING */ /**************************************************************************** * Name: riscv_uservaddr * * Description: * Return true if the virtual address, vaddr, lies in the user address * space. * ****************************************************************************/ static inline bool riscv_uservaddr(uintptr_t vaddr) { /* Check if this address is within the range of the virtualized .bss/.data, * heap, or stack regions. */ return vaddr >= ARCH_ADDRENV_VBASE && vaddr < ARCH_ADDRENV_VEND; } /**************************************************************************** * Name: riscv_pgwipe * * Description: * Wipe a page of physical memory, first mapping it into virtual memory. * * Input Parameters: * paddr - Physical address of page * ****************************************************************************/ static inline void riscv_pgwipe(uintptr_t paddr) { uintptr_t vaddr = riscv_pgvaddr(paddr); memset((void *)vaddr, 0, MM_PGSIZE); } #endif /* CONFIG_MM_PGALLOC */ #endif /* __ARCH_RISC_V_SRC_COMMON_PGALLOC_H */
072adf77f34f5f56a2e9ab97fd42783655ca0174
54c67306d63bb69a5cf381d12108d3dc98ae0f5d
/third-party/replxx/examples/c-api.c
7572a9b3d3539ab3a40529b4a855ea2a41a690e6
[ "ISC", "HPND-Markus-Kuhn", "LicenseRef-scancode-unicode-mappings", "BSD-3-Clause", "GPL-1.0-or-later" ]
permissive
open-goal/jak-project
adf30a3459c24afda5b180e3abe1583c93458a37
d96dce27149fbf58586160cfecb634614f055943
refs/heads/master
2023-09-01T21:51:16.736237
2023-09-01T16:10:59
2023-09-01T16:10:59
289,585,720
1,826
131
ISC
2023-09-14T13:27:47
2020-08-22T23:55:21
Common Lisp
UTF-8
C
false
false
7,593
c
c-api.c
#ifndef __sun #define _POSIX_C_SOURCE 200809L #else #define __EXTENSIONS__ 1 #endif #include <ctype.h> #include <string.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <errno.h> #include "replxx.h" #include "util.h" void modify_callback(char** line, int* cursorPosition, void* ud) { char* s = *line; char* p = strchr( s, '*' ); if ( p ) { int len = (int)strlen( s ); char* n = *line = calloc( len * 2, 1 ); int i = (int)( p - s ); strncpy(n, s, i); n += i; strncpy(n, s, i); n += i; strncpy(n, p + 1, len - i - 1); n += ( len - i - 1 ); strncpy(n, p + 1, len - i - 1); *cursorPosition *= 2; free( s ); } } void completionHook(char const* context, replxx_completions* lc, int* contextLen, void* ud) { char** examples = (char**)( ud ); size_t i; int utf8ContextLen = context_len( context ); int prefixLen = (int)strlen( context ) - utf8ContextLen; *contextLen = utf8str_codepoint_len( context + prefixLen, utf8ContextLen ); for (i = 0; examples[i] != NULL; ++i) { if (strncmp(context + prefixLen, examples[i], utf8ContextLen) == 0) { replxx_add_completion(lc, examples[i]); } } } void hintHook(char const* context, replxx_hints* lc, int* contextLen, ReplxxColor* c, void* ud) { char** examples = (char**)( ud ); int i; int utf8ContextLen = context_len( context ); int prefixLen = (int)strlen( context ) - utf8ContextLen; *contextLen = utf8str_codepoint_len( context + prefixLen, utf8ContextLen ); if ( *contextLen > 0 ) { for (i = 0; examples[i] != NULL; ++i) { if (strncmp(context + prefixLen, examples[i], utf8ContextLen) == 0) { replxx_add_hint(lc, examples[i]); } } } } void colorHook( char const* str_, ReplxxColor* colors_, int size_, void* ud ) { int i = 0; for ( ; i < size_; ++ i ) { if ( isdigit( str_[i] ) ) { colors_[i] = REPLXX_COLOR_BRIGHTMAGENTA; } } if ( ( size_ > 0 ) && ( str_[size_ - 1] == '(' ) ) { replxx_emulate_key_press( ud, ')' ); replxx_emulate_key_press( ud, REPLXX_KEY_LEFT ); } } ReplxxActionResult word_eater( int ignored, void* ud ) { Replxx* replxx = (Replxx*)ud; return ( replxx_invoke( replxx, REPLXX_ACTION_KILL_TO_BEGINING_OF_WORD, 0 ) ); } ReplxxActionResult upper_case_line( int ignored, void* ud ) { Replxx* replxx = (Replxx*)ud; ReplxxState state; replxx_get_state( replxx, &state ); int l = (int)strlen( state.text ); #ifdef _WIN32 #define strdup _strdup #endif char* d = strdup( state.text ); #undef strdup for ( int i = 0; i < l; ++ i ) { d[i] = toupper( d[i] ); } state.text = d; state.cursorPosition /= 2; replxx_set_state( replxx, &state ); free( d ); return ( REPLXX_ACTION_RESULT_CONTINUE ); } char const* recode( char* s ) { char const* r = s; while ( *s ) { if ( *s == '~' ) { *s = '\n'; } ++ s; } return ( r ); } void split( char* str_, char** data_, int size_ ) { int i = 0; char* p = str_, *o = p; while ( i < size_ ) { int last = *p == 0; if ( ( *p == ',' ) || last ) { *p = 0; data_[i ++] = o; o = p + 1; if ( last ) { break; } } ++ p; } data_[i] = 0; } int main( int argc, char** argv ) { #define MAX_EXAMPLE_COUNT 128 char* examples[MAX_EXAMPLE_COUNT + 1] = { "db", "hello", "hallo", "hans", "hansekogge", "seamann", "quetzalcoatl", "quit", "power", NULL }; Replxx* replxx = replxx_init(); replxx_install_window_change_handler( replxx ); int quiet = 0; char const* prompt = "\x1b[1;32mreplxx\x1b[0m> "; int installModifyCallback = 0; int installCompletionCallback = 1; int installHighlighterCallback = 1; int installHintsCallback = 1; int indentMultiline = 0; while ( argc > 1 ) { -- argc; ++ argv; #ifdef __REPLXX_DEBUG__ if ( !strcmp( *argv, "--keycodes" ) ) { replxx_debug_dump_print_codes(); exit(0); } #endif switch ( (*argv)[0] ) { case 'b': replxx_set_beep_on_ambiguous_completion( replxx, (*argv)[1] - '0' ); break; case 'c': replxx_set_completion_count_cutoff( replxx, atoi( (*argv) + 1 ) ); break; case 'e': replxx_set_complete_on_empty( replxx, (*argv)[1] - '0' ); break; case 'd': replxx_set_double_tab_completion( replxx, (*argv)[1] - '0' ); break; case 'h': replxx_set_max_hint_rows( replxx, atoi( (*argv) + 1 ) ); break; case 'H': replxx_set_hint_delay( replxx, atoi( (*argv) + 1 ) ); break; case 's': replxx_set_max_history_size( replxx, atoi( (*argv) + 1 ) ); break; case 'P': replxx_set_preload_buffer( replxx, recode( (*argv) + 1 ) ); break; case 'I': replxx_set_immediate_completion( replxx, (*argv)[1] - '0' ); break; case 'u': replxx_set_unique_history( replxx, (*argv)[1] - '0' ); break; case 'w': replxx_set_word_break_characters( replxx, (*argv) + 1 ); break; case 'm': replxx_set_no_color( replxx, (*argv)[1] - '0' ); break; case 'i': replxx_set_ignore_case( replxx, (*argv)[1] - '0' ); break; case 'n': indentMultiline = (*argv)[1] - '0'; break; case 'B': replxx_enable_bracketed_paste( replxx ); break; case 'p': prompt = recode( (*argv) + 1 ); break; case 'q': quiet = atoi( (*argv) + 1 ); break; case 'M': installModifyCallback = atoi( (*argv) + 1 ); break; case 'C': installCompletionCallback = 0; break; case 'S': installHighlighterCallback = 0; break; case 'N': installHintsCallback = 0; break; case 'x': split( (*argv) + 1, examples, MAX_EXAMPLE_COUNT ); break; } } replxx_set_indent_multiline( replxx, indentMultiline ); const char* file = "./replxx_history.txt"; replxx_history_load( replxx, file ); if ( installModifyCallback ) { replxx_set_modify_callback( replxx, modify_callback, 0 ); } if ( installCompletionCallback ) { replxx_set_completion_callback( replxx, completionHook, examples ); } if ( installHighlighterCallback ) { replxx_set_highlighter_callback( replxx, colorHook, replxx ); } if ( installHintsCallback ) { replxx_set_hint_callback( replxx, hintHook, examples ); } replxx_bind_key( replxx, '.', word_eater, replxx ); replxx_bind_key( replxx, REPLXX_KEY_F2, upper_case_line, replxx ); printf("starting...\n"); while (1) { char const* result = NULL; do { result = replxx_input( replxx, prompt ); } while ( ( result == NULL ) && ( errno == EAGAIN ) ); if (result == NULL) { printf("\n"); break; } else if (!strncmp(result, "/history", 9)) { /* Display the current history. */ int index = 0; int size = replxx_history_size( replxx ); ReplxxHistoryScan* hs = replxx_history_scan_start( replxx ); ReplxxHistoryEntry he; for ( ; replxx_history_scan_next( replxx, hs, &he ) == 0; ++index ) { replxx_print( replxx, "%4d: %s\n", index, he.text ); } replxx_history_scan_stop( replxx, hs ); } else if (!strncmp(result, "/unique", 8)) { replxx_set_unique_history( replxx, 1 ); } else if (!strncmp(result, "/eb", 4)) { replxx_enable_bracketed_paste( replxx ); } else if (!strncmp(result, "/db", 4)) { replxx_disable_bracketed_paste( replxx ); } if (*result != '\0') { replxx_print( replxx, quiet ? "%s\n" : "thanks for the input: %s\n", result ); replxx_history_add( replxx, result ); } } replxx_history_save( replxx, file ); printf( "Exiting Replxx\n" ); replxx_end( replxx ); }
b1eea7bb312f65149d608aa6b8aafb2ada83c196
fa7ba9dc69c3d1c47f2caab8b6012c4003eff852
/source/htslib/htslib/bgzf.h
1edce419c71efca4fcf2fc0af4c3cace3e82995d
[ "MIT" ]
permissive
alexdobin/STAR
22d6c771b6346b8ec19f89751f21a56fd42549df
79affaae7d5e70221287762eab4e40679fad87f7
refs/heads/master
2023-08-23T07:32:52.945974
2023-08-15T19:21:58
2023-08-15T19:21:58
17,778,869
1,686
594
MIT
2023-08-16T15:49:57
2014-03-15T15:47:05
C
UTF-8
C
false
false
9,857
h
bgzf.h
/* The MIT License Copyright (c) 2008 Broad Institute / Massachusetts Institute of Technology 2011, 2012 Attractive Chaos <attractor@live.co.uk> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* The BGZF library was originally written by Bob Handsaker from the Broad * Institute. It was later improved by the SAMtools developers. */ #ifndef __BGZF_H #define __BGZF_H #include <stdint.h> #include <stdio.h> #include <zlib.h> #include <sys/types.h> #define BGZF_BLOCK_SIZE 0xff00 // make sure compressBound(BGZF_BLOCK_SIZE) < BGZF_MAX_BLOCK_SIZE #define BGZF_MAX_BLOCK_SIZE 0x10000 #define BGZF_ERR_ZLIB 1 #define BGZF_ERR_HEADER 2 #define BGZF_ERR_IO 4 #define BGZF_ERR_MISUSE 8 struct hFILE; struct bgzf_mtaux_t; typedef struct __bgzidx_t bgzidx_t; struct BGZF { int errcode:16, is_write:2, is_be:2, compress_level:9, is_compressed:2, is_gzip:1; int cache_size; int block_length, block_offset; int64_t block_address, uncompressed_address; void *uncompressed_block, *compressed_block; void *cache; // a pointer to a hash table struct hFILE *fp; // actual file handle struct bgzf_mtaux_t *mt; // only used for multi-threading bgzidx_t *idx; // BGZF index int idx_build_otf; // build index on the fly, set by bgzf_index_build_init() z_stream *gz_stream;// for gzip-compressed files }; #ifndef HTS_BGZF_TYPEDEF typedef struct BGZF BGZF; #define HTS_BGZF_TYPEDEF #endif #ifndef KSTRING_T #define KSTRING_T kstring_t typedef struct __kstring_t { size_t l, m; char *s; } kstring_t; #endif #ifdef __cplusplus extern "C" { #endif /****************** * Basic routines * ******************/ /** * Open an existing file descriptor for reading or writing. * * @param fd file descriptor * @param mode mode matching /[rwa][u0-9]+/: 'r' for reading, 'w' for * writing, or 'a' for appending, while a digit specifies * the zlib compression level. * Note that there is a distinction between 'u' and '0': the * first yields plain uncompressed output whereas the latter * outputs uncompressed data wrapped in the zlib format. * @return BGZF file handler; 0 on error */ BGZF* bgzf_dopen(int fd, const char *mode); #define bgzf_fdopen(fd, mode) bgzf_dopen((fd), (mode)) // for backward compatibility /** * Open the specified file for reading or writing. */ BGZF* bgzf_open(const char* path, const char *mode); /** * Open an existing hFILE stream for reading or writing. */ BGZF* bgzf_hopen(struct hFILE *fp, const char *mode); /** * Close the BGZF and free all associated resources. * * @param fp BGZF file handler * @return 0 on success and -1 on error */ int bgzf_close(BGZF *fp); /** * Read up to _length_ bytes from the file storing into _data_. * * @param fp BGZF file handler * @param data data array to read into * @param length size of data to read * @return number of bytes actually read; 0 on end-of-file and -1 on error */ ssize_t bgzf_read(BGZF *fp, void *data, size_t length); /** * Write _length_ bytes from _data_ to the file. If no I/O errors occur, * the complete _length_ bytes will be written (or queued for writing). * * @param fp BGZF file handler * @param data data array to write * @param length size of data to write * @return number of bytes written (i.e., _length_); negative on error */ ssize_t bgzf_write(BGZF *fp, const void *data, size_t length); /** * Read up to _length_ bytes directly from the underlying stream without * decompressing. Bypasses BGZF blocking, so must be used with care in * specialised circumstances only. * * @param fp BGZF file handler * @param data data array to read into * @param length number of raw bytes to read * @return number of bytes actually read; 0 on end-of-file and -1 on error */ ssize_t bgzf_raw_read(BGZF *fp, void *data, size_t length); /** * Write _length_ bytes directly to the underlying stream without * compressing. Bypasses BGZF blocking, so must be used with care * in specialised circumstances only. * * @param fp BGZF file handler * @param data data array to write * @param length number of raw bytes to write * @return number of bytes actually written; -1 on error */ ssize_t bgzf_raw_write(BGZF *fp, const void *data, size_t length); /** * Write the data in the buffer to the file. */ int bgzf_flush(BGZF *fp); /** * Return a virtual file pointer to the current location in the file. * No interpetation of the value should be made, other than a subsequent * call to bgzf_seek can be used to position the file at the same point. * Return value is non-negative on success. */ #define bgzf_tell(fp) (((fp)->block_address << 16) | ((fp)->block_offset & 0xFFFF)) /** * Set the file to read from the location specified by _pos_. * * @param fp BGZF file handler * @param pos virtual file offset returned by bgzf_tell() * @param whence must be SEEK_SET * @return 0 on success and -1 on error */ int64_t bgzf_seek(BGZF *fp, int64_t pos, int whence); /** * Check if the BGZF end-of-file (EOF) marker is present * * @param fp BGZF file handler opened for reading * @return 1 if the EOF marker is present and correct; * 2 if it can't be checked, e.g., because fp isn't seekable; * 0 if the EOF marker is absent; * -1 (with errno set) on error */ int bgzf_check_EOF(BGZF *fp); /** * Check if a file is in the BGZF format * * @param fn file name * @return 1 if _fn_ is BGZF; 0 if not or on I/O error */ int bgzf_is_bgzf(const char *fn); /********************* * Advanced routines * *********************/ /** * Set the cache size. Only effective when compiled with -DBGZF_CACHE. * * @param fp BGZF file handler * @param size size of cache in bytes; 0 to disable caching (default) */ void bgzf_set_cache_size(BGZF *fp, int size); /** * Flush the file if the remaining buffer size is smaller than _size_ * @return 0 if flushing succeeded or was not needed; negative on error */ int bgzf_flush_try(BGZF *fp, ssize_t size); /** * Read one byte from a BGZF file. It is faster than bgzf_read() * @param fp BGZF file handler * @return byte read; -1 on end-of-file or error */ int bgzf_getc(BGZF *fp); /** * Read one line from a BGZF file. It is faster than bgzf_getc() * * @param fp BGZF file handler * @param delim delimitor * @param str string to write to; must be initialized * @return length of the string; 0 on end-of-file; negative on error */ int bgzf_getline(BGZF *fp, int delim, kstring_t *str); /** * Read the next BGZF block. */ int bgzf_read_block(BGZF *fp); /** * Enable multi-threading (only effective on writing and when the * library was compiled with -DBGZF_MT) * * @param fp BGZF file handler; must be opened for writing * @param n_threads #threads used for writing * @param n_sub_blks #blocks processed by each thread; a value 64-256 is recommended */ int bgzf_mt(BGZF *fp, int n_threads, int n_sub_blks); /******************* * bgzidx routines * *******************/ /** * Position BGZF at the uncompressed offset * * @param fp BGZF file handler; must be opened for reading * @param uoffset file offset in the uncompressed data * @param where SEEK_SET supported atm * * Returns 0 on success and -1 on error. */ int bgzf_useek(BGZF *fp, long uoffset, int where); /** * Position in uncompressed BGZF * * @param fp BGZF file handler; must be opened for reading * * Returns the current offset on success and -1 on error. */ long bgzf_utell(BGZF *fp); /** * Tell BGZF to build index while compressing. * * @param fp BGZF file handler; can be opened for reading or writing. * * Returns 0 on success and -1 on error. */ int bgzf_index_build_init(BGZF *fp); /** * Load BGZF index * * @param fp BGZF file handler * @param bname base name * @param suffix suffix to add to bname (can be NULL) * * Returns 0 on success and -1 on error. */ int bgzf_index_load(BGZF *fp, const char *bname, const char *suffix); /** * Save BGZF index * * @param fp BGZF file handler * @param bname base name * @param suffix suffix to add to bname (can be NULL) * * Returns 0 on success and -1 on error. */ int bgzf_index_dump(BGZF *fp, const char *bname, const char *suffix); #ifdef __cplusplus } #endif #endif
7ee2d0fd2629b2fc27a5cb383acaf5e19c620d7f
b732361d6b3405c3e79ac0a7d8361cf5b329b015
/ext/phalcon/datamapper/pdo/connection/decorated.zep.c
e08ea11081bb66a9698e828b9aefc92bda3a20f8
[ "BSD-3-Clause" ]
permissive
phalcon/cphalcon
4a5b26f47b5c2a4107541d7fd73c595c0d90ed73
fc183e11e8b96c43daf7d893244846206dc2aa73
refs/heads/master
2023-03-07T22:09:48.814291
2023-02-28T16:45:15
2023-02-28T16:45:15
2,854,337
8,135
2,343
BSD-3-Clause
2023-09-12T12:41:13
2011-11-26T05:52:50
PHP
UTF-8
C
false
true
3,326
c
decorated.zep.c
#ifdef HAVE_CONFIG_H #include "../../../../ext_config.h" #endif #include <php.h> #include "../../../../php_ext.h" #include "../../../../ext.h" #include <Zend/zend_operators.h> #include <Zend/zend_exceptions.h> #include <Zend/zend_interfaces.h> #include "kernel/main.h" #include "kernel/object.h" #include "kernel/operators.h" #include "kernel/memory.h" #include "kernel/fcall.h" #include "ext/pdo/php_pdo_driver.h" #include "kernel/exception.h" /** * This file is part of the Phalcon Framework. * * (c) Phalcon Team <team@phalcon.io> * * For the full copyright and license information, please view the LICENSE.txt * file that was distributed with this source code. * * Implementation of this file has been influenced by AtlasPHP * * @link https://github.com/atlasphp/Atlas.Pdo * @license https://github.com/atlasphp/Atlas.Pdo/blob/1.x/LICENSE.md */ /** * Decorates an existing PDO instance with the extended methods. */ ZEPHIR_INIT_CLASS(Phalcon_DataMapper_Pdo_Connection_Decorated) { ZEPHIR_REGISTER_CLASS_EX(Phalcon\\DataMapper\\Pdo\\Connection, Decorated, phalcon, datamapper_pdo_connection_decorated, phalcon_datamapper_pdo_connection_abstractconnection_ce, phalcon_datamapper_pdo_connection_decorated_method_entry, 0); return SUCCESS; } /** * * Constructor. * * This overrides the parent so that it can take an existing PDO instance * and decorate it with the extended methods. * * @param \PDO $pdo * @param ProfilerInterface|null $profiler * */ PHP_METHOD(Phalcon_DataMapper_Pdo_Connection_Decorated, __construct) { zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *pdo, pdo_sub, *profiler = NULL, profiler_sub, __$null; zval *this_ptr = getThis(); ZVAL_UNDEF(&pdo_sub); ZVAL_UNDEF(&profiler_sub); ZVAL_NULL(&__$null); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_OBJECT_OF_CLASS(pdo, php_pdo_get_dbh_ce()) Z_PARAM_OPTIONAL Z_PARAM_OBJECT_OF_CLASS_OR_NULL(profiler, phalcon_datamapper_pdo_profiler_profilerinterface_ce) ZEND_PARSE_PARAMETERS_END(); #endif ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 1, &pdo, &profiler); if (!profiler) { profiler = &profiler_sub; ZEPHIR_CPY_WRT(profiler, &__$null); } else { ZEPHIR_SEPARATE_PARAM(profiler); } zephir_update_property_zval(this_ptr, ZEND_STRL("pdo"), pdo); if (Z_TYPE_P(profiler) == IS_NULL) { ZEPHIR_INIT_NVAR(profiler); object_init_ex(profiler, phalcon_datamapper_pdo_profiler_profiler_ce); ZEPHIR_CALL_METHOD(NULL, profiler, "__construct", NULL, 198); zephir_check_call_status(); } ZEPHIR_CALL_METHOD(NULL, this_ptr, "setprofiler", NULL, 0, profiler); zephir_check_call_status(); ZEPHIR_MM_RESTORE(); } /** * Connects to the database. */ PHP_METHOD(Phalcon_DataMapper_Pdo_Connection_Decorated, connect) { zval *this_ptr = getThis(); } /** * Disconnects from the database; disallowed with decorated PDO connections. * * @throws CannotDisconnect */ PHP_METHOD(Phalcon_DataMapper_Pdo_Connection_Decorated, disconnect) { zval *this_ptr = getThis(); ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(phalcon_datamapper_pdo_exception_cannotdisconnect_ce, "Cannot disconnect a Decorated connection instance", "phalcon/DataMapper/Pdo/Connection/Decorated.zep", 66); return; }
1dc43c19f3463f193fadd2df5479afc021168930
99bdb3251fecee538e0630f15f6574054dfc1468
/components/lwp/arch/aarch64/cortex-a/lwp_arch.h
f9faebfc91659dd576f932d1e2f8d3534fcd162e
[ "Apache-2.0" ]
permissive
RT-Thread/rt-thread
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
3602f891211904a27dcbd51e5ba72fefce7326b2
refs/heads/master
2023-09-01T04:10:20.295801
2023-08-31T16:20:55
2023-08-31T16:20:55
7,408,108
9,599
5,805
Apache-2.0
2023-09-14T13:37:26
2013-01-02T14:49:21
C
UTF-8
C
false
false
1,602
h
lwp_arch.h
/* * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2021-05-18 Jesven first version */ #ifndef LWP_ARCH_H__ #define LWP_ARCH_H__ #include <lwp.h> #include <lwp_arch_comm.h> #ifdef ARCH_MM_MMU #define USER_VADDR_TOP 0x0001000000000000UL #define USER_HEAP_VEND 0x0000ffffB0000000UL #define USER_HEAP_VADDR 0x0000ffff80000000UL #define USER_STACK_VSTART 0x0000ffff70000000UL #define USER_STACK_VEND USER_HEAP_VADDR #define LDSO_LOAD_VADDR 0x60000000UL #define USER_VADDR_START 0x00200000UL #define USER_LOAD_VADDR USER_VADDR_START #ifdef __cplusplus extern "C" { #endif unsigned long rt_hw_ffz(unsigned long x); rt_inline void icache_invalid_all(void) { asm volatile ("ic ialluis\n\tisb sy":::"memory"); } /** * @brief Save signal-related context to user stack * * @param user_sp the current sp of user * @param exp_frame exception frame to resume former execution * @param psiginfo pointer to the siginfo * @param elr pc of former execution * @param spsr program status of former execution * @return void* the new user sp */ void *arch_signal_ucontext_save(rt_base_t user_sp, siginfo_t *psiginfo, struct rt_hw_exp_stack *exp_frame, lwp_sigset_t *save_sig_mask); /** * @brief Restore the signal mask after return * * @param user_sp sp of user * @return void* */ void *arch_signal_ucontext_restore(rt_base_t user_sp); #ifdef __cplusplus } #endif #endif #endif /*LWP_ARCH_H__*/
8e6e35d38080aebaa9a2ca0a3736af928c22ed6c
fbe68d84e97262d6d26dd65c704a7b50af2b3943
/third_party/virtualbox/src/VBox/Devices/EFI/Firmware/IntelFspWrapperPkg/FspInitPei/FspNotifyS3.c
947768f5cd39bfa39c477bc5c8e68907332c67f0
[ "GPL-2.0-only", "LicenseRef-scancode-unknown-license-reference", "CDDL-1.0", "LicenseRef-scancode-warranty-disclaimer", "GPL-1.0-or-later", "LGPL-2.1-or-later", "GPL-2.0-or-later", "MPL-1.0", "LicenseRef-scancode-generic-exception", "Apache-2.0", "OpenSSL", "MIT" ]
permissive
thalium/icebox
c4e6573f2b4f0973b6c7bb0bf068fe9e795fdcfb
6f78952d58da52ea4f0e55b2ab297f28e80c1160
refs/heads/master
2022-08-14T00:19:36.984579
2022-02-22T13:10:31
2022-02-22T13:10:31
190,019,914
585
109
MIT
2022-01-13T20:58:15
2019-06-03T14:18:12
C++
UTF-8
C
false
false
2,653
c
FspNotifyS3.c
/** @file In EndOfPei notify, it will call FspNotifyPhase API. Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #include "FspInitPei.h" /** This function handles S3 resume task at the end of PEI @param[in] PeiServices Pointer to PEI Services Table. @param[in] NotifyDesc Pointer to the descriptor for the Notification event that caused this function to execute. @param[in] Ppi Pointer to the PPI data associated with this function. @retval EFI_STATUS Always return EFI_SUCCESS **/ EFI_STATUS EFIAPI S3EndOfPeiNotify ( IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc, IN VOID *Ppi ); EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc = { (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), &gEfiEndOfPeiSignalPpiGuid, S3EndOfPeiNotify }; /** This function handles S3 resume task at the end of PEI @param[in] PeiServices Pointer to PEI Services Table. @param[in] NotifyDesc Pointer to the descriptor for the Notification event that caused this function to execute. @param[in] Ppi Pointer to the PPI data associated with this function. @retval EFI_STATUS Always return EFI_SUCCESS **/ EFI_STATUS EFIAPI S3EndOfPeiNotify ( IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc, IN VOID *Ppi ) { NOTIFY_PHASE_PARAMS NotifyPhaseParams; EFI_STATUS Status; FSP_INFO_HEADER *FspHeader; FspHeader = FspFindFspHeader (PcdGet32 (PcdFlashFvFspBase)); if (FspHeader == NULL) { return EFI_DEVICE_ERROR; } DEBUG ((DEBUG_INFO, "S3EndOfPeiNotify enter\n")); NotifyPhaseParams.Phase = EnumInitPhaseAfterPciEnumeration; Status = CallFspNotifyPhase (FspHeader, &NotifyPhaseParams); DEBUG((DEBUG_INFO, "FSP S3NotifyPhase AfterPciEnumeration status: 0x%x\n", Status)); NotifyPhaseParams.Phase = EnumInitPhaseReadyToBoot; Status = CallFspNotifyPhase (FspHeader, &NotifyPhaseParams); DEBUG((DEBUG_INFO, "FSP S3NotifyPhase ReadyToBoot status: 0x%x\n", Status)); return EFI_SUCCESS; }
11693ad1ea5ad4921e94272678d809a3a5c45ce6
a5a7c59b04a1a64fe34653c7970c3cf173f9c1df
/externals/tools/SiconosCompat.h
4d87f6623d768705b044eb817eb73ef0eed02c40
[ "Apache-2.0", "LicenseRef-scancode-unknown-license-reference" ]
permissive
siconos/siconos
a7afdba41a2bc1192ad8dcd93ac7266fa281f4cf
82a8d1338bfc1be0d36b5e8a9f40c1ad5384a641
refs/heads/master
2023-08-21T22:22:55.625941
2023-07-17T13:07:32
2023-07-17T13:07:32
37,709,357
166
33
Apache-2.0
2023-07-17T12:31:16
2015-06-19T07:55:53
C
UTF-8
C
false
false
1,613
h
SiconosCompat.h
/* Siconos is a program dedicated to modeling, simulation and control * of non smooth dynamical systems. * * Copyright 2022 INRIA. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _SICONOS_COMPAT #define _SICONOS_COMPAT #if defined(_MSC_VER) || defined(__MINGW32__) // check other mingw #define SN_SIZE_T_F "%Iu" #define SN_SSIZE_T_F "%Id" #define SN_PTRDIFF_T_F "%Id" // Note FP : I think that this is obsolete, isn't it ? // See https://docs.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=vs-2019 // Could we remove this and the define ? #else #define SN_SIZE_T_F "%zu" #define SN_SSIZE_T_F "%zd" #define SN_PTRDIFF_T_F "%zd" #endif #ifdef _WIN32 #define DLLPRE "" #define DLLEXT ".dll" #else #define DLLPRE "lib" #define DLLEXT ".so" #endif #define DLL_FROM_NAME(X) DLLPRE X DLLEXT #if defined(_MSC_VER) // for M_PI #define _USE_MATH_DEFINES #endif /* defined(_MSC_VER) */ #if defined(__SUNPRO_CC) #define INFINITY (DBL_MAX+DBL_MAX) #define NAN (INFINITY-INFINITY) #endif #endif
992dff44515c8d06f2154ef476e968bf921aeb8c
39568e19301a7a112398be542154950af25591de
/sw/device/silicon_creator/rom_ext/bootstrap.c
ce3990d85390c9b1fb803cd45cdebe94c1a2e3db
[ "Apache-2.0", "LicenseRef-scancode-unknown-license-reference" ]
permissive
lowRISC/opentitan
493995bc7cf7cb3aee486a5203af3fd62bba3bfc
51f6017b8425b14d5a4aa9abace8fe5a25ef08c8
refs/heads/master
2023-08-31T22:05:09.425796
2023-08-14T14:52:15
2023-08-31T20:31:13
204,516,692
2,077
634
Apache-2.0
2023-09-14T21:16:21
2019-08-26T16:30:16
SystemVerilog
UTF-8
C
false
false
5,303
c
bootstrap.c
// Copyright lowRISC contributors. // Licensed under the Apache License, Version 2.0, see LICENSE for details. // SPDX-License-Identifier: Apache-2.0 #include "sw/device/silicon_creator/rom_ext/bootstrap.h" #include <stdint.h> #include "sw/device/lib/base/hardened.h" #include "sw/device/silicon_creator/lib/base/chip.h" #include "sw/device/silicon_creator/lib/bootstrap.h" #include "sw/device/silicon_creator/lib/drivers/flash_ctrl.h" #include "sw/device/silicon_creator/lib/drivers/otp.h" #include "sw/device/silicon_creator/lib/drivers/rstmgr.h" #include "sw/device/silicon_creator/lib/error.h" #include "flash_ctrl_regs.h" #include "hw/ip/otp_ctrl/data/otp_ctrl_regs.h" enum { /* * Maximum flash address, exclusive. */ kMaxAddress = FLASH_CTRL_PARAM_BYTES_PER_BANK * FLASH_CTRL_PARAM_REG_NUM_BANKS, /* * The total number of flash pages. */ kNumPages = FLASH_CTRL_PARAM_REG_PAGES_PER_BANK * FLASH_CTRL_PARAM_REG_NUM_BANKS, }; rom_error_t bootstrap_chip_erase(void) { // Unlike ROM bootstrap, we cannot erase entire banks at a time because that // would erase ROM_EXT regions as well. flash_ctrl_bank_erase_perms_set(kHardenedBoolTrue); rom_error_t last_err = kErrorOk; for (uint32_t i = 0; i < kNumPages; ++i) { const uint32_t addr = i * FLASH_CTRL_PARAM_BYTES_PER_PAGE; // Do not erase this page if it lies within ROM_EXT on either slot. if (addr < CHIP_ROM_EXT_SIZE_MAX || (addr >= FLASH_CTRL_PARAM_BYTES_PER_BANK && addr < FLASH_CTRL_PARAM_BYTES_PER_BANK + CHIP_ROM_EXT_SIZE_MAX)) { continue; } rom_error_t err = flash_ctrl_data_erase(addr, kFlashCtrlEraseTypePage); if (err != kErrorOk) { last_err = err; } } flash_ctrl_bank_erase_perms_set(kHardenedBoolFalse); return last_err; } rom_error_t bootstrap_erase_verify(void) { rom_error_t last_err = kErrorOk; for (uint32_t i = 0; i < kNumPages; ++i) { const uint32_t addr = i * FLASH_CTRL_PARAM_BYTES_PER_PAGE; // Do not verify this page if it lies within ROM_EXT on either slot. if (addr < CHIP_ROM_EXT_SIZE_MAX || (addr >= FLASH_CTRL_PARAM_BYTES_PER_BANK && addr < FLASH_CTRL_PARAM_BYTES_PER_BANK + CHIP_ROM_EXT_SIZE_MAX)) { continue; } rom_error_t err = flash_ctrl_data_erase_verify(addr, kFlashCtrlEraseTypePage); if (err != kErrorOk) { last_err = err; } } return last_err; } hardened_bool_t rom_ext_bootstrap_enabled(void) { // Check that bootstrap is enabled in OTP. uint32_t bootstrap_en = otp_read32(OTP_CTRL_PARAM_OWNER_SW_CFG_ROM_EXT_BOOTSTRAP_EN_OFFSET); if (launder32(bootstrap_en) != kHardenedBoolTrue) { return kHardenedBoolFalse; } HARDENED_CHECK_EQ(bootstrap_en, kHardenedBoolTrue); // Check that the reset reason is PoR. const uint32_t reset_mask = 1 << kRstmgrReasonPowerOn; const uint32_t reset_reason = rstmgr_reason_get(); const uint32_t is_por = reset_reason & reset_mask; if (launder32(is_por) == 0) { return kHardenedBoolFalse; } HARDENED_CHECK_EQ(is_por, reset_mask); return kHardenedBoolTrue; } rom_error_t rom_ext_bootstrap(void) { hardened_bool_t enabled = rom_ext_bootstrap_enabled(); if (launder32(enabled) != kHardenedBoolTrue) { return kErrorBootstrapDisabledRomExt; } HARDENED_CHECK_EQ(enabled, kHardenedBoolTrue); enum { kNumPagesInRomExt = CHIP_ROM_EXT_SIZE_MAX / FLASH_CTRL_PARAM_BYTES_PER_PAGE }; static_assert(CHIP_ROM_EXT_SIZE_MAX % FLASH_CTRL_PARAM_BYTES_PER_PAGE == 0, "ROM_EXT size must be an integer multiple of flash page size."); static_assert(kNumPagesInRomExt <= FLASH_CTRL_PARAM_REG_PAGES_PER_BANK, "ROM_EXT must fit within a single flash bank."); // Read the DEFAULT_REGION register to determine default values for some // fields of MP_REGION_CFG_${region}. const flash_ctrl_cfg_t default_cfg = flash_ctrl_data_default_cfg_get(); // The region of slot A following the ROM_EXT region is erasable and // programmable. flash_ctrl_data_region_protect( /*region=*/0, /*page_offset=*/kNumPagesInRomExt, /*num_pages=*/FLASH_CTRL_PARAM_REG_PAGES_PER_BANK - kNumPagesInRomExt, (flash_ctrl_perms_t){ .read = kMultiBitBool4True, .write = kMultiBitBool4True, .erase = kMultiBitBool4True, }, default_cfg); // The region of slot B following the ROM_EXT region is erasable, but not // programmable. flash_ctrl_data_region_protect( /*region=*/1, /*page_offset=*/FLASH_CTRL_PARAM_REG_PAGES_PER_BANK + kNumPagesInRomExt, /*num_pages=*/FLASH_CTRL_PARAM_REG_PAGES_PER_BANK - kNumPagesInRomExt, (flash_ctrl_perms_t){ .read = kMultiBitBool4True, .write = kMultiBitBool4False, .erase = kMultiBitBool4True, }, default_cfg); // With the lowest priority, disable programming and erasing the flash. flash_ctrl_data_region_protect( /*region=*/2, /*page_offset=*/0, /*num_pages=*/FLASH_CTRL_PARAM_REG_PAGES_PER_BANK * FLASH_CTRL_PARAM_REG_NUM_BANKS, (flash_ctrl_perms_t){ .read = kMultiBitBool4True, .write = kMultiBitBool4False, .erase = kMultiBitBool4False, }, default_cfg); return enter_bootstrap(); }
d87420ef4666f4d121e43a49d164ed4ea8c08c7d
c475cd8531a94ffae69cc92371d41531dbbddb6c
/Source/Math/vec4math.h
24bb72a0197dc39c472b8cce7341da3f0b374db0
[ "Apache-2.0", "LicenseRef-scancode-free-unknown" ]
permissive
WolfireGames/overgrowth
72d3dd29cbd7254337265c29f8de3e5c32400114
594a2a4f9da0855304ee8cd5335d042f8e954ce1
refs/heads/main
2023-08-15T19:36:56.156578
2023-05-17T08:17:53
2023-05-17T08:20:36
467,448,492
2,264
245
Apache-2.0
2023-05-09T07:29:58
2022-03-08T09:38:54
C++
UTF-8
C
false
false
4,530
h
vec4math.h
//----------------------------------------------------------------------------- // Name: vec4math.h // Developer: Wolfire Games LLC // Description: // License: Read below //----------------------------------------------------------------------------- // // Copyright 2022 Wolfire Games LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //----------------------------------------------------------------------------- #pragma once #include <Math/vec4.h> #include <Math/vec3.h> #include <Math/vec3math.h> inline vec4 operator+(const vec4 &vec, const vec4 &param) { return vec4(vec.entries[0] + param.entries[0], vec.entries[1] + param.entries[1], vec.entries[2] + param.entries[2], vec.entries[3]); } inline vec4 operator-(const vec4 &vec, const vec4 &param) { return vec4(vec.entries[0] - param.entries[0], vec.entries[1] - param.entries[1], vec.entries[2] - param.entries[2], vec.entries[3]); } inline vec4 operator*(const vec4 &vec, float param) { return vec4(vec.entries[0] * param, vec.entries[1] * param, vec.entries[2] * param, vec.entries[3]); } inline vec4 operator/(const vec4 &vec, float param) { return vec4(vec.entries[0] / param, vec.entries[1] / param, vec.entries[2] / param, vec.entries[3]); } inline void operator+=(vec4 &vec, const vec4 &param) { vec.entries[0] += param.entries[0]; vec.entries[1] += param.entries[1]; vec.entries[2] += param.entries[2]; } inline void operator-=(vec4 &vec, const vec4 &param) { vec.entries[0] -= param.entries[0]; vec.entries[1] -= param.entries[1]; vec.entries[2] -= param.entries[2]; } inline void operator*=(vec4 &vec, float param) { vec.entries[0] *= param; vec.entries[1] *= param; vec.entries[2] *= param; } inline void operator*=(vec4 &vec, const vec4 &param) { vec.entries[0] *= param.entries[0]; vec.entries[1] *= param.entries[1]; vec.entries[2] *= param.entries[2]; } inline void operator/=(vec4 &vec, float param) { vec.entries[0] /= param; vec.entries[1] /= param; vec.entries[2] /= param; } inline bool operator==(const vec4 &vec, const vec4 &param) { return (vec.entries[0] == param.entries[0] && vec.entries[1] == param.entries[1] && vec.entries[2] == param.entries[2] && vec.entries[3] == param.entries[3]); } inline bool operator!=(const vec4 &vec, const vec4 &param) { return (vec.entries[0] != param.entries[0] || vec.entries[1] != param.entries[1] || vec.entries[2] != param.entries[2] || vec.entries[3] != param.entries[3]); } float length(const vec4 &vec); inline float length_squared(const vec4 &vec) { return vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]; } inline float dot(const vec4 &vec_a, const vec4 &vec_b) { return vec_a[0] * vec_b[0] + vec_a[1] * vec_b[1] + vec_a[2] * vec_b[2]; } inline float distance(const vec4 &vec_a, const vec4 &vec_b) { return length(vec_a - vec_b); } inline float distance_squared(const vec4 &vec_a, const vec4 &vec_b) { return length_squared(vec_a - vec_b); } inline vec4 normalize(const vec4 &vec) { return vec4(normalize(vec.xyz()), vec[3]); } inline vec4 cross(const vec4 &vec_a, const vec4 &vec_b) { vec4 result; result[0] = vec_a[1] * vec_b[2] - vec_a[2] * vec_b[1]; result[1] = vec_a[2] * vec_b[0] - vec_a[0] * vec_b[2]; result[2] = vec_a[0] * vec_b[1] - vec_a[1] * vec_b[0]; return result; } inline vec4 reflect(const vec4 &vec, const vec4 &normal) { return vec - normal * (2.0f * dot(vec, normal)); } inline vec4 operator-(const vec4 &vec) { return vec * -1.0f; } inline vec4 operator*(float param, const vec4 &vec_b) { return vec_b * param; } inline vec4 lerp(vec4 v0, vec4 v1, float t) { return (1 - t) * v0 + t * v1; }
4e419ed235a268aa37d94447594481a2692e12a3
88ae8695987ada722184307301e221e1ba3cc2fa
/third_party/ffmpeg/doc/examples/decode_filter_audio.c
2046419819a93405768103565b13bb34744224a1
[ "BSD-3-Clause", "LGPL-2.1-only", "LGPL-3.0-only", "LGPL-2.0-or-later", "GPL-1.0-or-later", "GPL-2.0-only", "LGPL-2.1-or-later", "GPL-3.0-or-later", "LGPL-3.0-or-later", "IJG", "LicenseRef-scancode-other-permissive", "MIT", "GPL-2.0-or-later", "Apache-2.0", "GPL-3.0-only" ]
permissive
iridium-browser/iridium-browser
71d9c5ff76e014e6900b825f67389ab0ccd01329
5ee297f53dc7f8e70183031cff62f37b0f19d25f
refs/heads/master
2023-08-03T16:44:16.844552
2023-07-20T15:17:00
2023-07-23T16:09:30
220,016,632
341
40
BSD-3-Clause
2021-08-13T13:54:45
2019-11-06T14:32:31
null
UTF-8
C
false
false
10,380
c
decode_filter_audio.c
/* * Copyright (c) 2010 Nicolas George * Copyright (c) 2011 Stefano Sabatini * Copyright (c) 2012 Clément Bœsch * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ /** * @file audio decoding and filtering usage example * @example decode_filter_audio.c * * Demux, decode and filter audio input file, generate a raw audio * file to be played with ffplay. */ #include <unistd.h> #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libavfilter/buffersink.h> #include <libavfilter/buffersrc.h> #include <libavutil/channel_layout.h> #include <libavutil/opt.h> static const char *filter_descr = "aresample=8000,aformat=sample_fmts=s16:channel_layouts=mono"; static const char *player = "ffplay -f s16le -ar 8000 -ac 1 -"; static AVFormatContext *fmt_ctx; static AVCodecContext *dec_ctx; AVFilterContext *buffersink_ctx; AVFilterContext *buffersrc_ctx; AVFilterGraph *filter_graph; static int audio_stream_index = -1; static int open_input_file(const char *filename) { const AVCodec *dec; int ret; if ((ret = avformat_open_input(&fmt_ctx, filename, NULL, NULL)) < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot open input file\n"); return ret; } if ((ret = avformat_find_stream_info(fmt_ctx, NULL)) < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n"); return ret; } /* select the audio stream */ ret = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_AUDIO, -1, -1, &dec, 0); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot find an audio stream in the input file\n"); return ret; } audio_stream_index = ret; /* create decoding context */ dec_ctx = avcodec_alloc_context3(dec); if (!dec_ctx) return AVERROR(ENOMEM); avcodec_parameters_to_context(dec_ctx, fmt_ctx->streams[audio_stream_index]->codecpar); /* init the audio decoder */ if ((ret = avcodec_open2(dec_ctx, dec, NULL)) < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot open audio decoder\n"); return ret; } return 0; } static int init_filters(const char *filters_descr) { char args[512]; int ret = 0; const AVFilter *abuffersrc = avfilter_get_by_name("abuffer"); const AVFilter *abuffersink = avfilter_get_by_name("abuffersink"); AVFilterInOut *outputs = avfilter_inout_alloc(); AVFilterInOut *inputs = avfilter_inout_alloc(); static const enum AVSampleFormat out_sample_fmts[] = { AV_SAMPLE_FMT_S16, -1 }; static const int out_sample_rates[] = { 8000, -1 }; const AVFilterLink *outlink; AVRational time_base = fmt_ctx->streams[audio_stream_index]->time_base; filter_graph = avfilter_graph_alloc(); if (!outputs || !inputs || !filter_graph) { ret = AVERROR(ENOMEM); goto end; } /* buffer audio source: the decoded frames from the decoder will be inserted here. */ if (dec_ctx->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) av_channel_layout_default(&dec_ctx->ch_layout, dec_ctx->ch_layout.nb_channels); ret = snprintf(args, sizeof(args), "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=", time_base.num, time_base.den, dec_ctx->sample_rate, av_get_sample_fmt_name(dec_ctx->sample_fmt)); av_channel_layout_describe(&dec_ctx->ch_layout, args + ret, sizeof(args) - ret); ret = avfilter_graph_create_filter(&buffersrc_ctx, abuffersrc, "in", args, NULL, filter_graph); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot create audio buffer source\n"); goto end; } /* buffer audio sink: to terminate the filter chain. */ ret = avfilter_graph_create_filter(&buffersink_ctx, abuffersink, "out", NULL, NULL, filter_graph); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot create audio buffer sink\n"); goto end; } ret = av_opt_set_int_list(buffersink_ctx, "sample_fmts", out_sample_fmts, -1, AV_OPT_SEARCH_CHILDREN); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot set output sample format\n"); goto end; } ret = av_opt_set(buffersink_ctx, "ch_layouts", "mono", AV_OPT_SEARCH_CHILDREN); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot set output channel layout\n"); goto end; } ret = av_opt_set_int_list(buffersink_ctx, "sample_rates", out_sample_rates, -1, AV_OPT_SEARCH_CHILDREN); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot set output sample rate\n"); goto end; } /* * Set the endpoints for the filter graph. The filter_graph will * be linked to the graph described by filters_descr. */ /* * The buffer source output must be connected to the input pad of * the first filter described by filters_descr; since the first * filter input label is not specified, it is set to "in" by * default. */ outputs->name = av_strdup("in"); outputs->filter_ctx = buffersrc_ctx; outputs->pad_idx = 0; outputs->next = NULL; /* * The buffer sink input must be connected to the output pad of * the last filter described by filters_descr; since the last * filter output label is not specified, it is set to "out" by * default. */ inputs->name = av_strdup("out"); inputs->filter_ctx = buffersink_ctx; inputs->pad_idx = 0; inputs->next = NULL; if ((ret = avfilter_graph_parse_ptr(filter_graph, filters_descr, &inputs, &outputs, NULL)) < 0) goto end; if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0) goto end; /* Print summary of the sink buffer * Note: args buffer is reused to store channel layout string */ outlink = buffersink_ctx->inputs[0]; av_channel_layout_describe(&outlink->ch_layout, args, sizeof(args)); av_log(NULL, AV_LOG_INFO, "Output: srate:%dHz fmt:%s chlayout:%s\n", (int)outlink->sample_rate, (char *)av_x_if_null(av_get_sample_fmt_name(outlink->format), "?"), args); end: avfilter_inout_free(&inputs); avfilter_inout_free(&outputs); return ret; } static void print_frame(const AVFrame *frame) { const int n = frame->nb_samples * frame->ch_layout.nb_channels; const uint16_t *p = (uint16_t*)frame->data[0]; const uint16_t *p_end = p + n; while (p < p_end) { fputc(*p & 0xff, stdout); fputc(*p>>8 & 0xff, stdout); p++; } fflush(stdout); } int main(int argc, char **argv) { int ret; AVPacket *packet = av_packet_alloc(); AVFrame *frame = av_frame_alloc(); AVFrame *filt_frame = av_frame_alloc(); if (!packet || !frame || !filt_frame) { fprintf(stderr, "Could not allocate frame or packet\n"); exit(1); } if (argc != 2) { fprintf(stderr, "Usage: %s file | %s\n", argv[0], player); exit(1); } if ((ret = open_input_file(argv[1])) < 0) goto end; if ((ret = init_filters(filter_descr)) < 0) goto end; /* read all packets */ while (1) { if ((ret = av_read_frame(fmt_ctx, packet)) < 0) break; if (packet->stream_index == audio_stream_index) { ret = avcodec_send_packet(dec_ctx, packet); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error while sending a packet to the decoder\n"); break; } while (ret >= 0) { ret = avcodec_receive_frame(dec_ctx, frame); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { break; } else if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error while receiving a frame from the decoder\n"); goto end; } if (ret >= 0) { /* push the audio data from decoded frame into the filtergraph */ if (av_buffersrc_add_frame_flags(buffersrc_ctx, frame, AV_BUFFERSRC_FLAG_KEEP_REF) < 0) { av_log(NULL, AV_LOG_ERROR, "Error while feeding the audio filtergraph\n"); break; } /* pull filtered audio from the filtergraph */ while (1) { ret = av_buffersink_get_frame(buffersink_ctx, filt_frame); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) break; if (ret < 0) goto end; print_frame(filt_frame); av_frame_unref(filt_frame); } av_frame_unref(frame); } } } av_packet_unref(packet); } end: avfilter_graph_free(&filter_graph); avcodec_free_context(&dec_ctx); avformat_close_input(&fmt_ctx); av_packet_free(&packet); av_frame_free(&frame); av_frame_free(&filt_frame); if (ret < 0 && ret != AVERROR_EOF) { fprintf(stderr, "Error occurred: %s\n", av_err2str(ret)); exit(1); } exit(0); }
4c774ed5d7b90471d5db07be1bcff78f3d45fc8d
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/drivers/net/ethernet/ti/davinci_mdio.c
c47f0dbcebb513d7a33c49c92725350e13d73c6e
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "LicenseRef-scancode-free-unknown", "Apache-2.0", "LicenseRef-scancode-warranty-disclaimer" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
12,105
c
davinci_mdio.c
/* * DaVinci MDIO Module driver * * Copyright (C) 2010 Texas Instruments. * * Shamelessly ripped out of davinci_emac.c, original copyrights follow: * * Copyright (C) 2009 Texas Instruments. * * --------------------------------------------------------------------------- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * --------------------------------------------------------------------------- */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/platform_device.h> #include <linux/delay.h> #include <linux/sched.h> #include <linux/slab.h> #include <linux/phy.h> #include <linux/clk.h> #include <linux/err.h> #include <linux/io.h> #include <linux/pm_runtime.h> #include <linux/davinci_emac.h> #include <linux/of.h> #include <linux/of_device.h> /* * This timeout definition is a worst-case ultra defensive measure against * unexpected controller lock ups. Ideally, we should never ever hit this * scenario in practice. */ #define MDIO_TIMEOUT 100 /* msecs */ #define PHY_REG_MASK 0x1f #define PHY_ID_MASK 0x1f #define DEF_OUT_FREQ 2200000 /* 2.2 MHz */ struct davinci_mdio_regs { u32 version; u32 control; #define CONTROL_IDLE BIT(31) #define CONTROL_ENABLE BIT(30) #define CONTROL_MAX_DIV (0xffff) u32 alive; u32 link; u32 linkintraw; u32 linkintmasked; u32 __reserved_0[2]; u32 userintraw; u32 userintmasked; u32 userintmaskset; u32 userintmaskclr; u32 __reserved_1[20]; struct { u32 access; #define USERACCESS_GO BIT(31) #define USERACCESS_WRITE BIT(30) #define USERACCESS_ACK BIT(29) #define USERACCESS_READ (0) #define USERACCESS_DATA (0xffff) u32 physel; } user[0]; }; struct mdio_platform_data default_pdata = { .bus_freq = DEF_OUT_FREQ, }; struct davinci_mdio_data { struct mdio_platform_data pdata; struct davinci_mdio_regs __iomem *regs; spinlock_t lock; struct clk *clk; struct device *dev; struct mii_bus *bus; bool suspended; unsigned long access_time; /* jiffies */ }; static void __davinci_mdio_reset(struct davinci_mdio_data *data) { u32 mdio_in, div, mdio_out_khz, access_time; mdio_in = clk_get_rate(data->clk); div = (mdio_in / data->pdata.bus_freq) - 1; if (div > CONTROL_MAX_DIV) div = CONTROL_MAX_DIV; /* set enable and clock divider */ __raw_writel(div | CONTROL_ENABLE, &data->regs->control); /* * One mdio transaction consists of: * 32 bits of preamble * 32 bits of transferred data * 24 bits of bus yield (not needed unless shared?) */ mdio_out_khz = mdio_in / (1000 * (div + 1)); access_time = (88 * 1000) / mdio_out_khz; /* * In the worst case, we could be kicking off a user-access immediately * after the mdio bus scan state-machine triggered its own read. If * so, our request could get deferred by one access cycle. We * defensively allow for 4 access cycles. */ data->access_time = usecs_to_jiffies(access_time * 4); if (!data->access_time) data->access_time = 1; } static int davinci_mdio_reset(struct mii_bus *bus) { struct davinci_mdio_data *data = bus->priv; u32 phy_mask, ver; __davinci_mdio_reset(data); /* wait for scan logic to settle */ msleep(PHY_MAX_ADDR * data->access_time); /* dump hardware version info */ ver = __raw_readl(&data->regs->version); dev_info(data->dev, "davinci mdio revision %d.%d\n", (ver >> 8) & 0xff, ver & 0xff); /* get phy mask from the alive register */ phy_mask = __raw_readl(&data->regs->alive); if (phy_mask) { /* restrict mdio bus to live phys only */ dev_info(data->dev, "detected phy mask %x\n", ~phy_mask); phy_mask = ~phy_mask; } else { /* desperately scan all phys */ dev_warn(data->dev, "no live phy, scanning all\n"); phy_mask = 0; } data->bus->phy_mask = phy_mask; return 0; } /* wait until hardware is ready for another user access */ static inline int wait_for_user_access(struct davinci_mdio_data *data) { struct davinci_mdio_regs __iomem *regs = data->regs; unsigned long timeout = jiffies + msecs_to_jiffies(MDIO_TIMEOUT); u32 reg; while (time_after(timeout, jiffies)) { reg = __raw_readl(&regs->user[0].access); if ((reg & USERACCESS_GO) == 0) return 0; reg = __raw_readl(&regs->control); if ((reg & CONTROL_IDLE) == 0) continue; /* * An emac soft_reset may have clobbered the mdio controller's * state machine. We need to reset and retry the current * operation */ dev_warn(data->dev, "resetting idled controller\n"); __davinci_mdio_reset(data); return -EAGAIN; } reg = __raw_readl(&regs->user[0].access); if ((reg & USERACCESS_GO) == 0) return 0; dev_err(data->dev, "timed out waiting for user access\n"); return -ETIMEDOUT; } /* wait until hardware state machine is idle */ static inline int wait_for_idle(struct davinci_mdio_data *data) { struct davinci_mdio_regs __iomem *regs = data->regs; unsigned long timeout = jiffies + msecs_to_jiffies(MDIO_TIMEOUT); while (time_after(timeout, jiffies)) { if (__raw_readl(&regs->control) & CONTROL_IDLE) return 0; } dev_err(data->dev, "timed out waiting for idle\n"); return -ETIMEDOUT; } static int davinci_mdio_read(struct mii_bus *bus, int phy_id, int phy_reg) { struct davinci_mdio_data *data = bus->priv; u32 reg; int ret; if (phy_reg & ~PHY_REG_MASK || phy_id & ~PHY_ID_MASK) return -EINVAL; spin_lock(&data->lock); if (data->suspended) { spin_unlock(&data->lock); return -ENODEV; } reg = (USERACCESS_GO | USERACCESS_READ | (phy_reg << 21) | (phy_id << 16)); while (1) { ret = wait_for_user_access(data); if (ret == -EAGAIN) continue; if (ret < 0) break; __raw_writel(reg, &data->regs->user[0].access); ret = wait_for_user_access(data); if (ret == -EAGAIN) continue; if (ret < 0) break; reg = __raw_readl(&data->regs->user[0].access); ret = (reg & USERACCESS_ACK) ? (reg & USERACCESS_DATA) : -EIO; break; } spin_unlock(&data->lock); return ret; } static int davinci_mdio_write(struct mii_bus *bus, int phy_id, int phy_reg, u16 phy_data) { struct davinci_mdio_data *data = bus->priv; u32 reg; int ret; if (phy_reg & ~PHY_REG_MASK || phy_id & ~PHY_ID_MASK) return -EINVAL; spin_lock(&data->lock); if (data->suspended) { spin_unlock(&data->lock); return -ENODEV; } reg = (USERACCESS_GO | USERACCESS_WRITE | (phy_reg << 21) | (phy_id << 16) | (phy_data & USERACCESS_DATA)); while (1) { ret = wait_for_user_access(data); if (ret == -EAGAIN) continue; if (ret < 0) break; __raw_writel(reg, &data->regs->user[0].access); ret = wait_for_user_access(data); if (ret == -EAGAIN) continue; break; } spin_unlock(&data->lock); return 0; } static int davinci_mdio_probe_dt(struct mdio_platform_data *data, struct platform_device *pdev) { struct device_node *node = pdev->dev.of_node; u32 prop; if (!node) return -EINVAL; if (of_property_read_u32(node, "bus_freq", &prop)) { pr_err("Missing bus_freq property in the DT.\n"); return -EINVAL; } data->bus_freq = prop; return 0; } static int davinci_mdio_probe(struct platform_device *pdev) { struct mdio_platform_data *pdata = pdev->dev.platform_data; struct device *dev = &pdev->dev; struct davinci_mdio_data *data; struct resource *res; struct phy_device *phy; int ret, addr; data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; data->bus = mdiobus_alloc(); if (!data->bus) { dev_err(dev, "failed to alloc mii bus\n"); ret = -ENOMEM; goto bail_out; } if (dev->of_node) { if (davinci_mdio_probe_dt(&data->pdata, pdev)) data->pdata = default_pdata; snprintf(data->bus->id, MII_BUS_ID_SIZE, "%s", pdev->name); } else { data->pdata = pdata ? (*pdata) : default_pdata; snprintf(data->bus->id, MII_BUS_ID_SIZE, "%s-%x", pdev->name, pdev->id); } data->bus->name = dev_name(dev); data->bus->read = davinci_mdio_read, data->bus->write = davinci_mdio_write, data->bus->reset = davinci_mdio_reset, data->bus->parent = dev; data->bus->priv = data; pm_runtime_enable(&pdev->dev); pm_runtime_get_sync(&pdev->dev); data->clk = clk_get(&pdev->dev, "fck"); if (IS_ERR(data->clk)) { dev_err(dev, "failed to get device clock\n"); ret = PTR_ERR(data->clk); data->clk = NULL; goto bail_out; } dev_set_drvdata(dev, data); data->dev = dev; spin_lock_init(&data->lock); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(dev, "could not find register map resource\n"); ret = -ENOENT; goto bail_out; } res = devm_request_mem_region(dev, res->start, resource_size(res), dev_name(dev)); if (!res) { dev_err(dev, "could not allocate register map resource\n"); ret = -ENXIO; goto bail_out; } data->regs = devm_ioremap_nocache(dev, res->start, resource_size(res)); if (!data->regs) { dev_err(dev, "could not map mdio registers\n"); ret = -ENOMEM; goto bail_out; } /* register the mii bus */ ret = mdiobus_register(data->bus); if (ret) goto bail_out; /* scan and dump the bus */ for (addr = 0; addr < PHY_MAX_ADDR; addr++) { phy = data->bus->phy_map[addr]; if (phy) { dev_info(dev, "phy[%d]: device %s, driver %s\n", phy->addr, dev_name(&phy->dev), phy->drv ? phy->drv->name : "unknown"); } } return 0; bail_out: if (data->bus) mdiobus_free(data->bus); if (data->clk) clk_put(data->clk); pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); kfree(data); return ret; } static int davinci_mdio_remove(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct davinci_mdio_data *data = dev_get_drvdata(dev); if (data->bus) { mdiobus_unregister(data->bus); mdiobus_free(data->bus); } if (data->clk) clk_put(data->clk); pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); dev_set_drvdata(dev, NULL); kfree(data); return 0; } static int davinci_mdio_suspend(struct device *dev) { struct davinci_mdio_data *data = dev_get_drvdata(dev); u32 ctrl; spin_lock(&data->lock); /* shutdown the scan state machine */ ctrl = __raw_readl(&data->regs->control); ctrl &= ~CONTROL_ENABLE; __raw_writel(ctrl, &data->regs->control); wait_for_idle(data); data->suspended = true; spin_unlock(&data->lock); pm_runtime_put_sync(data->dev); return 0; } static int davinci_mdio_resume(struct device *dev) { struct davinci_mdio_data *data = dev_get_drvdata(dev); pm_runtime_get_sync(data->dev); spin_lock(&data->lock); /* restart the scan state machine */ __davinci_mdio_reset(data); data->suspended = false; spin_unlock(&data->lock); return 0; } static const struct dev_pm_ops davinci_mdio_pm_ops = { .suspend_late = davinci_mdio_suspend, .resume_early = davinci_mdio_resume, }; static const struct of_device_id davinci_mdio_of_mtable[] = { { .compatible = "ti,davinci_mdio", }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(of, davinci_mdio_of_mtable); static struct platform_driver davinci_mdio_driver = { .driver = { .name = "davinci_mdio", .owner = THIS_MODULE, .pm = &davinci_mdio_pm_ops, .of_match_table = of_match_ptr(davinci_mdio_of_mtable), }, .probe = davinci_mdio_probe, .remove = davinci_mdio_remove, }; static int __init davinci_mdio_init(void) { return platform_driver_register(&davinci_mdio_driver); } device_initcall(davinci_mdio_init); static void __exit davinci_mdio_exit(void) { platform_driver_unregister(&davinci_mdio_driver); } module_exit(davinci_mdio_exit); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("DaVinci MDIO driver");
1de9775fbd00225856d5c14e0a3aab33411020ff
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/arch/arm/mach-exynos/dev-ohci.c
d5bc129e6bb77e989524ae8135066ade732435b2
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
1,343
c
dev-ohci.c
/* linux/arch/arm/mach-exynos/dev-ohci.c * * Copyright (c) 2011 Samsung Electronics Co., Ltd. * http://www.samsung.com * * EXYNOS - OHCI support * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/dma-mapping.h> #include <linux/platform_device.h> #include <linux/platform_data/usb-ohci-exynos.h> #include <mach/irqs.h> #include <mach/map.h> #include <plat/devs.h> #include <plat/usb-phy.h> static struct resource exynos4_ohci_resource[] = { [0] = DEFINE_RES_MEM(EXYNOS4_PA_OHCI, SZ_256), [1] = DEFINE_RES_IRQ(IRQ_USB_HOST), }; static u64 exynos4_ohci_dma_mask = DMA_BIT_MASK(32); struct platform_device exynos4_device_ohci = { .name = "exynos-ohci", .id = -1, .num_resources = ARRAY_SIZE(exynos4_ohci_resource), .resource = exynos4_ohci_resource, .dev = { .dma_mask = &exynos4_ohci_dma_mask, .coherent_dma_mask = DMA_BIT_MASK(32), } }; void __init exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd) { struct exynos4_ohci_platdata *npd; npd = s3c_set_platdata(pd, sizeof(struct exynos4_ohci_platdata), &exynos4_device_ohci); if (!npd->phy_init) npd->phy_init = s5p_usb_phy_init; if (!npd->phy_exit) npd->phy_exit = s5p_usb_phy_exit; }
4f7d5a11b03f3c34f44fc3055eff0dae447b3d7d
17d7357e5c5130ace022b3c9d9f98e7b13dda0ca
/src/coding/mpeg_custom_utils.c
b86c9c3822a1e902ece96f237ce6b412dc884756
[ "ISC", "LicenseRef-scancode-public-domain" ]
permissive
vgmstream/vgmstream
4a7747bb75ff513f8fc8cc26f31d6e3a4150bc43
883d796d4b63c42810586e9f1ffbdcdd28c73ef5
refs/heads/master
2023-09-04T16:14:38.136915
2023-09-02T18:06:38
2023-09-02T18:06:38
5,591,410
762
137
NOASSERTION
2023-09-10T22:58:26
2012-08-28T20:08:24
C
UTF-8
C
false
false
21,887
c
mpeg_custom_utils.c
#include "mpeg_decoder.h" #ifdef VGM_USE_MPEG /* init config and validate per type */ int mpeg_custom_setup_init_default(STREAMFILE* sf, off_t start_offset, mpeg_codec_data* data, coding_t* coding_type) { mpeg_frame_info info; /* get frame info at offset */ if ( !mpeg_get_frame_info(sf, start_offset, &info)) goto fail; switch(info.layer) { case 1: *coding_type = coding_MPEG_layer1; break; case 2: *coding_type = coding_MPEG_layer2; break; case 3: *coding_type = coding_MPEG_layer3; break; default: goto fail; } data->channels_per_frame = info.channels; data->samples_per_frame = info.frame_samples; data->bitrate_per_frame = info.bit_rate; data->sample_rate_per_frame = info.sample_rate; /* extra checks per type */ switch(data->type) { case MPEG_XVAG: if (data->config.chunk_size <= 0 || data->config.interleave <= 0) goto fail; /* needs external fixed size */ break; case MPEG_FSB: if (data->config.fsb_padding != 0 && data->config.fsb_padding != 2 && data->config.fsb_padding != 4 && data->config.fsb_padding != 16) goto fail; /* aligned to closest 0/2/4/16 bytes */ /* get find interleave to stream offsets are set up externally */ { int current_data_size = info.frame_size; int current_padding = 0; /* FSB padding for Layer III or multichannel Layer II */ if ((info.layer == 3 && data->config.fsb_padding) || data->config.fsb_padding == 16) { current_padding = (current_data_size % data->config.fsb_padding) ? data->config.fsb_padding - (current_data_size % data->config.fsb_padding) : 0; } data->config.interleave = current_data_size + current_padding; /* should be constant for all stream */ } break; //todo simplify/unify XVAG/P3D/SCD/LYN and just feed arbitrary chunks to the decoder case MPEG_P3D: case MPEG_SCD: if (data->config.interleave <= 0) goto fail; /* needs external fixed size */ break; case MPEG_LYN: if (data->config.interleave <= 0) goto fail; /* needs external fixed size */ data->default_buffer_size = data->config.interleave; if (data->default_buffer_size < data->config.interleave_last) data->default_buffer_size = data->config.interleave_last; break; case MPEG_STANDARD: case MPEG_AHX: case MPEG_EA: if (info.channels != data->config.channels) goto fail; /* no multichannel expected */ break; default: break; /* nothing special needed */ } //todo: test more: this improves the output, but seems formats aren't usually prepared // (and/or the num_samples includes all possible samples in file, so by discarding some it'll reach EOF) /* set encoder delay (samples to skip at the beginning of a stream) if needed, which varies with encoder used */ switch(data->type) { //case MPEG_AHX: data->skip_samples = 480; break; /* observed default */ //case MPEG_P3D: data->skip_samples = info.frame_samples; break; /* matches Radical ADPCM (PC) output */ /* FSBs (with FMOD DLLs) don't seem to need it. Particularly a few games (all from Wayforward?) * contain audible garbage at the beginning, but it's actually there in-game too. * Games doing full loops also must not have delay (reuses mpeg state on loop) */ case MPEG_FSB: data->skip_samples = 0; break; case MPEG_XVAG: /* set in header and needed for gapless looping */ data->skip_samples = data->config.skip_samples; break; case MPEG_STANDARD: data->skip_samples = data->config.skip_samples; break; case MPEG_EA: /* typical MP2 decoder delay, verified vs sx.exe, also SCHl blocks header takes discard * samples into account (so block_samples+240*2+1 = total frame samples) */ if (info.layer == 2) { data->skip_samples = 240*2 + 1; } /* MP3 probably uses 576 + 528+1 but no known games use it */ break; default: break; } data->samples_to_discard = data->skip_samples; return 1; fail: return 0; } /* writes data to the buffer and moves offsets */ int mpeg_custom_parse_frame_default(VGMSTREAMCHANNEL* stream, mpeg_codec_data* data, int num_stream) { mpeg_custom_stream *ms = data->streams[num_stream]; mpeg_frame_info info; size_t current_data_size = 0; size_t current_padding = 0; size_t current_interleave_pre = 0; /* interleaved data size before current stream */ size_t current_interleave_post = 0; /* interleaved data size after current stream */ size_t current_interleave = 0; /* interleave in this block (usually this + pre + post = interleave*streams = block) */ /* Get data size to give to the decoder, per stream. Usually 1 frame at a time, * but doesn't really need to be a full frame (decoder would request more data). */ switch(data->type) { case MPEG_XVAG: /* frames of fixed size (though we could read frame info too) */ current_interleave = data->config.interleave; /* big interleave */ current_interleave_pre = current_interleave*num_stream; current_interleave_post = current_interleave*(data->streams_size-1) - current_interleave_pre; current_data_size = data->config.chunk_size; break; case MPEG_FSB: /* frames with padding + interleave */ current_interleave = data->config.interleave; /* constant for multi-stream FSbs (1 frame + padding) */ current_interleave_pre = current_interleave*num_stream; current_interleave_post = current_interleave*(data->streams_size-1) - current_interleave_pre; if (!mpeg_get_frame_info(stream->streamfile, stream->offset + current_interleave_pre, &info)) goto fail; current_data_size = info.frame_size; /* get FSB padding for Layer III or multichannel Layer II (Layer I isn't supported by FMOD). * Padding sometimes contains garbage like the next frame header so we can't feed it to mpg123 or it gets confused. */ if ((info.layer == 3 && data->config.fsb_padding) || data->config.fsb_padding == 16) { current_padding = (current_data_size % data->config.fsb_padding) ? data->config.fsb_padding - (current_data_size % data->config.fsb_padding) : 0; /* Rare Mafia II (PS3) bug (GP_0701_music multilang only): some frame paddings "4" are incorrect, * calcs give 0xD0+0x00 but need 0xD0+0x04 (unlike all other fsbs, which never do that). * FMOD tools decode fine, so they may be doing special detection too, since even * re-encoding the same file and using the same FSB flags/modes won't trigger the bug. */ if (info.layer == 3 && data->config.fsb_padding == 4 && current_data_size == 0xD0) { uint32_t next_header; off_t next_offset; next_offset = stream->offset + current_data_size + current_padding; if (current_interleave && ((next_offset - stream->channel_start_offset + current_interleave_pre + current_interleave_post) % current_interleave == 0)) { next_offset += current_interleave_pre + current_interleave_post; } next_header = read_32bitBE(next_offset, stream->streamfile); if ((next_header & 0xFFE00000) != 0xFFE00000) { /* doesn't land in a proper frame, fix sizes and hope */ VGM_LOG_ONCE("MPEG FSB: stream with wrong padding found\n"); current_padding = 0x04; } } } VGM_ASSERT(data->streams_size > 1 && current_interleave != current_data_size+current_padding, "MPEG FSB: %i streams with non-constant interleave found @ 0x%08x\n", data->streams_size, (uint32_t)stream->offset); break; case MPEG_P3D: /* fixed interleave, not frame-aligned (ie. blocks may end/start in part of a frame) */ case MPEG_SCD: current_interleave = data->config.interleave; /* check if current interleave block is short */ { off_t block_offset = stream->offset - stream->channel_start_offset; size_t next_block = data->streams_size*data->config.interleave; if (data->config.data_size && block_offset + next_block >= data->config.data_size) current_interleave = (data->config.data_size % next_block) / data->streams_size; /* short_interleave*/ } current_interleave_pre = current_interleave*num_stream; current_interleave_post = current_interleave*(data->streams_size-1) - current_interleave_pre; current_data_size = current_interleave; break; case MPEG_LYN: /* after N interleaves last block is bigger */ if (ms->current_size_count < data->config.max_chunks) current_interleave = data->config.interleave; else if (ms->current_size_count == data->config.max_chunks) current_interleave = data->config.interleave_last; else goto fail; current_interleave_pre = current_interleave*num_stream; current_interleave_post = current_interleave*(data->streams_size-1) - current_interleave_pre; //VGM_LOG("o=%lx, %i: %x, %x, %x, %x\n", stream->offset, num_stream, ms->current_size_count, current_interleave, current_interleave_pre, current_interleave_post ); current_data_size = current_interleave; ms->current_size_count++; break; default: /* standard frames (CBR or VBR) */ if ( !mpeg_get_frame_info(stream->streamfile, stream->offset, &info) ) goto fail; current_data_size = info.frame_size; break; } if (!current_data_size || current_data_size > ms->buffer_size) { VGM_LOG("MPEG: incorrect data_size 0x%x vs buffer 0x%x\n", current_data_size, ms->buffer_size); goto fail; } /* This assumes all streams' offsets start in the first stream, and advances * the 'full interleaved block' at once, ex: * start at s0=0x00, s1=0x00, interleave=0x40 (block = 0x40*2=0x80) * @0x00 read 0x40 of s0, skip 0x40 of s1 (block of 0x80 done) > new offset = 0x80 * @0x00 skip 0x40 of s0, read 0x40 of s1 (block of 0x80 done) > new offset = 0x800 */ /* read chunk (skipping other interleaves if needed) */ ms->bytes_in_buffer = read_streamfile(ms->buffer,stream->offset + current_interleave_pre, current_data_size, stream->streamfile); /* update offsets and skip other streams */ stream->offset += current_data_size + current_padding; /* skip rest of block (interleave per stream) once this stream's interleaved data is done, if defined */ if (current_interleave && ((stream->offset - stream->channel_start_offset + current_interleave_pre + current_interleave_post) % current_interleave == 0)) { stream->offset += current_interleave_pre + current_interleave_post; } return 1; fail: return 0; } #endif //TODO: move to a better place /*****************/ /* FRAME HELPERS */ /*****************/ /** * Gets info from a MPEG frame header at offset. Normally you would use mpg123_info but somehow * it's wrong at times (maybe because we use an ancient version) so here we do our thing. */ static int mpeg_get_frame_info_h(uint32_t header, mpeg_frame_info* info) { /* index tables */ static const int versions[4] = { /* MPEG 2.5 */ 3, /* reserved */ -1, /* MPEG 2 */ 2, /* MPEG 1 */ 1 }; static const int layers[4] = { -1,3,2,1 }; static const int bit_rates[5][16] = { /* [version index ][bit rate index] (0=free, -1=bad) */ { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, -1 }, /* MPEG1 Layer I */ { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, -1 }, /* MPEG1 Layer II */ { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1 }, /* MPEG1 Layer III */ { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, -1 }, /* MPEG2/2.5 Layer I */ { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, -1 }, /* MPEG2/2.5 Layer II/III */ }; static const int sample_rates[4][4] = { /* [version][sample rate index] */ { 44100, 48000, 32000, -1}, /* MPEG1 */ { 22050, 24000, 16000, -1}, /* MPEG2 */ { 11025, 12000, 8000, -1}, /* MPEG2.5 */ }; static const int channels[4] = { 2,2,2, 1 }; /* [channel] */ static const int frame_samples[3][3] = { /* [version][layer] */ { 384, 1152, 1152 }, /* MPEG1 */ { 384, 1152, 576 }, /* MPEG2 */ { 384, 1152, 576 } /* MPEG2.5 */ }; int idx, padding; memset(info, 0, sizeof(*info)); if ((header >> 21) != 0x7FF) /* 31-21: sync */ goto fail; info->version = versions[(header >> 19) & 0x3]; /* 20,19: version */ if (info->version <= 0) goto fail; info->layer = layers[(header >> 17) & 0x3]; /* 18,17: layer */ if (info->layer <= 0 || info->layer > 3) goto fail; //crc = (header >> 16) & 0x1; /* 16: protected by crc? */ idx = (info->version==1 ? info->layer-1 : (3 + (info->layer==1 ? 0 : 1))); info->bit_rate = bit_rates[idx][(header >> 12) & 0xf]; /* 15-12: bit rate */ if (info->bit_rate <= 0) goto fail; info->sample_rate = sample_rates[info->version-1][(header >> 10) & 0x3]; /* 11-10: sampling rate */ if (info->sample_rate <= 0) goto fail; padding = (header >> 9) & 0x1; /* 9: padding? */ //private = (header >> 8) & 0x1; /* 8: private bit */ info->channels = channels[(header >> 6) & 0x3]; /* 7,6: channel mode */ //js_mode = (header >> 4) & 0x3; /* 5,4: mode extension for joint stereo */ //copyright = (header >> 3) & 0x1; /* 3: copyrighted */ //original = (header >> 2) & 0x1; /* 2: original */ //emphasis = (header >> 0) & 0x3; /* 1,0: emphasis */ info->frame_samples = frame_samples[info->version-1][info->layer-1]; /* calculate frame length (from hcs's fsb_mpeg) */ switch (info->frame_samples) { case 384: info->frame_size = (12l * info->bit_rate * 1000l / info->sample_rate + padding) * 4; break; /* 384/32 = 12 */ case 576: info->frame_size = (72l * info->bit_rate * 1000l / info->sample_rate + padding); break; /* 576/8 = 72 */ case 1152: info->frame_size = (144l * info->bit_rate * 1000l / info->sample_rate + padding); break; /* 1152/8 = 144 */ default: goto fail; } return 1; fail: return 0; } int mpeg_get_frame_info(STREAMFILE* sf, off_t offset, mpeg_frame_info* info) { uint32_t header = read_u32be(offset, sf); return mpeg_get_frame_info_h(header, info); } uint32_t mpeg_get_tag_size(STREAMFILE* sf, uint32_t offset, uint32_t header) { if (!header) header = read_u32be(offset+0x00, sf); /* skip ID3v2 */ if ((header & 0xFFFFFF00) == get_id32be("ID3\0")) { size_t frame_size = 0; uint8_t flags = read_u8(offset+0x05, sf); /* this is how it's officially read :/ */ frame_size += read_u8(offset+0x06, sf) << 21; frame_size += read_u8(offset+0x07, sf) << 14; frame_size += read_u8(offset+0x08, sf) << 7; frame_size += read_u8(offset+0x09, sf) << 0; frame_size += 0x0a; if (flags & 0x10) /* footer? */ frame_size += 0x0a; return frame_size; } /* skip ID3v1 */ if ((header & 0xFFFFFF00) == get_id32be("TAG\0")) { ;VGM_LOG("MPEG: ID3v1 at %x\n", offset); return 0x80; } return 0; } size_t mpeg_get_samples(STREAMFILE* sf, off_t start_offset, size_t bytes) { off_t offset = start_offset; off_t max_offset = start_offset + bytes; int frames = 0, samples = 0, encoder_delay = 0, encoder_padding = 0; mpeg_frame_info info; if (!sf) return 0; if (max_offset > get_streamfile_size(sf)) max_offset = get_streamfile_size(sf); /* MPEG may use VBR so must read all frames */ while (offset < max_offset) { uint32_t header = read_u32be(offset+0x00, sf); size_t tag_size = mpeg_get_tag_size(sf, offset, header); if (tag_size) { offset += tag_size; continue; } /* regular frame (assumed) */ if (!mpeg_get_frame_info_h(header, &info)) { VGM_LOG("MPEG: unknown frame at %lx\n", offset); break; } /* detect Xing header (disguised as a normal frame) */ if (frames < 3) { /* should be first after tags */ /* frame is empty so Xing goes after MPEG side info */ off_t xing_offset; if (info.version == 1) xing_offset = (info.channels == 2 ? 0x20 : 0x11) + 0x04; else xing_offset = (info.channels == 2 ? 0x11 : 0x09) + 0x04; if (info.frame_size >= xing_offset + 0x78 && read_u32be(offset + 0x04, sf) == 0 && /* empty frame */ (read_u32be(offset + xing_offset, sf) == 0x58696E67 || /* "Xing" (mainly for VBR) */ read_u32be(offset + xing_offset, sf) == 0x496E666F)) { /* "Info" (mainly for CBR) */ uint32_t flags = read_u32be(offset + xing_offset + 0x04, sf); if (flags & 1) { uint32_t frame_count = read_u32be(offset + xing_offset + 0x08, sf); samples = frame_count * info.frame_samples; } /* other flags indicate seek table and stuff */ ;VGM_LOG("MPEG: found Xing header\n"); /* vendor specific */ if (info.frame_size > xing_offset + 0x78 + 0x24) { uint32_t sub_id = read_u32be(offset + xing_offset + 0x78, sf); if (sub_id == get_id32be("LAME") || /* LAME */ sub_id == get_id32be("Lavc")) { /* FFmpeg */ if (info.layer == 3) { uint32_t delays = read_u32be(offset + xing_offset + 0x8C, sf); encoder_delay = ((delays >> 12) & 0xFFF); encoder_padding = ((delays >> 0) & 0xFFF); encoder_delay += (528 + 1); /* implicit MDCT decoder delay (seen in LAME source) */ if (encoder_padding > 528 + 1) encoder_padding -= (528 + 1); } else { encoder_delay = 240 + 1; } } /* replay gain and stuff */ } /* there is also "iTunes" vendor with no apparent extra info, iTunes delays are in "iTunSMPB" ID3 tag */ break; /* we got samples */ } } //TODO: detect "VBRI" header (Fraunhofer encoder) // https://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header#VBRIHeader /* could detect VBR/CBR but read frames to remove ID3 end tags */ frames++; offset += info.frame_size; samples += info.frame_samples; } ;VGM_LOG("MPEG: samples=%i, ed=%i, ep=%i, end=%i\n", samples,encoder_delay,encoder_padding, samples - encoder_delay - encoder_padding); //todo return encoder delay samples = samples - encoder_delay - encoder_padding; return samples; } /* variation of the above, for clean streams = no ID3/VBR headers * (maybe should be fused in a single thing with config, API is kinda messy too) */ int32_t mpeg_get_samples_clean(STREAMFILE* sf, off_t start, size_t size, uint32_t* p_loop_start, uint32_t* p_loop_end, int is_vbr) { mpeg_frame_info info; off_t offset = start; int32_t num_samples = 0, loop_start = 0, loop_end = 0; if (!is_vbr) { /* CBR = quick calcs */ if (!mpeg_get_frame_info(sf, offset, &info)) goto fail; num_samples = size / info.frame_size * info.frame_samples; if (p_loop_start) loop_start = *p_loop_start / info.frame_size * info.frame_samples; if (p_loop_end) loop_end = *p_loop_end / info.frame_size * info.frame_samples; } else { /* VBR (or unknown) = count frames */ while (offset < start + size) { if (!mpeg_get_frame_info(sf, offset, &info)) goto fail; if (p_loop_start && *p_loop_start + start == offset) loop_start = num_samples; num_samples += info.frame_samples; offset += info.frame_size; if (p_loop_end && *p_loop_end + start == offset) loop_end = num_samples; } } if (p_loop_start) *p_loop_start = loop_start; if (p_loop_end) *p_loop_end = loop_end; return num_samples; fail: VGM_LOG("MPEG: sample reader failed at %lx\n", offset); return 0; }
29714b83644230f2bac281a80c7996fd6aa4d29d
14ed2724b7c610543959f23d401e7b90283e63c4
/Source/dlnewtrn.c
e5643a0e564978f4d407f5b24a6e8168ab5319cd
[ "MIT" ]
permissive
powervr-graphics/PowerVR-Series1
d0ec36623d257e05c078e5d3f4bdfcd786ba46a4
c8c11cbe29c5b758ed1ef9600fc8614fc8da618e
refs/heads/main
2023-08-14T18:42:40.609670
2022-03-23T10:29:37
2022-03-23T10:29:37
467,444,934
260
17
null
null
null
null
UTF-8
C
false
false
1,927
c
dlnewtrn.c
/****************************************************************************** * Name : dltransf.c * Title : Transformation Display List Routine, List nodes * Author : Stel Michael * Created : 1/05/1995 * * Copyright : 1995-2022 Imagination Technologies (c) * License : MIT * * Description : SGL Routines for adding a new translucent node * * Platform : ANSI compatible * * Modifications:- * $Log: dlnewtrn.c,v $ * Revision 1.6 1997/05/13 17:52:30 mjg * Added sglmem include. * * Revision 1.5 1997/05/02 07:42:44 erf * Removed UINT32's etc and replaced with sgl_uint32's etc. * * Revision 1.4 1997/04/24 20:53:57 gdc * sgl now initialsed form DllMain in windows builds * * Revision 1.3 1997/04/04 13:02:57 jop * Added explicit #include "pvrosapi.h" * * Revision 1.2 1997/04/03 13:12:34 mjg * Updated the calling convention. * * Revision 1.1 1995/09/04 15:36:10 sm * Initial revision * * *****************************************************************************/ #include "sgl_defs.h" #include "sgl_init.h" #include "dlnodes.h" #include "nm_intf.h" #include "dlglobal.h" #include "pvrosapi.h" #include "sglmem.h" void CALL_CONV sgl_new_translucent() { NTRAN_NODE_STRUCT * pNode; /* Initialise sgl if this hasn't yet been done */ #if !WIN32 if(SglInitialise() != 0) { /* We failed to initialise sgl */ SglError(sgl_err_failed_init); return; } #endif /* Create a new translucent node */ pNode = NEW(NTRAN_NODE_STRUCT); if(pNode == NULL) { /* Abort */ SglError(sgl_err_no_mem); return; } pNode->node_hdr.n16_node_type = (sgl_int16) nt_newtran; pNode->node_hdr.n16_name = (sgl_int16) NM_INVALID_NAME; pNode->node_hdr.next_node = NULL; AppendNodeToList(dlUserGlobals.pCurrentList, pNode); SglError(sgl_no_err); } /*--------------------------- End of File --------------------------------*/
c3b2a6d3c7879413af3e73d82726fd8c1a363ced
99bdb3251fecee538e0630f15f6574054dfc1468
/bsp/allwinner/libraries/sunxi-hal/hal/source/g2d_rcq/g2d_bld.c
b62922f86a8651d95ef58803f934bbb9c7da5a2c
[ "Apache-2.0", "Zlib", "LicenseRef-scancode-proprietary-license", "MIT", "BSD-3-Clause", "X11", "BSD-4-Clause-UC", "LicenseRef-scancode-unknown-license-reference" ]
permissive
RT-Thread/rt-thread
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
3602f891211904a27dcbd51e5ba72fefce7326b2
refs/heads/master
2023-09-01T04:10:20.295801
2023-08-31T16:20:55
2023-08-31T16:20:55
7,408,108
9,599
5,805
Apache-2.0
2023-09-14T13:37:26
2013-01-02T14:49:21
C
UTF-8
C
false
false
16,151
c
g2d_bld.c
/* * g2d_bld/g2d_bld.c * * Copyright (c) 2007-2019 Allwinnertech Co., Ltd. * Author: zhengxiaobin <zhengxiaobin@allwinnertech.com> * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and * may be copied, distributed, and modified under those terms. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ #include <stdlib.h> #include "g2d_bld.h" __s32 rgb2Ycbcr_709[12] = { 0x0bb, 0x0275, 0x03f, 0x4200, 0xFFFFFF99, 0xFFFFFEA6, 0x01c2, 0x20200, 0x01c2, 0xFFFFFE67, 0xFFFFFFD7, 0x20200, }; __s32 Ycbcr2rgb_709[12] = { 0x04a8, 0x0, 0x072c, 0xFFFC1F7D, 0x04a8, 0xFFFFFF26, 0xFFFFFDDD, 0x133F8, 0x04a8, 0x0876, 0, 0xFFFB7AA0, }; __s32 rgb2Ycbcr_601[12] = { 0x0107, 0x0204, 0x064, 0x4200, 0xFFFFFF68, 0xFFFFFED6, 0x01c2, 0x20200, 0x01c2, 0xFFFFFE87, 0xFFFFFFB7, 0x20200,}; __s32 Ycbcr2rgb_601[12] = { 0x04a8, 0x0, 0x0662, 0xFFFC865A, 0x04a8, 0xFFFFFE70, 0xFFFFFCBF, 0x21FF4, 0x04a8, 0x0812, 0x0, 0xFFFBAE4A,}; /* * sel: 0-->pipe0 1-->pipe1 other:error */ __s32 bld_in_set(struct blender_submodule *p_bld, __u32 sel, g2d_rect rect, int premul) { __s32 ret = -1; struct g2d_mixer_bld_reg *p_reg = NULL; p_reg = p_bld->get_reg(p_bld); if (!p_reg) goto OUT; if (sel == 0) { p_reg->bld_en_ctrl.bits.p0_en = 1; /* we best use p0 as bottom layer */ p_reg->bld_en_ctrl.bits.p0_fcen = 1; if (premul) p_reg->premulti_ctrl.bits.p0_alpha_mode = 1; } else if (sel == 1) { p_reg->bld_en_ctrl.bits.p1_en = 1; if (premul) p_reg->premulti_ctrl.bits.p1_alpha_mode = 1; } else goto OUT; p_reg->mem_size[sel].bits.width = rect.w - 1; p_reg->mem_size[sel].bits.height = rect.h - 1; p_reg->mem_coor[sel].bits.xcoor = rect.x <= 0 ? 0 : rect.x - 1; p_reg->mem_coor[sel].bits.ycoor = rect.y <= 0 ? 0 : rect.y - 1; ret = 0; p_bld->set_block_dirty(p_bld, 0, 1); OUT: return ret; } /** * set colorkey para. */ __s32 bld_ck_para_set(struct blender_submodule *p_bld, g2d_ck *para, __u32 flag) { __u32 tmp = 0x0; __s32 ret = -1; struct g2d_mixer_bld_reg *p_reg = NULL; p_reg = p_bld->get_reg(p_bld); if (!p_reg || !para) goto OUT; if (para->match_rule) tmp = 0x7; p_reg->color_key_cfg.dwval = tmp; p_reg->color_key_max.dwval = para->max_color & 0x00ffffff; p_reg->color_key_min.dwval = para->min_color & 0x00ffffff; if (flag & G2D_CK_SRC) { p_reg->color_key.bits.key0_en = 1; p_reg->color_key.bits.key0_match_dir = 0; } else if (flag & G2D_CK_DST) { p_reg->color_key.bits.key0_en = 1; p_reg->color_key.bits.key0_match_dir = 1; } p_bld->set_block_dirty(p_bld, 0, 1); OUT: return ret; } /** * background color set */ __s32 bld_bk_set(struct blender_submodule *p_bld, __u32 color) { __s32 ret = -1; struct g2d_mixer_bld_reg *p_reg = NULL; p_reg = p_bld->get_reg(p_bld); if (!p_reg) goto OUT; p_reg->bld_backgroud_color = color & 0xffffffff; ret = 0; p_bld->set_block_dirty(p_bld, 0, 1); OUT: return ret; } __s32 bld_out_setting(struct blender_submodule *p_bld, g2d_image_enh *p_image) { __s32 ret = -1; struct g2d_mixer_bld_reg *p_reg = NULL; p_reg = p_bld->get_reg(p_bld); if (!p_reg) goto OUT; if (p_image->bpremul) p_reg->out_color.bits.premul_en = 1; else p_reg->out_color.bits.premul_en = 0; p_reg->out_size.bits.width = p_image->clip_rect.w == 0 ? 0 : p_image->clip_rect.w - 1; p_reg->out_size.bits.height = p_image->clip_rect.h == 0 ? 0 : p_image->clip_rect.h - 1; p_bld->set_block_dirty(p_bld, 0, 1); ret = 0; OUT: return ret; } __s32 bld_set_rop_ctrl(struct blender_submodule *p_bld, __u32 value) { __s32 ret = -1; struct g2d_mixer_bld_reg *p_reg = NULL; p_reg = p_bld->get_reg(p_bld); if (!p_reg) goto OUT; p_reg->rop_ctrl.dwval = value; p_reg->ch3_index0.dwval = 0x41000; ret = 0; p_bld->set_block_dirty(p_bld, 0, 1); OUT: return ret; } /** * set the bld color space based on the format * if the format is UI, then set the bld in RGB color space * if the format is Video, then set the bld in YUV color space */ __s32 bld_cs_set(struct blender_submodule *p_bld, __u32 format) { __s32 ret = -1; struct g2d_mixer_bld_reg *p_reg = NULL; p_reg = p_bld->get_reg(p_bld); if (!p_reg) goto OUT; if (format <= G2D_FORMAT_BGRA1010102) { p_reg->out_color.bits.alpha_mode = 0; } else if (format <= G2D_FORMAT_YUV411_PLANAR) { p_reg->out_color.bits.alpha_mode = 1; } else goto OUT; p_bld->set_block_dirty(p_bld, 0, 1); ret = 0; OUT: return ret; } /** * @csc_no: CSC ID, G2D support three CSC, * -1 will return to indicate inappropriate CSC number. * @csc_sel: CSC format, G2D support the ITU-R 601. ITU-R 709. standard trans- * form between RGB and YUV colorspace. */ __s32 bld_csc_reg_set(struct blender_submodule *p_bld, __u32 csc_no, g2d_csc_sel csc_sel) { void *csc_base_addr; __s32 ret = -1; struct g2d_mixer_bld_reg *p_reg = NULL; p_reg = p_bld->get_reg(p_bld); if (!p_reg) goto OUT; p_reg->bld_fill_color[0] = 0x00108080; p_reg->bld_fill_color[1] = 0x00108080; switch (csc_no) { case 0: csc_base_addr = &p_reg->csc0_coeff0_reg0; p_reg->cs_ctrl.bits.cs0_en = 1; break; case 1: csc_base_addr = &p_reg->csc1_coeff0_reg0; p_reg->cs_ctrl.bits.cs1_en = 1; break; case 2: csc_base_addr = &p_reg->csc2_coeff0_reg0; p_reg->cs_ctrl.bits.cs2_en = 1; break; default: goto OUT; } switch (csc_sel) { case G2D_RGB2YUV_709: memcpy(csc_base_addr, rgb2Ycbcr_709, 12 * sizeof(unsigned int)); break; case G2D_YUV2RGB_709: memcpy(csc_base_addr, Ycbcr2rgb_709, 12 * sizeof(unsigned int)); break; case G2D_RGB2YUV_601: memcpy(csc_base_addr, rgb2Ycbcr_601, 12 * sizeof(unsigned int)); break; case G2D_YUV2RGB_601: memcpy(csc_base_addr, Ycbcr2rgb_601, 12 * sizeof(unsigned int)); break; default: G2D_ERR_MSG("No implement standard:%d!\n", csc_sel); goto OUT; } p_bld->set_block_dirty(p_bld, 0, 1); ret = 0; OUT: return ret; } __s32 bld_porter_duff(struct blender_submodule *p_bld, __u32 cmd) { struct g2d_mixer_bld_reg *p_reg = NULL; __s32 ret = -1; p_reg = p_bld->get_reg(p_bld); if (!p_reg) goto OUT; switch (cmd) { case G2D_BLD_CLEAR: p_reg->bld_ctrl.dwval = 0x00000000; break; case G2D_BLD_COPY: p_reg->bld_ctrl.dwval = 0x00010001; break; case G2D_BLD_DST: p_reg->bld_ctrl.dwval = 0x01000100; break; case G2D_BLD_SRCOVER: p_reg->bld_ctrl.dwval = 0x03010301; break; case G2D_BLD_DSTOVER: p_reg->bld_ctrl.dwval = 0x01030103; break; case G2D_BLD_SRCIN: p_reg->bld_ctrl.dwval = 0x00020002; break; case G2D_BLD_DSTIN: p_reg->bld_ctrl.dwval = 0x02000200; break; case G2D_BLD_SRCOUT: p_reg->bld_ctrl.dwval = 0x00030003; break; case G2D_BLD_DSTOUT: p_reg->bld_ctrl.dwval = 0x03000300; break; case G2D_BLD_SRCATOP: p_reg->bld_ctrl.dwval = 0x03020302; break; case G2D_BLD_DSTATOP: p_reg->bld_ctrl.dwval = 0x02030203; break; case G2D_BLD_XOR: p_reg->bld_ctrl.dwval = 0x03030303; break; default: p_reg->bld_ctrl.dwval = 0x03010301; } p_bld->set_block_dirty(p_bld, 0, 1); ret = 0; OUT: return ret; } int bld_rcq_setup(struct blender_submodule *p_bld, u8 *base, struct g2d_rcq_mem_info *p_rcq_info) { u8 *reg_base = base + G2D_BLD; int ret = -1; if (!p_bld) { G2D_ERR_MSG("Null pointer!\n"); goto OUT; } p_bld->reg_info->size = sizeof(struct g2d_mixer_bld_reg); p_bld->reg_info->vir_addr = (u8 *)g2d_top_reg_memory_alloc( p_bld->reg_info->size, (void *)&(p_bld->reg_info->phy_addr), p_rcq_info); if (!p_bld->reg_info->vir_addr) { G2D_ERR_MSG("Malloc blender reg rcq memory fail!\n"); goto OUT; } p_bld->reg_blks->vir_addr = p_bld->reg_info->vir_addr; p_bld->reg_blks->phy_addr = p_bld->reg_info->phy_addr; p_bld->reg_blks->size = p_bld->reg_info->size; p_bld->reg_blks->reg_addr = reg_base; ret = 0; OUT: return ret; } /** * ROP2 cmd register set * Index0 is selected * dst mapping ch0' * src mapping ch1' */ __s32 bld_rop2_set(struct blender_submodule *p_bld, __u32 rop_cmd) { __s32 ret = -1; struct g2d_mixer_bld_reg *p_reg = p_bld->get_reg(p_bld); p_reg = p_bld->get_reg(p_bld); if (!p_reg) goto OUT; if (rop_cmd == G2D_BLT_BLACKNESS) { /* blackness */ /* tmpue = 0x1<<18; */ p_reg->ch3_index0.dwval = 0x40000; } else if (rop_cmd == G2D_BLT_NOTMERGEPEN) { /* ~(dst | src) */ /* tmpue = (0x1<<6) | (0x1<<10) | (0x2<<11) | (0x1<<18); */ p_reg->ch3_index0.dwval = 0x41440; } else if (rop_cmd == G2D_BLT_MASKNOTPEN) { /* ~src&dst */ /* tmpue = (0x1<<4) | (0x0<<10) | (0x2<<11) | (0x1<<18); */ p_reg->ch3_index0.dwval = 0x41010; } else if (rop_cmd == G2D_BLT_NOTCOPYPEN) { /* ~src */ /* tmpue = (0x1<<4) | (0x2<<6) | (0x2<<11) | * (0x1<<18) | (0x1<<17); */ p_reg->ch3_index0.dwval = 0x61090; } else if (rop_cmd == G2D_BLT_MASKPENNOT) { /* src&~dst */ /* tmpue = (0x1<<3) | (0x0<<10) | (0x2<<11) | (0x1<<18); */ p_reg->ch3_index0.dwval = 0x41008; } else if (rop_cmd == G2D_BLT_NOT) { /* ~dst */ /* tmpue = (0x1<<3) | (0x2<<6) | (0x2<<11) | * (0x1<<18) | (0x1<<16); */ p_reg->ch3_index0.dwval = 0x51088; } else if (rop_cmd == G2D_BLT_XORPEN) { /* src xor dst */ /* tmpue = (0x2<<6) | (0x2<<11) | (0x1<<18); */ p_reg->ch3_index0.dwval = 0x41080; } else if (rop_cmd == G2D_BLT_NOTMASKPEN) { /* ~(src & dst) */ /* tmpue = (0x0<<6) | (0x1<<10) | (0x2<<11) | (0x1<<18); */ p_reg->ch3_index0.dwval = 0x41400; } else if (rop_cmd == G2D_BLT_MASKPEN) { /* src&dst */ /* tmpue = (0x0<<6) | (0x2<<11) | (0x1<<18); */ p_reg->ch3_index0.dwval = 0x41000; } else if (rop_cmd == G2D_BLT_NOTXORPEN) { /* ~(src xor dst) */ /* tmpue = (0x2<<6) | (0x1<<10) | (0x2<<11) | (0x1<<18); */ p_reg->ch3_index0.dwval = 0x41480; } else if (rop_cmd == G2D_BLT_NOP) { /* dst */ /* tmpue = (0x2<<6) | (0x2<<11) | (0x1<<18) | (0x1<<16); */ p_reg->ch3_index0.dwval = 0x51080; } else if (rop_cmd == G2D_BLT_MERGENOTPEN) { /* ~dst or src */ /* tmpue = (0x1<<3)| (0x1<<6) | (0x2<<11) | (0x1<<18) */ /* write_wvalue(ROP_INDEX0, 0x40A20); */ p_reg->ch3_index0.dwval = 0x41048; } else if (rop_cmd == G2D_BLT_COPYPEN) { /* src */ /* tmpue = (0x2<<6) | (0x2<<11) | (0x1<<18) | (0x1<<17); */ p_reg->ch3_index0.dwval = 0x61080; } else if (rop_cmd == G2D_BLT_MERGEPENNOT) { /* src or ~dst */ /* tmpue = (0x1<<3)| (0x1<<6) | (0x2<<11) | (0x1<<18) */ p_reg->ch3_index0.dwval = 0x41048; } else if (rop_cmd == G2D_BLT_MERGEPEN) { /* src or dst */ /* tmpue = (0x1<<6) | (0x1<<18) | (0x2<<11); */ p_reg->ch3_index0.dwval = 0x41040; } else if (rop_cmd == G2D_BLT_WHITENESS) { /* whiteness */ /* tmpue = (0x1<<18) | (0x1<<15); */ p_reg->ch3_index0.dwval = 0x48000; } else goto OUT; p_reg->ch3_index0.bits.index0node0 = 2; /*TODO:different with source*/ p_bld->set_block_dirty(p_bld, 0, 1); ret = 0; OUT: return ret; } /** * ROP3 cmd register set * dst mapping ch0' * src mapping ch1' * ptn mapping ch2' * -1 return meaning that the operate is not supported by now */ __s32 bld_rop3_set(struct blender_submodule *p_bld, __u32 sel, __u32 rop3_cmd) { __s32 ret = -1; union g2d_mixer_rop_ch3_index0 *p_addr = NULL; struct g2d_mixer_bld_reg *p_reg = p_bld->get_reg(p_bld); p_reg = p_bld->get_reg(p_bld); if (!p_reg) goto OUT; if (sel == 0) p_addr = &p_reg->ch3_index0; else if (sel == 1) p_addr = &p_reg->ch3_index1; else goto OUT; if (rop3_cmd == G2D_ROP3_BLACKNESS) { /* blackness */ /* 0x1<<18; */ p_addr->dwval = 0x40000; } else if (rop3_cmd == G2D_ROP3_NOTSRCERASE) { /* (~src) AND (~dst) */ /* (0x1<<3) | (0x1<<4) | (0x1<<18) | (0x2<<11); */ p_addr->dwval = 0x41018; } else if (rop3_cmd == G2D_ROP3_NOTSRCCOPY) { /* ~src */ /* (0x1<<4) | (0x2<<6) | (0x2<<11) | (0x1<<18) | (0x1<<16); */ p_addr->dwval = 0x51090; } else if (rop3_cmd == G2D_ROP3_SRCERASE) { /* src AND ~dst */ /* (0x1<<3) | (0x0<<6) | (0x2<<11) | (0x1<<18); */ p_addr->dwval = 0x41008; } else if (rop3_cmd == G2D_ROP3_DSTINVERT) { /* ~dst */ /* (0x1<<3) | (0x2<<6) | (0x2<<11) | (0x1<<18) | (0x1<<17); */ p_addr->dwval = 0x61088; } else if (rop3_cmd == G2D_ROP3_PATINVERT) { /* ptn XOR dst */ /* (0x2<<6) | (0x2<<11) | (0x1<<17) */ p_addr->dwval = 0x21080; } else if (rop3_cmd == G2D_ROP3_SRCINVERT) { /* src XOR dst */ /* (0x2<<6) | (0x2<<11) | (0x1<<18); */ p_addr->dwval = 0x41080; } else if (rop3_cmd == G2D_ROP3_SRCAND) { /* src AND dst */ /* (0x0<<6) | (0x2<<11) | (0x1<<18); */ p_addr->dwval = 0x41000; } else if (rop3_cmd == G2D_ROP3_MERGEPAINT) { /* ~src OR dst */ /* (0x1<<4) | (0x1<<6) | (0x2<<11) | (0x1<<18); */ p_addr->dwval = 0x41050; } else if (rop3_cmd == G2D_ROP3_MERGECOPY) { /* src AND pattern */ /* (0x2<<6) | (0x1<<16) */ p_addr->dwval = 0x10080; } else if (rop3_cmd == G2D_ROP3_SRCCOPY) { /* src */ /* (0x2<<6) | (0x2<<11) | (0x1<<18) | (0x1<<16); */ p_addr->dwval = 0x51080; } else if (rop3_cmd == G2D_ROP3_SRCPAINT) { /* src OR dst */ /* (0x1<<6) | (0x2<<11) | (0x1<<18); */ p_addr->dwval = 0x41040; } else if (rop3_cmd == G2D_ROP3_PATCOPY) { /* ptn */ /* (0x1<<16) | (0x1<<17) | (0x2)<<11 */ p_addr->dwval = 0x31000; } else if (rop3_cmd == G2D_ROP3_PATPAINT) { /* DPSnoo */ /* (0x1<<3) | (0x1<<6) | (0x1<<11) */ p_addr->dwval = 0x848; } else if (rop3_cmd == G2D_ROP3_WHITENESS) { /* whiteness */ p_addr->dwval = 0x48000; } else goto OUT; p_bld->set_block_dirty(p_bld, 0, 1); ret = 0; OUT: return ret; } static __u32 bld_get_reg_block_num(struct blender_submodule *p_bld) { if (p_bld) return p_bld->reg_blk_num; return 0; } static __s32 bld_get_reg_block(struct blender_submodule *p_bld, struct g2d_reg_block **blks) { __s32 i = 0, ret = -1; if (p_bld) { for (i = 0; i < p_bld->reg_blk_num; ++i) blks[i] = p_bld->reg_blks + i; } return ret; } static struct g2d_mixer_bld_reg *bld_get_reg(struct blender_submodule *p_bld) { #if G2D_MIXER_RCQ_USED == 1 return (struct g2d_mixer_bld_reg *)(p_bld->reg_blks ->vir_addr); #else return (struct g2d_mixer_bld_reg *)(p_bld->reg_blks ->reg_addr); #endif return NULL; } static void bld_set_block_dirty(struct blender_submodule *p_bld, __u32 blk_id, __u32 dirty) { #if G2D_MIXER_RCQ_USED == 1 if (p_bld && p_bld->reg_blks->rcq_hd) p_bld->reg_blks->rcq_hd->dirty.bits.dirty = dirty; else G2D_ERR_MSG("Null pointer!\n"); #else if (p_bld) p_bld->reg_blks->dirty = dirty; else G2D_ERR_MSG("Null pointer!\n"); #endif } static __u32 bld_get_rcq_mem_size(struct blender_submodule *p_bld) { return G2D_RCQ_BYTE_ALIGN(sizeof(struct g2d_mixer_bld_reg)); } static __s32 bld_destory(struct blender_submodule *p_bld) { __s32 ret = -1; if (p_bld) { free(p_bld->reg_blks); p_bld->reg_blks = NULL; free(p_bld->reg_info); p_bld->reg_info = NULL; free(p_bld); ret = 0; } return ret; } struct blender_submodule * g2d_bld_submodule_setup(struct g2d_mixer_frame *p_frame) { struct blender_submodule *p_bld = NULL; p_bld = hal_malloc(sizeof(struct blender_submodule)); if (!p_bld) { G2D_ERR_MSG("malloc wb submodule fail!\n"); return NULL; } memset(p_bld, 0, sizeof(struct blender_submodule)); p_bld->rcq_setup = bld_rcq_setup; p_bld->reg_blk_num = 1; p_bld->get_reg_block_num = bld_get_reg_block_num; p_bld->get_reg_block = bld_get_reg_block; p_bld->get_reg = bld_get_reg; p_bld->set_block_dirty = bld_set_block_dirty; p_bld->get_rcq_mem_size = bld_get_rcq_mem_size; p_bld->destory = bld_destory; p_bld->reg_blks = hal_malloc(sizeof(struct g2d_reg_block) * p_bld->reg_blk_num); p_bld->reg_info = hal_malloc(sizeof(struct g2d_reg_mem_info)); if (!p_bld->reg_blks || !p_bld->reg_info) { G2D_ERR_MSG("malloc wb reg info fail!\n"); goto FREE_WB; } memset(p_bld->reg_blks, 0, sizeof(struct g2d_reg_block) * p_bld->reg_blk_num); memset(p_bld->reg_info, 0, sizeof(struct g2d_reg_mem_info)); return p_bld; FREE_WB: free(p_bld->reg_blks); free(p_bld->reg_info); free(p_bld); return NULL; }
6759392c861dccad21fd1cb38da630d41e39c94d
f8cc1dd4b1378490386def2e0571561fab10b275
/src/include/skalibs/strerr2.h
d41e15d475071447a64d6dbc155ce381731b63c0
[ "ISC" ]
permissive
skarnet/skalibs
b1eb2a0e38663cbfa918ee0a7916f56227bd7c2d
1f2d5f95684e93f8523e369ef1fed7a75c444082
refs/heads/master
2023-08-23T07:33:20.996016
2023-08-08T09:39:15
2023-08-08T09:39:15
31,461,366
104
32
ISC
2021-04-11T10:10:54
2015-02-28T12:01:41
C
UTF-8
C
false
false
189
h
strerr2.h
/* ISC license. */ #ifndef SKALIBS_STRERR2_H #define SKALIBS_STRERR2_H #include <skalibs/strerr.h> #warning strerr2.h is now deprecated, use #include <skalibs/strerr.h> instead. #endif
c56a49beca9bd9654fd5f0d67043bb5cf6530c9c
68e115d504decf90cf8adaf1c373a220c059d8d7
/Library/QcomPlatformClockInitLib/msm8994-clock.c
0b561177d287c643c037b1966bc9e1167c1a3399
[ "GPL-1.0-or-later", "GPL-2.0-only", "BSD-2-Clause" ]
permissive
WOA-Project/Lumia950XLPkg
24fcad187d71488270b853d08fcdff542bbac5a2
0e7e24adb2ac80672ade1e56f9b538d99941328f
refs/heads/master
2023-08-11T09:20:00.600571
2022-09-14T09:09:51
2022-09-14T09:09:51
132,070,715
264
64
BSD-2-Clause
2022-12-18T20:27:21
2018-05-04T01:44:48
C
UTF-8
C
false
false
32,398
c
msm8994-clock.c
/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 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. * * Neither the name of The Linux Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS * 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 <Library/LKEnvLib.h> #include <Chipset/clock.h> // Must come in order #include <Chipset/clock_pll.h> // Must come in order #include <Chipset/clock_lib2.h> #include <Platform/clock.h> #include <Platform/iomap.h> /* Mux source select values */ #define cxo_source_val 0 #define gpll0_source_val 1 #define gpll4_source_val 5 #define cxo_mm_source_val 0 #define mmpll0_mm_source_val 1 #define mmpll1_mm_source_val 2 #define mmpll3_mm_source_val 3 #define gpll0_mm_source_val 5 #define edppll_270_mm_source_val 4 #define edppll_350_mm_source_val 4 #define hdmipll_mm_source_val 3 #define pcie_pipe_source_val 2 struct clk_freq_tbl rcg_dummy_freq = F_END; /* Clock Operations */ static struct clk_ops clk_ops_rst = { .reset = clock_lib2_reset_clk_reset, }; static struct clk_ops clk_ops_branch = { .enable = clock_lib2_branch_clk_enable, .disable = clock_lib2_branch_clk_disable, .set_rate = clock_lib2_branch_set_rate, .reset = clock_lib2_branch_clk_reset, }; static struct clk_ops clk_ops_rcg_mnd = { .enable = clock_lib2_rcg_enable, .set_rate = clock_lib2_rcg_set_rate, }; static struct clk_ops clk_ops_rcg = { .enable = clock_lib2_rcg_enable, .set_rate = clock_lib2_rcg_set_rate, }; static struct clk_ops clk_ops_cxo = { .enable = cxo_clk_enable, .disable = cxo_clk_disable, }; static struct clk_ops clk_ops_pll_vote = { .enable = pll_vote_clk_enable, .disable = pll_vote_clk_disable, .auto_off = pll_vote_clk_disable, .is_enabled = pll_vote_clk_is_enabled, }; static struct clk_ops clk_ops_vote = { .enable = clock_lib2_vote_clk_enable, .disable = clock_lib2_vote_clk_disable, }; /* Clock Sources */ static struct fixed_clk cxo_clk_src = { .c = { .rate = 19200000, .dbg_name = "cxo_clk_src", .ops = &clk_ops_cxo, }, }; static struct pll_vote_clk gpll0_clk_src = { .en_reg = (void *)APCS_GPLL_ENA_VOTE, .en_mask = BIT(0), .status_reg = (void *)GPLL0_MODE, .status_mask = BIT(30), .parent = &cxo_clk_src.c, .c = { .rate = 600000000, .dbg_name = "gpll0_clk_src", .ops = &clk_ops_pll_vote, }, }; static struct pll_vote_clk gpll4_clk_src = { .en_reg = (void *)APCS_GPLL_ENA_VOTE, .en_mask = BIT(4), .status_reg = (void *)GPLL4_MODE, .status_mask = BIT(30), .parent = &cxo_clk_src.c, .c = { .rate = 1600000000, .dbg_name = "gpll4_clk_src", .ops = &clk_ops_pll_vote, }, }; /* UART Clocks */ static struct clk_freq_tbl ftbl_gcc_blsp1_2_uart1_6_apps_clk[] = { F(3686400, gpll0, 1, 96, 15625), F(7372800, gpll0, 1, 192, 15625), F(14745600, gpll0, 1, 384, 15625), F(16000000, gpll0, 5, 2, 15), F(19200000, cxo, 1, 0, 0), F(24000000, gpll0, 5, 1, 5), F(32000000, gpll0, 1, 4, 75), F(40000000, gpll0, 15, 0, 0), F(46400000, gpll0, 1, 29, 375), F(48000000, gpll0, 12.5, 0, 0), F(51200000, gpll0, 1, 32, 375), F(56000000, gpll0, 1, 7, 75), F(58982400, gpll0, 1, 1536, 15625), F(60000000, gpll0, 10, 0, 0), F(63160000, gpll0, 9.5, 0, 0), F_END}; static struct rcg_clk blsp1_uart2_apps_clk_src = { .cmd_reg = (uint32_t *)BLSP1_UART2_APPS_CMD_RCGR, .cfg_reg = (uint32_t *)BLSP1_UART2_APPS_CFG_RCGR, .m_reg = (uint32_t *)BLSP1_UART2_APPS_M, .n_reg = (uint32_t *)BLSP1_UART2_APPS_N, .d_reg = (uint32_t *)BLSP1_UART2_APPS_D, .set_rate = clock_lib2_rcg_set_rate_mnd, .freq_tbl = ftbl_gcc_blsp1_2_uart1_6_apps_clk, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "blsp1_uart2_apps_clk", .ops = &clk_ops_rcg_mnd, }, }; static struct branch_clk gcc_blsp1_uart2_apps_clk = { .cbcr_reg = (uint32_t *)BLSP1_UART2_APPS_CBCR, .parent = &blsp1_uart2_apps_clk_src.c, .c = { .dbg_name = "gcc_blsp1_uart2_apps_clk", .ops = &clk_ops_branch, }, }; static struct vote_clk gcc_blsp1_ahb_clk = { .cbcr_reg = (uint32_t *)BLSP1_AHB_CBCR, .vote_reg = (uint32_t *)APCS_CLOCK_BRANCH_ENA_VOTE, .en_mask = BIT(17), .c = { .dbg_name = "gcc_blsp1_ahb_clk", .ops = &clk_ops_vote, }, }; static struct vote_clk gcc_blsp2_ahb_clk = { .cbcr_reg = (uint32_t *)BLSP2_AHB_CBCR, .vote_reg = (uint32_t *)APCS_CLOCK_BRANCH_ENA_VOTE, .en_mask = BIT(15), .c = { .dbg_name = "gcc_blsp2_ahb_clk", .ops = &clk_ops_vote, }, }; /* USB Clocks */ static struct clk_freq_tbl ftbl_gcc_usb_hs_system_clk[] = { F(75000000, gpll0, 8, 0, 0), F_END}; static struct rcg_clk usb_hs_system_clk_src = { .cmd_reg = (uint32_t *)USB_HS_SYSTEM_CMD_RCGR, .cfg_reg = (uint32_t *)USB_HS_SYSTEM_CFG_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_gcc_usb_hs_system_clk, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "usb_hs_system_clk", .ops = &clk_ops_rcg, }, }; static struct branch_clk gcc_usb_hs_system_clk = { .cbcr_reg = (uint32_t *)USB_HS_SYSTEM_CBCR, .parent = &usb_hs_system_clk_src.c, .c = { .dbg_name = "gcc_usb_hs_system_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk gcc_usb_hs_ahb_clk = { .cbcr_reg = (uint32_t *)USB_HS_AHB_CBCR, .has_sibling = 1, .c = { .dbg_name = "gcc_usb_hs_ahb_clk", .ops = &clk_ops_branch, }, }; /* SDCC Clocks */ static struct clk_freq_tbl ftbl_gcc_sdcc1_apps_clk[] = { F(144000, cxo, 16, 3, 25), F(400000, cxo, 12, 1, 4), F(20000000, gpll0, 15, 1, 2), F(25000000, gpll0, 12, 1, 2), F(50000000, gpll0, 12, 0, 0), F(96000000, gpll4, 6, 0, 0), F(192000000, gpll4, 2, 0, 0), F(384000000, gpll4, 1, 0, 0), F_END}; static struct clk_freq_tbl ftbl_gcc_sdcc2_apps_clk[] = { F(144000, cxo, 16, 3, 25), F(400000, cxo, 12, 1, 4), F(20000000, gpll0, 15, 1, 2), F(25000000, gpll0, 12, 1, 2), F(50000000, gpll0, 12, 0, 0), F(100000000, gpll0, 6, 0, 0), F(200000000, gpll0, 3, 0, 0), F_END}; static struct rcg_clk sdcc1_apps_clk_src = { .cmd_reg = (uint32_t *)SDCC1_CMD_RCGR, .cfg_reg = (uint32_t *)SDCC1_CFG_RCGR, .m_reg = (uint32_t *)SDCC1_M, .n_reg = (uint32_t *)SDCC1_N, .d_reg = (uint32_t *)SDCC1_D, .set_rate = clock_lib2_rcg_set_rate_mnd, .freq_tbl = ftbl_gcc_sdcc1_apps_clk, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "sdc1_clk", .ops = &clk_ops_rcg_mnd, }, }; static struct branch_clk gcc_sdcc1_apps_clk = { .cbcr_reg = (uint32_t *)SDCC1_APPS_CBCR, .parent = &sdcc1_apps_clk_src.c, .c = { .dbg_name = "gcc_sdcc1_apps_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk gcc_sdcc1_ahb_clk = { .cbcr_reg = (uint32_t *)SDCC1_AHB_CBCR, .has_sibling = 1, .c = { .dbg_name = "gcc_sdcc1_ahb_clk", .ops = &clk_ops_branch, }, }; static struct rcg_clk sdcc2_apps_clk_src = { .cmd_reg = (uint32_t *)SDCC2_CMD_RCGR, .cfg_reg = (uint32_t *)SDCC2_CFG_RCGR, .m_reg = (uint32_t *)SDCC2_M, .n_reg = (uint32_t *)SDCC2_N, .d_reg = (uint32_t *)SDCC2_D, .set_rate = clock_lib2_rcg_set_rate_mnd, .freq_tbl = ftbl_gcc_sdcc2_apps_clk, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "sdc2_clk", .ops = &clk_ops_rcg_mnd, }, }; static struct branch_clk gcc_sdcc2_apps_clk = { .cbcr_reg = (uint32_t *)SDCC2_APPS_CBCR, .parent = &sdcc2_apps_clk_src.c, .c = { .dbg_name = "gcc_sdcc2_apps_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk gcc_sdcc2_ahb_clk = { .cbcr_reg = (uint32_t *)SDCC2_AHB_CBCR, .has_sibling = 1, .c = { .dbg_name = "gcc_sdcc2_ahb_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk gcc_sys_noc_usb30_axi_clk = { .cbcr_reg = (uint32_t *)SYS_NOC_USB3_AXI_CBCR, .has_sibling = 1, .c = { .dbg_name = "sys_noc_usb30_axi_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk gcc_usb2b_phy_sleep_clk = { .cbcr_reg = (uint32_t *)USB2B_PHY_SLEEP_CBCR, .bcr_reg = (uint32_t *)USB2B_PHY_BCR, .has_sibling = 1, .c = { .dbg_name = "usb2b_phy_sleep_clk", .ops = &clk_ops_branch, }, }; static struct clk_freq_tbl ftbl_gcc_usb30_master_clk[] = { F(125000000, gpll0, 1, 5, 24), F_END}; static struct rcg_clk usb30_master_clk_src = { .cmd_reg = (uint32_t *)USB30_MASTER_CMD_RCGR, .cfg_reg = (uint32_t *)USB30_MASTER_CFG_RCGR, .m_reg = (uint32_t *)USB30_MASTER_M, .n_reg = (uint32_t *)USB30_MASTER_N, .d_reg = (uint32_t *)USB30_MASTER_D, .set_rate = clock_lib2_rcg_set_rate_mnd, .freq_tbl = ftbl_gcc_usb30_master_clk, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "usb30_master_clk_src", .ops = &clk_ops_rcg, }, }; static struct branch_clk gcc_usb30_master_clk = { .cbcr_reg = (uint32_t *)USB30_MASTER_CBCR, .bcr_reg = (uint32_t *)USB_30_BCR, .parent = &usb30_master_clk_src.c, .c = { .dbg_name = "usb30_master_clk", .ops = &clk_ops_branch, }, }; static struct clk_freq_tbl ftbl_gcc_usb30_mock_utmi_clk_src[] = { F(60000000, gpll0, 10, 0, 0), F_END}; static struct rcg_clk usb30_mock_utmi_clk_src = { .cmd_reg = (uint32_t *)USB30_MOCK_UTMI_CMD_RCGR, .cfg_reg = (uint32_t *)USB30_MOCK_UTMI_CFG_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_gcc_usb30_mock_utmi_clk_src, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "usb30_mock_utmi_clk_src", .ops = &clk_ops_rcg, }, }; static struct branch_clk gcc_usb30_mock_utmi_clk = { .cbcr_reg = (uint32_t *)USB30_MOCK_UTMI_CBCR, .has_sibling = 0, .parent = &usb30_mock_utmi_clk_src.c, .c = { .dbg_name = "usb30_mock_utmi_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk gcc_usb30_sleep_clk = { .cbcr_reg = (uint32_t *)USB30_SLEEP_CBCR, .has_sibling = 1, .c = { .dbg_name = "usb30_sleep_clk", .ops = &clk_ops_branch, }, }; static struct clk_freq_tbl ftbl_gcc_usb30_phy_aux_clk_src[] = { F(1200000, cxo, 16, 0, 0), F_END}; static struct rcg_clk usb30_phy_aux_clk_src = { .cmd_reg = (uint32_t *)USB30_PHY_AUX_CMD_RCGR, .cfg_reg = (uint32_t *)USB30_PHY_AUX_CFG_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_gcc_usb30_phy_aux_clk_src, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "usb30_phy_aux_clk_src", .ops = &clk_ops_rcg, }, }; static struct branch_clk gcc_usb30_phy_aux_clk = { .cbcr_reg = (uint32_t *)USB30_PHY_AUX_CBCR, .has_sibling = 0, .parent = &usb30_phy_aux_clk_src.c, .c = { .dbg_name = "usb30_phy_aux_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk gcc_usb30_pipe_clk = { .bcr_reg = (uint32_t *)USB30PHY_PHY_BCR, .cbcr_reg = (uint32_t *)USB30_PHY_PIPE_CBCR, .has_sibling = 1, .c = { .dbg_name = "usb30_pipe_clk", .ops = &clk_ops_branch, }, }; static struct reset_clk gcc_usb30_phy_reset = { .bcr_reg = (uint32_t)USB30_PHY_BCR, .c = { .dbg_name = "usb30_phy_reset", .ops = &clk_ops_rst, }, }; static struct branch_clk gcc_usb_phy_cfg_ahb2phy_clk = { .cbcr_reg = (uint32_t *)USB_PHY_CFG_AHB2PHY_CBCR, .has_sibling = 1, .c = { .dbg_name = "usb_phy_cfg_ahb2phy_clk", .ops = &clk_ops_branch, }, }; /* Display clocks */ static struct clk_freq_tbl ftbl_mdss_esc0_1_clk[] = { F_MM(19200000, cxo, 1, 0, 0), F_END}; static struct clk_freq_tbl ftbl_mdss_esc1_1_clk[] = { F_MM(19200000, cxo, 1, 0, 0), F_END}; static struct clk_freq_tbl ftbl_mmss_axi_clk[] = { F_MM(19200000, cxo, 1, 0, 0), F_MM(100000000, gpll0, 6, 0, 0), F_MM(300000000, gpll0, 2, 0, 0), F_END}; static struct clk_freq_tbl ftbl_mdp_clk[] = { F_MM(75000000, gpll0, 8, 0, 0), F_MM(240000000, gpll0, 2.5, 0, 0), F_MM(300000000, gpll0, 2, 0, 0), F_END}; static struct rcg_clk dsi_esc0_clk_src = { .cmd_reg = (uint32_t *)DSI_ESC0_CMD_RCGR, .cfg_reg = (uint32_t *)DSI_ESC0_CFG_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_mdss_esc0_1_clk, .c = { .dbg_name = "dsi_esc0_clk_src", .ops = &clk_ops_rcg, }, }; static struct rcg_clk dsi_esc1_clk_src = { .cmd_reg = (uint32_t *)DSI_ESC1_CMD_RCGR, .cfg_reg = (uint32_t *)DSI_ESC1_CFG_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_mdss_esc1_1_clk, .c = { .dbg_name = "dsi_esc1_clk_src", .ops = &clk_ops_rcg, }, }; static struct clk_freq_tbl ftbl_mdss_vsync_clk[] = { F_MM(19200000, cxo, 1, 0, 0), F_END}; static struct rcg_clk vsync_clk_src = { .cmd_reg = (uint32_t *)VSYNC_CMD_RCGR, .cfg_reg = (uint32_t *)VSYNC_CFG_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_mdss_vsync_clk, .c = { .dbg_name = "vsync_clk_src", .ops = &clk_ops_rcg, }, }; static struct rcg_clk mdp_axi_clk_src = { .cmd_reg = (uint32_t *)MDP_AXI_CMD_RCGR, .cfg_reg = (uint32_t *)MDP_AXI_CFG_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_mmss_axi_clk, .c = { .dbg_name = "mdp_axi_clk_src", .ops = &clk_ops_rcg, }, }; static struct branch_clk mdss_esc0_clk = { .cbcr_reg = (uint32_t *)DSI_ESC0_CBCR, .parent = &dsi_esc0_clk_src.c, .has_sibling = 0, .c = { .dbg_name = "mdss_esc0_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk mdss_esc1_clk = { .cbcr_reg = (uint32_t *)DSI_ESC1_CBCR, .parent = &dsi_esc1_clk_src.c, .has_sibling = 0, .c = { .dbg_name = "mdss_esc1_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk mdss_axi_clk = { .cbcr_reg = (uint32_t *)MDP_AXI_CBCR, .parent = &mdp_axi_clk_src.c, .has_sibling = 0, .c = { .dbg_name = "mdss_axi_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk mmss_mmssnoc_axi_clk = { .cbcr_reg = (uint32_t *)MMSS_MMSSNOC_AXI_CBCR, .parent = &mdp_axi_clk_src.c, .has_sibling = 0, .c = { .dbg_name = "mmss_mmssnoc_axi_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk mmss_s0_axi_clk = { .cbcr_reg = (uint32_t *)MMSS_S0_AXI_CBCR, .parent = &mdp_axi_clk_src.c, .has_sibling = 0, .c = { .dbg_name = "mmss_s0_axi_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk mdp_ahb_clk = { .cbcr_reg = (uint32_t *)MDP_AHB_CBCR, .has_sibling = 1, .c = { .dbg_name = "mdp_ahb_clk", .ops = &clk_ops_branch, }, }; static struct rcg_clk mdss_mdp_clk_src = { .cmd_reg = (uint32_t *)MDP_CMD_RCGR, .cfg_reg = (uint32_t *)MDP_CFG_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_mdp_clk, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "mdss_mdp_clk_src", .ops = &clk_ops_rcg, }, }; static struct branch_clk mdss_mdp_clk = { .cbcr_reg = (uint32_t *)MDP_CBCR, .parent = &mdss_mdp_clk_src.c, .has_sibling = 1, .c = { .dbg_name = "mdss_mdp_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk mdss_mdp_lut_clk = { .cbcr_reg = (uint32_t *)MDP_LUT_CBCR, .parent = &mdss_mdp_clk_src.c, .has_sibling = 1, .c = { .dbg_name = "mdss_mdp_lut_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk mdss_vsync_clk = { .cbcr_reg = (uint32_t *)MDSS_VSYNC_CBCR, .parent = &vsync_clk_src.c, .has_sibling = 0, .c = { .dbg_name = "mdss_vsync_clk", .ops = &clk_ops_branch, }, }; static struct clk_freq_tbl ftbl_mdss_edpaux_clk[] = { F_MM(19200000, cxo, 1, 0, 0), F_END}; static struct rcg_clk edpaux_clk_src = { .cmd_reg = (uint32_t *)EDPAUX_CMD_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_mdss_edpaux_clk, .c = { .dbg_name = "edpaux_clk_src", .ops = &clk_ops_rcg, }, }; static struct branch_clk mdss_edpaux_clk = { .cbcr_reg = (uint32_t *)MDSS_EDPAUX_CBCR, .parent = &edpaux_clk_src.c, .has_sibling = 0, .c = { .dbg_name = "mdss_edpaux_clk", .ops = &clk_ops_branch, }, }; static struct clk_freq_tbl ftbl_mdss_edplink_clk[] = { F_MDSS(162000000, edppll_270, 2, 0, 0), F_MDSS(270000000, edppll_270, 11, 0, 0), F_END}; static struct rcg_clk edplink_clk_src = { .cmd_reg = (uint32_t *)EDPLINK_CMD_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_mdss_edplink_clk, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "edplink_clk_src", .ops = &clk_ops_rcg, }, }; static struct clk_freq_tbl ftbl_mdss_edppixel_clk[] = { F_MDSS(138500000, edppll_350, 2, 0, 0), F_MDSS(350000000, edppll_350, 11, 0, 0), F_END}; static struct rcg_clk edppixel_clk_src = { .cmd_reg = (uint32_t *)EDPPIXEL_CMD_RCGR, .set_rate = clock_lib2_rcg_set_rate_mnd, .freq_tbl = ftbl_mdss_edppixel_clk, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "edppixel_clk_src", .ops = &clk_ops_rcg_mnd, }, }; static struct branch_clk mdss_edplink_clk = { .cbcr_reg = (uint32_t *)MDSS_EDPLINK_CBCR, .has_sibling = 0, .parent = &edplink_clk_src.c, .c = { .dbg_name = "mdss_edplink_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk mdss_edppixel_clk = { .cbcr_reg = (uint32_t *)MDSS_EDPPIXEL_CBCR, .has_sibling = 0, .parent = &edppixel_clk_src.c, .c = { .dbg_name = "mdss_edppixel_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk mmss_misc_ahb_clk = { .cbcr_reg = (uint32_t *)MMSS_MISC_AHB_CBCR, .has_sibling = 1, .c = { .dbg_name = "mmss_misc_ahb_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk mdss_hdmi_ahb_clk = { .cbcr_reg = (uint32_t *)MDSS_HDMI_AHB_CBCR, .has_sibling = 1, .c = { .dbg_name = "mdss_hdmi_ahb_clk", .ops = &clk_ops_branch, }, }; static struct clk_freq_tbl ftbl_mdss_hdmi_clk[] = {F_MM(19200000, cxo, 1, 0, 0), F_END}; static struct rcg_clk hdmi_clk_src = { .cmd_reg = (uint32_t *)HDMI_CMD_RCGR, .cfg_reg = (uint32_t *)HDMI_CFG_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_mdss_hdmi_clk, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "hdmi_clk_src", .ops = &clk_ops_rcg, }, }; static struct branch_clk mdss_hdmi_clk = { .cbcr_reg = (uint32_t *)MDSS_HDMI_CBCR, .has_sibling = 0, .parent = &hdmi_clk_src.c, .c = { .dbg_name = "mdss_hdmi_clk", .ops = &clk_ops_branch, }, }; static struct clk_freq_tbl ftbl_mdss_extpclk_clk[] = { F_MDSS(74250000, hdmipll, 1, 0, 0), F_MDSS(25200000, hdmipll, 1, 0, 0), F_MDSS(27000000, hdmipll, 1, 0, 0), F_MDSS(27030000, hdmipll, 1, 0, 0), F_MDSS(27070000, hdmipll, 1, 0, 0), F_MDSS(65000000, hdmipll, 1, 0, 0), F_MDSS(108000000, hdmipll, 1, 0, 0), F_MDSS(148500000, hdmipll, 1, 0, 0), F_MDSS(268500000, hdmipll, 1, 0, 0), F_MDSS(297000000, hdmipll, 1, 0, 0), F_END}; static struct rcg_clk extpclk_clk_src = { .cmd_reg = (uint32_t *)EXTPCLK_CMD_RCGR, .cfg_reg = (uint32_t *)EXTPCLK_CFG_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_mdss_extpclk_clk, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "extpclk_clk_src", .ops = &clk_ops_rcg, }, }; static struct branch_clk mdss_extpclk_clk = { .cbcr_reg = (uint32_t *)MDSS_EXTPCLK_CBCR, .has_sibling = 0, .parent = &extpclk_clk_src.c, .c = { .dbg_name = "mdss_extpclk_clk", .ops = &clk_ops_branch, }, }; /* BLSP2_QUP4 SPI clocks */ static struct clk_freq_tbl ftbl_blsp2_qup4_spi_apps_clk_src[] = { F(960000, cxo, 10, 1, 2), F(4800000, cxo, 4, 0, 0), F(9600000, cxo, 2, 0, 0), F(15000000, gpll0, 10, 1, 4), F(19200000, cxo, 1, 0, 0), F(24000000, gpll0, 12.5, 1, 2), F(25000000, gpll0, 12, 1, 2), F(42860000, gpll0, 14, 0, 0), F(48000000, gpll0, 12.5, 0, 0), F_END, }; static struct rcg_clk gcc_blsp2_qup4_spi_apps_clk_src = { .cmd_reg = (uint32_t *)BLSP2_QUP4_SPI_APPS_CMD_RCGR, .cfg_reg = (uint32_t *)BLSP2_QUP4_SPI_APPS_CFG_CBCR, .m_reg = (uint32_t *)BLSP2_QUP4_SPI_APPS_M, .n_reg = (uint32_t *)BLSP2_QUP4_SPI_APPS_N, .d_reg = (uint32_t *)BLSP2_QUP4_SPI_APPS_D, .set_rate = clock_lib2_rcg_set_rate_mnd, .freq_tbl = ftbl_blsp2_qup4_spi_apps_clk_src, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "gcc_blsp2_qup4_spi_apps_clk_src", .ops = &clk_ops_rcg_mnd, }, }; static struct branch_clk gcc_blsp2_qup4_spi_apps_clk = { .cbcr_reg = (uint32_t *)BLSP2_QUP4_SPI_APPS_CBCR, .parent = &gcc_blsp2_qup4_spi_apps_clk_src.c, .c = { .dbg_name = "gcc_blsp2_qup4_spi_apps_clk", .ops = &clk_ops_branch, }, }; /* BLSP1_QUP2 I2C clocks */ static struct clk_freq_tbl ftbl_blsp_i2c_apps_clk_src[] = { F(19200000, cxo, 1, 0, 0), F(50000000, gpll0, 16, 0, 0), F_END, }; static struct rcg_clk gcc_blsp1_qup1_i2c_apps_clk_src = { .cmd_reg = (uint32_t *)GCC_BLSP1_QUP1_CMD_RCGR, .cfg_reg = (uint32_t *)GCC_BLSP1_QUP1_CFG_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_blsp_i2c_apps_clk_src, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "gcc_blsp1_qup1_i2c_apps_clk_src", .ops = &clk_ops_rcg, }, }; static struct rcg_clk gcc_blsp1_qup2_i2c_apps_clk_src = { .cmd_reg = (uint32_t *)GCC_BLSP1_QUP2_CMD_RCGR, .cfg_reg = (uint32_t *)GCC_BLSP1_QUP2_CFG_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_blsp_i2c_apps_clk_src, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "gcc_blsp1_qup2_i2c_apps_clk_src", .ops = &clk_ops_rcg, }, }; static struct rcg_clk gcc_blsp1_qup6_i2c_apps_clk_src = { .cmd_reg = (uint32_t *)GCC_BLSP1_QUP6_CMD_RCGR, .cfg_reg = (uint32_t *)GCC_BLSP1_QUP6_CFG_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_blsp_i2c_apps_clk_src, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "gcc_blsp1_qup6_i2c_apps_clk_src", .ops = &clk_ops_rcg, }, }; static struct rcg_clk gcc_blsp2_qup1_i2c_apps_clk_src = { .cmd_reg = (uint32_t *)GCC_BLSP2_QUP1_CMD_RCGR, .cfg_reg = (uint32_t *)GCC_BLSP2_QUP1_CFG_RCGR, .set_rate = clock_lib2_rcg_set_rate_hid, .freq_tbl = ftbl_blsp_i2c_apps_clk_src, .current_freq = &rcg_dummy_freq, .c = { .dbg_name = "gcc_blsp2_qup1_i2c_apps_clk_src", .ops = &clk_ops_rcg, }, }; static struct branch_clk gcc_blsp1_qup1_i2c_apps_clk = { .cbcr_reg = (uint32_t *)BLSP1_QUP1_I2C_APPS_CBCR, .parent = &gcc_blsp1_qup1_i2c_apps_clk_src.c, .c = { .dbg_name = "gcc_blsp1_qup1_i2c_apps_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk gcc_blsp1_qup2_i2c_apps_clk = { .cbcr_reg = (uint32_t *)BLSP1_QUP2_I2C_APPS_CBCR, .parent = &gcc_blsp1_qup2_i2c_apps_clk_src.c, .c = { .dbg_name = "gcc_blsp1_qup2_i2c_apps_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk gcc_blsp1_qup6_i2c_apps_clk = { .cbcr_reg = (uint32_t *)BLSP1_QUP6_I2C_APPS_CBCR, .parent = &gcc_blsp1_qup6_i2c_apps_clk_src.c, .c = { .dbg_name = "gcc_blsp1_qup6_i2c_apps_clk", .ops = &clk_ops_branch, }, }; static struct branch_clk gcc_blsp2_qup1_i2c_apps_clk = { .cbcr_reg = (uint32_t *)BLSP2_QUP1_I2C_APPS_CBCR, .parent = &gcc_blsp2_qup1_i2c_apps_clk_src.c, .c = { .dbg_name = "gcc_blsp2_qup1_i2c_apps_clk", .ops = &clk_ops_branch, }, }; static struct clk_freq_tbl ftbl_pcie_0_aux_clk_src[] = { F(1011000, cxo, 1, 1, 19), F_END}; /* Clock lookup table */ static struct clk_lookup msm_8994_clocks[] = { CLK_LOOKUP("sdc1_iface_clk", gcc_sdcc1_ahb_clk.c), CLK_LOOKUP("sdc1_core_clk", gcc_sdcc1_apps_clk.c), CLK_LOOKUP("sdc2_iface_clk", gcc_sdcc2_ahb_clk.c), CLK_LOOKUP("sdc2_core_clk", gcc_sdcc2_apps_clk.c), CLK_LOOKUP("uart2_iface_clk", gcc_blsp1_ahb_clk.c), CLK_LOOKUP("uart2_core_clk", gcc_blsp1_uart2_apps_clk.c), CLK_LOOKUP("usb_iface_clk", gcc_usb_hs_ahb_clk.c), CLK_LOOKUP("usb_core_clk", gcc_usb_hs_system_clk.c), /* USB30 clocks */ CLK_LOOKUP("usb2b_phy_sleep_clk", gcc_usb2b_phy_sleep_clk.c), CLK_LOOKUP("usb30_master_clk", gcc_usb30_master_clk.c), CLK_LOOKUP("usb30_iface_clk", gcc_sys_noc_usb30_axi_clk.c), CLK_LOOKUP("usb30_mock_utmi_clk", gcc_usb30_mock_utmi_clk.c), CLK_LOOKUP("usb30_sleep_clk", gcc_usb30_sleep_clk.c), CLK_LOOKUP("usb30_phy_aux_clk", gcc_usb30_phy_aux_clk.c), CLK_LOOKUP("usb30_pipe_clk", gcc_usb30_pipe_clk.c), CLK_LOOKUP("usb30_phy_reset", gcc_usb30_phy_reset.c), CLK_LOOKUP("usb_phy_cfg_ahb2phy_clk", gcc_usb_phy_cfg_ahb2phy_clk.c), /* mdss clocks */ CLK_LOOKUP("mdp_ahb_clk", mdp_ahb_clk.c), CLK_LOOKUP("mdss_esc0_clk", mdss_esc0_clk.c), CLK_LOOKUP("mdss_esc1_clk", mdss_esc1_clk.c), CLK_LOOKUP("mdss_axi_clk", mdss_axi_clk.c), CLK_LOOKUP("mmss_mmssnoc_axi_clk", mmss_mmssnoc_axi_clk.c), CLK_LOOKUP("mmss_s0_axi_clk", mmss_s0_axi_clk.c), CLK_LOOKUP("mdss_vsync_clk", mdss_vsync_clk.c), CLK_LOOKUP("mdss_mdp_clk_src", mdss_mdp_clk_src.c), CLK_LOOKUP("mdss_mdp_clk", mdss_mdp_clk.c), CLK_LOOKUP("mdss_mdp_lut_clk", mdss_mdp_lut_clk.c), CLK_LOOKUP("mmss_misc_ahb_clk", mmss_misc_ahb_clk.c), CLK_LOOKUP("edp_pixel_clk", mdss_edppixel_clk.c), CLK_LOOKUP("edp_link_clk", mdss_edplink_clk.c), CLK_LOOKUP("edp_aux_clk", mdss_edpaux_clk.c), CLK_LOOKUP("hdmi_ahb_clk", mdss_hdmi_ahb_clk.c), CLK_LOOKUP("hdmi_core_clk", mdss_hdmi_clk.c), CLK_LOOKUP("hdmi_extp_clk", mdss_extpclk_clk.c), /* I2C QUP Clocks */ CLK_LOOKUP("qupF9923000_ahb_iface_clk", gcc_blsp1_ahb_clk.c), CLK_LOOKUP( "gcc_qupF9923000_i2c_apps_clk_src", gcc_blsp1_qup1_i2c_apps_clk_src.c), CLK_LOOKUP("gcc_qupF9923000_i2c_apps_clk", gcc_blsp1_qup1_i2c_apps_clk.c), CLK_LOOKUP("qupF9924000_ahb_iface_clk", gcc_blsp1_ahb_clk.c), CLK_LOOKUP( "gcc_qupF9924000_i2c_apps_clk_src", gcc_blsp1_qup2_i2c_apps_clk_src.c), CLK_LOOKUP("gcc_qupF9924000_i2c_apps_clk", gcc_blsp1_qup2_i2c_apps_clk.c), CLK_LOOKUP("qupF9928000_ahb_iface_clk", gcc_blsp1_ahb_clk.c), CLK_LOOKUP( "gcc_qupF9928000_i2c_apps_clk_src", gcc_blsp1_qup6_i2c_apps_clk_src.c), CLK_LOOKUP("gcc_qupF9928000_i2c_apps_clk", gcc_blsp1_qup6_i2c_apps_clk.c), CLK_LOOKUP("qupF9963000_ahb_iface_clk", gcc_blsp2_ahb_clk.c), CLK_LOOKUP( "gcc_qupF9963000_i2c_apps_clk_src", gcc_blsp2_qup1_i2c_apps_clk_src.c), CLK_LOOKUP("gcc_qupF9963000_i2c_apps_clk", gcc_blsp2_qup1_i2c_apps_clk.c), /* SMMU Clocks */ /* BLSP2 QUP4 SPI clocks */ CLK_LOOKUP( "gcc_blsp2_qup4_spi_apps_clk_src", gcc_blsp2_qup4_spi_apps_clk_src.c), CLK_LOOKUP("gcc_blsp2_qup4_spi_apps_clk", gcc_blsp2_qup4_spi_apps_clk.c), }; RETURN_STATUS EFIAPI LibQcomPlatformClockInit(struct clk_lookup **clist, unsigned *num) { *clist = msm_8994_clocks; *num = ARRAY_SIZE(msm_8994_clocks); return RETURN_SUCCESS; }
6d51295854d5d2aa527188007e76459a373fdb1b
fbe68d84e97262d6d26dd65c704a7b50af2b3943
/third_party/virtualbox/src/VBox/ExtPacks/VBoxDTrace/onnv/lib/libdtrace/common/dt_pcb.c
05a99dd2af1c8317784e0fb2b50f95ffbf769e64
[ "CDDL-1.0", "LicenseRef-scancode-unknown-license-reference", "GPL-2.0-only", "LicenseRef-scancode-warranty-disclaimer", "GPL-1.0-or-later", "LGPL-2.1-or-later", "GPL-2.0-or-later", "MPL-1.0", "LicenseRef-scancode-generic-exception", "Apache-2.0", "OpenSSL", "MIT" ]
permissive
thalium/icebox
c4e6573f2b4f0973b6c7bb0bf068fe9e795fdcfb
6f78952d58da52ea4f0e55b2ab297f28e80c1160
refs/heads/master
2022-08-14T00:19:36.984579
2022-02-22T13:10:31
2022-02-22T13:10:31
190,019,914
585
109
MIT
2022-01-13T20:58:15
2019-06-03T14:18:12
C++
UTF-8
C
false
false
5,819
c
dt_pcb.c
/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef VBOX #pragma ident "%Z%%M% %I% %E% SMI" #endif /* * DTrace Parsing Control Block * * A DTrace Parsing Control Block (PCB) contains all of the state that is used * by a single pass of the D compiler, other than the global variables used by * lex and yacc. The routines in this file are used to set up and tear down * PCBs, which are kept on a stack pointed to by the libdtrace global 'yypcb'. * The main engine of the compiler, dt_compile(), is located in dt_cc.c and is * responsible for calling these routines to begin and end a compilation pass. * * Sun's lex/yacc are not MT-safe or re-entrant, but we permit limited nested * use of dt_compile() once the entire parse tree has been constructed but has * not yet executed the "cooking" pass (see dt_cc.c for more information). The * PCB design also makes it easier to debug (since all global state is kept in * one place) and could permit us to make the D compiler MT-safe or re-entrant * in the future by adding locks to libdtrace or switching to Flex and Bison. */ #ifndef VBOX #include <strings.h> #include <stdlib.h> #include <assert.h> #endif #include <dt_impl.h> #include <dt_program.h> #include <dt_provider.h> #include <dt_pcb.h> /* * Initialize the specified PCB by zeroing it and filling in a few default * members, and then pushing it on to the top of the PCB stack and setting * yypcb to point to it. Increment the current handle's generation count. */ void dt_pcb_push(dtrace_hdl_t *dtp, dt_pcb_t *pcb) { /* * Since lex/yacc are not re-entrant and we don't implement state save, * assert that if another PCB is active, it is from the same handle and * has completed execution of yyparse(). If the first assertion fires, * the caller is calling libdtrace without proper MT locking. If the * second assertion fires, dt_compile() is being called recursively * from an illegal location in libdtrace, or a dt_pcb_pop() is missing. */ if (yypcb != NULL) { assert(yypcb->pcb_hdl == dtp); assert(yypcb->pcb_yystate == YYS_DONE); } bzero(pcb, sizeof (dt_pcb_t)); dt_scope_create(&pcb->pcb_dstack); dt_idstack_push(&pcb->pcb_globals, dtp->dt_globals); dt_irlist_create(&pcb->pcb_ir); pcb->pcb_hdl = dtp; pcb->pcb_prev = dtp->dt_pcb; dtp->dt_pcb = pcb; dtp->dt_gen++; #ifndef USING_FLEX /* In case flex starts work too early. Moved to dt_compile. */ yyinit(pcb); #endif } static int dt_pcb_pop_ident(dt_idhash_t *dhp, dt_ident_t *idp, void *arg) { dtrace_hdl_t *dtp = arg; if (idp->di_gen == dtp->dt_gen) dt_idhash_delete(dhp, idp); return (0); } /* * Pop the topmost PCB from the PCB stack and destroy any data structures that * are associated with it. If 'err' is non-zero, destroy any intermediate * state that is left behind as part of a compilation that has failed. */ void dt_pcb_pop(dtrace_hdl_t *dtp, int err) { dt_pcb_t *pcb = yypcb; uint_t i; assert(pcb != NULL); assert(pcb == dtp->dt_pcb); while (pcb->pcb_dstack.ds_next != NULL) (void) dt_scope_pop(); dt_scope_destroy(&pcb->pcb_dstack); dt_irlist_destroy(&pcb->pcb_ir); dt_node_link_free(&pcb->pcb_list); dt_node_link_free(&pcb->pcb_hold); if (err != 0) { dt_xlator_t *dxp, *nxp; dt_provider_t *pvp, *nvp; if (pcb->pcb_prog != NULL) dt_program_destroy(dtp, pcb->pcb_prog); if (pcb->pcb_stmt != NULL) dtrace_stmt_destroy(dtp, pcb->pcb_stmt); if (pcb->pcb_ecbdesc != NULL) dt_ecbdesc_release(dtp, pcb->pcb_ecbdesc); for (dxp = dt_list_next(&dtp->dt_xlators); dxp; dxp = nxp) { nxp = dt_list_next(dxp); if (dxp->dx_gen == dtp->dt_gen) dt_xlator_destroy(dtp, dxp); } for (pvp = dt_list_next(&dtp->dt_provlist); pvp; pvp = nvp) { nvp = dt_list_next(pvp); if (pvp->pv_gen == dtp->dt_gen) dt_provider_destroy(dtp, pvp); } (void) dt_idhash_iter(dtp->dt_aggs, dt_pcb_pop_ident, dtp); dt_idhash_update(dtp->dt_aggs); (void) dt_idhash_iter(dtp->dt_globals, dt_pcb_pop_ident, dtp); dt_idhash_update(dtp->dt_globals); (void) dt_idhash_iter(dtp->dt_tls, dt_pcb_pop_ident, dtp); dt_idhash_update(dtp->dt_tls); (void) ctf_discard(dtp->dt_cdefs->dm_ctfp); (void) ctf_discard(dtp->dt_ddefs->dm_ctfp); } if (pcb->pcb_pragmas != NULL) dt_idhash_destroy(pcb->pcb_pragmas); if (pcb->pcb_locals != NULL) dt_idhash_destroy(pcb->pcb_locals); if (pcb->pcb_idents != NULL) dt_idhash_destroy(pcb->pcb_idents); if (pcb->pcb_inttab != NULL) dt_inttab_destroy(pcb->pcb_inttab); if (pcb->pcb_strtab != NULL) dt_strtab_destroy(pcb->pcb_strtab); if (pcb->pcb_regs != NULL) dt_regset_destroy(pcb->pcb_regs); for (i = 0; i < pcb->pcb_asxreflen; i++) dt_free(dtp, pcb->pcb_asxrefs[i]); dt_free(dtp, pcb->pcb_asxrefs); dt_difo_free(dtp, pcb->pcb_difo); free(pcb->pcb_filetag); free(pcb->pcb_sflagv); dtp->dt_pcb = pcb->pcb_prev; bzero(pcb, sizeof (dt_pcb_t)); yyinit(dtp->dt_pcb); }
1196343da7841ba61fa224b7bd26f27200842684
7c857119fe1505b1d80d6e62969661c06dc1a2f4
/rEFIt_UEFI/Platform/sse3_patcher.h
137e11f3477a4a799fe84393b8dd483a7cc6f9e7
[ "BSD-2-Clause" ]
permissive
CloverHackyColor/CloverBootloader
7042ca7dd6b513d22be591a295e49071ae1482ee
2711170df4f60b2ae5aa20add3e00f35cf57b7e5
refs/heads/master
2023-08-30T22:14:34.590134
2023-08-27T19:14:02
2023-08-27T19:14:02
205,810,121
4,734
770
BSD-2-Clause
2023-09-03T12:41:33
2019-09-02T08:22:14
C
UTF-8
C
false
false
9,483
h
sse3_patcher.h
CONST UINT8 sse3_patcher[] = { 0x55, 0x48, 0x89, 0xe5, 0x48, 0x89, 0xf0, 0x48, 0x89, 0xfe, 0x48, 0x89, 0xc7, 0x48, 0x29, 0xf0, 0x48, 0x39, 0xd0, 0x72, 0x52, 0x48, 0x83, 0xfa, 0x50, 0x76, 0x1d, 0xeb, 0x4f, 0x0f, 0x1f, 0x00, 0x55, 0x48, 0x89, 0xe5, 0x49, 0x89, 0xfb, 0x48, 0x89, 0xf8, 0x48, 0x29, 0xf0, 0x48, 0x39, 0xd0, 0x72, 0x35, 0x48, 0x83, 0xfa, 0x50, 0x77, 0x34, 0x89, 0xd1, 0xc1, 0xe9, 0x02, 0x74, 0x10, 0x8b, 0x06, 0x48, 0x83, 0xc6, 0x04, 0x89, 0x07, 0x48, 0x83, 0xc7, 0x04, 0xff, 0xc9, 0x75, 0xf0, 0x83, 0xe2, 0x03, 0x74, 0x0e, 0x8a, 0x06, 0x48, 0xff, 0xc6, 0x88, 0x07, 0x48, 0xff, 0xc7, 0xff, 0xca, 0x75, 0xf2, 0x4c, 0x89, 0xd8, 0x5d, 0xc3, 0xe9, 0xad, 0x04, 0x00, 0x00, 0x48, 0x81, 0xfa, 0x00, 0xd0, 0x07, 0x00, 0x73, 0x77, 0x89, 0xf9, 0xf7, 0xd9, 0x83, 0xe1, 0x0f, 0x74, 0x04, 0x29, 0xca, 0xf3, 0xa4, 0x48, 0x89, 0xd1, 0x89, 0xf0, 0x83, 0xe2, 0x3f, 0x83, 0xe0, 0x0f, 0x48, 0x83, 0xe1, 0xc0, 0x4c, 0x8d, 0x05, 0x14, 0x00, 0x00, 0x00, 0x48, 0x01, 0xce, 0x48, 0x01, 0xcf, 0x41, 0x8b, 0x04, 0x80, 0x48, 0xf7, 0xd9, 0x4c, 0x01, 0xc0, 0xff, 0xe0, 0x66, 0x90, 0x66, 0x00, 0x00, 0x00, 0xad, 0x00, 0x00, 0x00, 0xed, 0x00, 0x00, 0x00, 0x2d, 0x01, 0x00, 0x00, 0x6d, 0x01, 0x00, 0x00, 0xad, 0x01, 0x00, 0x00, 0xed, 0x01, 0x00, 0x00, 0x2d, 0x02, 0x00, 0x00, 0x6d, 0x02, 0x00, 0x00, 0xad, 0x02, 0x00, 0x00, 0xed, 0x02, 0x00, 0x00, 0x2d, 0x03, 0x00, 0x00, 0x6d, 0x03, 0x00, 0x00, 0xad, 0x03, 0x00, 0x00, 0xed, 0x03, 0x00, 0x00, 0x2d, 0x04, 0x00, 0x00, 0x41, 0x53, 0x48, 0xb8, 0x00, 0x12, 0xe0, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xff, 0xd0, 0x58, 0x5d, 0xc3, 0x48, 0x01, 0xce, 0x48, 0x01, 0xcf, 0xf7, 0xd9, 0x09, 0xd1, 0xfc, 0xc1, 0xe9, 0x02, 0xf3, 0xa5, 0xe9, 0x3d, 0xff, 0xff, 0xff, 0x81, 0xf9, 0x0f, 0xc0, 0xff, 0xff, 0x7e, 0xe3, 0xeb, 0x04, 0x0f, 0x1f, 0x40, 0x00, 0x66, 0x0f, 0x6f, 0x04, 0x0e, 0x66, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0x66, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0x66, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0xdf, 0xfe, 0xff, 0xff, 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x0f, 0x6f, 0x04, 0x0e, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0x9f, 0xfe, 0xff, 0xff, 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x0f, 0x6f, 0x04, 0x0e, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0x5f, 0xfe, 0xff, 0xff, 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x0f, 0x6f, 0x04, 0x0e, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0x1f, 0xfe, 0xff, 0xff, 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x0f, 0x6f, 0x04, 0x0e, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0xdf, 0xfd, 0xff, 0xff, 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x0f, 0x6f, 0x04, 0x0e, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0x9f, 0xfd, 0xff, 0xff, 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x0f, 0x6f, 0x04, 0x0e, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0x5f, 0xfd, 0xff, 0xff, 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x0f, 0x6f, 0x04, 0x0e, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0x1f, 0xfd, 0xff, 0xff, 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x0f, 0x6f, 0x04, 0x0e, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0xdf, 0xfc, 0xff, 0xff, 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x0f, 0x6f, 0x04, 0x0e, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0x9f, 0xfc, 0xff, 0xff, 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x0f, 0x6f, 0x04, 0x0e, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0x5f, 0xfc, 0xff, 0xff, 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x0f, 0x6f, 0x04, 0x0e, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0x1f, 0xfc, 0xff, 0xff, 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x0f, 0x6f, 0x04, 0x0e, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0xdf, 0xfb, 0xff, 0xff, 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x0f, 0x6f, 0x04, 0x0e, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0x9f, 0xfb, 0xff, 0xff, 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x0f, 0x6f, 0x04, 0x0e, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0x5f, 0xfb, 0xff, 0xff, 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x0f, 0x6f, 0x04, 0x0e, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0x10, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0x20, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0x30, 0x66, 0x0f, 0x7f, 0x04, 0x0f, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0x10, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0x20, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0x30, 0x48, 0x83, 0xc1, 0x40, 0x75, 0xcc, 0xe9, 0x1f, 0xfb, 0xff, 0xff, 0x48, 0x01, 0xd6, 0x48, 0x01, 0xd7, 0x48, 0x83, 0xfa, 0x50, 0x77, 0x31, 0x89, 0xd1, 0xc1, 0xe9, 0x03, 0x74, 0x12, 0x48, 0x83, 0xee, 0x08, 0x48, 0x8b, 0x06, 0x48, 0x83, 0xef, 0x08, 0x48, 0x89, 0x07, 0xff, 0xc9, 0x75, 0xee, 0x83, 0xe2, 0x07, 0x74, 0x0e, 0x48, 0xff, 0xce, 0x8a, 0x06, 0x48, 0xff, 0xcf, 0x88, 0x07, 0xff, 0xca, 0x75, 0xf2, 0x4c, 0x89, 0xd8, 0x5d, 0xc3, 0x89, 0xf9, 0x83, 0xe1, 0x0f, 0x74, 0x11, 0x48, 0x29, 0xca, 0x48, 0xff, 0xce, 0x8a, 0x06, 0x48, 0xff, 0xcf, 0x88, 0x07, 0xff, 0xc9, 0x75, 0xf2, 0x48, 0x89, 0xd1, 0x83, 0xe2, 0x3f, 0x48, 0x83, 0xe1, 0xc0, 0x48, 0x29, 0xce, 0x48, 0x29, 0xcf, 0xf7, 0xc6, 0x0f, 0x00, 0x00, 0x00, 0x75, 0x3b, 0x66, 0x0f, 0x6f, 0x44, 0x0e, 0xf0, 0x66, 0x0f, 0x6f, 0x4c, 0x0e, 0xe0, 0x66, 0x0f, 0x6f, 0x54, 0x0e, 0xd0, 0x66, 0x0f, 0x6f, 0x5c, 0x0e, 0xc0, 0x66, 0x0f, 0x7f, 0x44, 0x0f, 0xf0, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0xe0, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0xd0, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0xc0, 0x48, 0x83, 0xe9, 0x40, 0x75, 0xca, 0xe9, 0x64, 0xff, 0xff, 0xff, 0xf3, 0x0f, 0x6f, 0x44, 0x0e, 0xf0, 0xf3, 0x0f, 0x6f, 0x4c, 0x0e, 0xe0, 0xf3, 0x0f, 0x6f, 0x54, 0x0e, 0xd0, 0xf3, 0x0f, 0x6f, 0x5c, 0x0e, 0xc0, 0x66, 0x0f, 0x7f, 0x44, 0x0f, 0xf0, 0x66, 0x0f, 0x7f, 0x4c, 0x0f, 0xe0, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0xd0, 0x66, 0x0f, 0x7f, 0x5c, 0x0f, 0xc0, 0x48, 0x83, 0xe9, 0x40, 0x75, 0xca, 0xe9, 0x29, 0xff, 0xff, 0xff };
8c97d44bc4faedb2f5adeec7c50758638ba3c758
eecd5e4c50d8b78a769bcc2675250576bed34066
/src/mat/impls/aij/mpi/crl/mcrl.c
eb0c2738cfa1db8173bd5b1d0446165217a48182
[ "BSD-2-Clause" ]
permissive
petsc/petsc
3b1a04fea71858e0292f9fd4d04ea11618c50969
9c5460f9064ca60dd71a234a1f6faf93e7a6b0c9
refs/heads/main
2023-08-17T20:51:16.507070
2023-08-17T16:08:06
2023-08-17T16:08:06
8,691,401
341
169
NOASSERTION
2023-03-29T11:02:58
2013-03-10T20:55:21
C
UTF-8
C
false
false
7,157
c
mcrl.c
/* Defines a matrix-vector product for the MATMPIAIJCRL matrix class. This class is derived from the MATMPIAIJ class and retains the compressed row storage (aka Yale sparse matrix format) but augments it with a column oriented storage that is more efficient for matrix vector products on Vector machines. CRL stands for constant row length (that is the same number of columns is kept (padded with zeros) for each row of the sparse matrix. See src/mat/impls/aij/seq/crl/crl.c for the sequential version */ #include <../src/mat/impls/aij/mpi/mpiaij.h> #include <../src/mat/impls/aij/seq/crl/crl.h> static PetscErrorCode MatDestroy_MPIAIJCRL(Mat A) { Mat_AIJCRL *aijcrl = (Mat_AIJCRL *)A->spptr; PetscFunctionBegin; if (aijcrl) { PetscCall(PetscFree2(aijcrl->acols, aijcrl->icols)); PetscCall(VecDestroy(&aijcrl->fwork)); PetscCall(VecDestroy(&aijcrl->xwork)); PetscCall(PetscFree(aijcrl->array)); } PetscCall(PetscFree(A->spptr)); PetscCall(PetscObjectChangeTypeName((PetscObject)A, MATMPIAIJ)); PetscCall(MatDestroy_MPIAIJ(A)); PetscFunctionReturn(PETSC_SUCCESS); } static PetscErrorCode MatMPIAIJCRL_create_aijcrl(Mat A) { Mat_MPIAIJ *a = (Mat_MPIAIJ *)(A)->data; Mat_SeqAIJ *Aij = (Mat_SeqAIJ *)(a->A->data), *Bij = (Mat_SeqAIJ *)(a->B->data); Mat_AIJCRL *aijcrl = (Mat_AIJCRL *)A->spptr; PetscInt m = A->rmap->n; /* Number of rows in the matrix. */ PetscInt nd = a->A->cmap->n; /* number of columns in diagonal portion */ PetscInt *aj = Aij->j, *bj = Bij->j; /* From the CSR representation; points to the beginning of each row. */ PetscInt i, j, rmax = 0, *icols, *ailen = Aij->ilen, *bilen = Bij->ilen; PetscScalar *aa = Aij->a, *ba = Bij->a, *acols, *array; PetscFunctionBegin; /* determine the row with the most columns */ for (i = 0; i < m; i++) rmax = PetscMax(rmax, ailen[i] + bilen[i]); aijcrl->nz = Aij->nz + Bij->nz; aijcrl->m = A->rmap->n; aijcrl->rmax = rmax; PetscCall(PetscFree2(aijcrl->acols, aijcrl->icols)); PetscCall(PetscMalloc2(rmax * m, &aijcrl->acols, rmax * m, &aijcrl->icols)); acols = aijcrl->acols; icols = aijcrl->icols; for (i = 0; i < m; i++) { for (j = 0; j < ailen[i]; j++) { acols[j * m + i] = *aa++; icols[j * m + i] = *aj++; } for (; j < ailen[i] + bilen[i]; j++) { acols[j * m + i] = *ba++; icols[j * m + i] = nd + *bj++; } for (; j < rmax; j++) { /* empty column entries */ acols[j * m + i] = 0.0; icols[j * m + i] = (j) ? icols[(j - 1) * m + i] : 0; /* handle case where row is EMPTY */ } } PetscCall(PetscInfo(A, "Percentage of 0's introduced for vectorized multiply %g\n", 1.0 - ((double)(aijcrl->nz)) / ((double)(rmax * m)))); PetscCall(PetscFree(aijcrl->array)); PetscCall(PetscMalloc1(a->B->cmap->n + nd, &array)); /* xwork array is actually B->n+nd long, but we define xwork this length so can copy into it */ PetscCall(VecDestroy(&aijcrl->xwork)); PetscCall(VecCreateMPIWithArray(PetscObjectComm((PetscObject)A), 1, nd, PETSC_DECIDE, array, &aijcrl->xwork)); PetscCall(VecDestroy(&aijcrl->fwork)); PetscCall(VecCreateSeqWithArray(PETSC_COMM_SELF, 1, a->B->cmap->n, array + nd, &aijcrl->fwork)); aijcrl->array = array; aijcrl->xscat = a->Mvctx; PetscFunctionReturn(PETSC_SUCCESS); } static PetscErrorCode MatAssemblyEnd_MPIAIJCRL(Mat A, MatAssemblyType mode) { Mat_MPIAIJ *a = (Mat_MPIAIJ *)A->data; Mat_SeqAIJ *Aij = (Mat_SeqAIJ *)(a->A->data), *Bij = (Mat_SeqAIJ *)(a->A->data); PetscFunctionBegin; Aij->inode.use = PETSC_FALSE; Bij->inode.use = PETSC_FALSE; PetscCall(MatAssemblyEnd_MPIAIJ(A, mode)); if (mode == MAT_FLUSH_ASSEMBLY) PetscFunctionReturn(PETSC_SUCCESS); /* Now calculate the permutation and grouping information. */ PetscCall(MatMPIAIJCRL_create_aijcrl(A)); PetscFunctionReturn(PETSC_SUCCESS); } extern PetscErrorCode MatMult_AIJCRL(Mat, Vec, Vec); extern PetscErrorCode MatDuplicate_AIJCRL(Mat, MatDuplicateOption, Mat *); /* MatConvert_MPIAIJ_MPIAIJCRL converts a MPIAIJ matrix into a * MPIAIJCRL matrix. This routine is called by the MatCreate_MPIAIJCRL() * routine, but can also be used to convert an assembled MPIAIJ matrix * into a MPIAIJCRL one. */ PETSC_INTERN PetscErrorCode MatConvert_MPIAIJ_MPIAIJCRL(Mat A, MatType type, MatReuse reuse, Mat *newmat) { Mat B = *newmat; Mat_AIJCRL *aijcrl; PetscFunctionBegin; if (reuse == MAT_INITIAL_MATRIX) PetscCall(MatDuplicate(A, MAT_COPY_VALUES, &B)); PetscCall(PetscNew(&aijcrl)); B->spptr = (void *)aijcrl; /* Set function pointers for methods that we inherit from AIJ but override. */ B->ops->duplicate = MatDuplicate_AIJCRL; B->ops->assemblyend = MatAssemblyEnd_MPIAIJCRL; B->ops->destroy = MatDestroy_MPIAIJCRL; B->ops->mult = MatMult_AIJCRL; /* If A has already been assembled, compute the permutation. */ if (A->assembled) PetscCall(MatMPIAIJCRL_create_aijcrl(B)); PetscCall(PetscObjectChangeTypeName((PetscObject)B, MATMPIAIJCRL)); *newmat = B; PetscFunctionReturn(PETSC_SUCCESS); } /*@C MatCreateMPIAIJCRL - Creates a sparse matrix of type `MATMPIAIJCRL`. Collective Input Parameters: + comm - MPI communicator, set to `PETSC_COMM_SELF` . m - number of rows . n - number of columns . nz - number of nonzeros per row (same for all rows), for the "diagonal" submatrix . nnz - array containing the number of nonzeros in the various rows (possibly different for each row) or `NULL`, for the "diagonal" submatrix . onz - number of nonzeros per row (same for all rows), for the "off-diagonal" submatrix - onnz - array containing the number of nonzeros in the various rows (possibly different for each row) or `NULL`, for the "off-diagonal" submatrix Output Parameter: . A - the matrix Level: intermediate Notes: This type inherits from `MATAIJ`, but stores some additional information that is used to allow better vectorization of the matrix-vector product. At the cost of increased storage, the AIJ formatted matrix can be copied to a format in which pieces of the matrix are stored in ELLPACK format, allowing the vectorized matrix multiply routine to use stride-1 memory accesses. If `nnz` is given then `nz` is ignored .seealso: [](ch_matrices), `Mat`, [Sparse Matrix Creation](sec_matsparse), `MATAIJ`, `MATAIJSELL`, `MATAIJPERM`, `MATAIJMKL`, `MatCreate()`, `MatCreateMPIAIJPERM()`, `MatSetValues()` @*/ PetscErrorCode MatCreateMPIAIJCRL(MPI_Comm comm, PetscInt m, PetscInt n, PetscInt nz, const PetscInt nnz[], PetscInt onz, const PetscInt onnz[], Mat *A) { PetscFunctionBegin; PetscCall(MatCreate(comm, A)); PetscCall(MatSetSizes(*A, m, n, m, n)); PetscCall(MatSetType(*A, MATMPIAIJCRL)); PetscCall(MatMPIAIJSetPreallocation_MPIAIJ(*A, nz, (PetscInt *)nnz, onz, (PetscInt *)onnz)); PetscFunctionReturn(PETSC_SUCCESS); } PETSC_EXTERN PetscErrorCode MatCreate_MPIAIJCRL(Mat A) { PetscFunctionBegin; PetscCall(MatSetType(A, MATMPIAIJ)); PetscCall(MatConvert_MPIAIJ_MPIAIJCRL(A, MATMPIAIJCRL, MAT_INPLACE_MATRIX, &A)); PetscFunctionReturn(PETSC_SUCCESS); }
af316b35ed63f659a603eeb4012fd8d72dc04951
79d11d81ffacf6fad9cf271256eda8ae4b30bdbc
/src/engine/crt.h
e91d9cfeae44d16d7a35e0c06971809ea09a8588
[ "MIT" ]
permissive
nem0/LumixEngine
d6c46d8febc54ff41e5bc5e6d71d861410f5b155
e6314612df50c6f37b34fb0dfcad9683cc506ec7
refs/heads/master
2023-09-02T09:14:49.212586
2023-08-23T21:01:37
2023-08-23T21:01:37
14,590,125
3,660
518
MIT
2023-09-14T14:49:32
2013-11-21T14:43:55
C++
UTF-8
C
false
false
3,933
h
crt.h
#pragma once #include "lumix.h" #if defined(_WIN32) && !defined(LUMIX_NO_CUSTOM_CRT) && !defined __clang__ #define _INC_FLOAT // if float.h is imported after this file, MCW_EM is redefined #define LUMIX_CRT_API LUMIX_LIBRARY_IMPORT #ifndef MCW_EM #define _EM_OVERFLOW 0x00000004 #define _EM_ZERODIVIDE 0x00000008 #define _EM_INVALID 0x00000010 #define _EM_DENORMAL 0x00080000 #define MCW_EM 0x0008001f #endif #define DBL_MAX 1.7976931348623158e+308 #define DBL_MIN 2.2250738585072014e-308 #define FLT_MAX 3.402823466e+38F #define FLT_MIN 1.175494351e-38F #define NULL 0 #define PRId64 "lld" #define PRIx64 "llx" extern "C" { typedef char* va_list; LUMIX_CRT_API void* __cdecl _aligned_malloc(size_t size, size_t align); LUMIX_CRT_API void __cdecl _aligned_free(void* ptr); LUMIX_CRT_API void* __cdecl _aligned_realloc(void* ptr, size_t size, size_t align); LUMIX_CRT_API unsigned int __cdecl _control87(unsigned int value, unsigned int mask); LUMIX_CRT_API int __cdecl _stricmp(const char* str1, const char* str2); LUMIX_CRT_API int __cdecl _strncmp(const char* str1, const char* str2); LUMIX_CRT_API int __cdecl _strnicmp(const char* str1, const char* str2, size_t max_count); LUMIX_CRT_API __declspec(noreturn) void __cdecl abort(void); LUMIX_CRT_API float __cdecl acosf(float x); LUMIX_CRT_API float __cdecl atan2f(float y, float x); LUMIX_CRT_API double __cdecl atof(const char* str); LUMIX_CRT_API int __cdecl atoi(const char* str); LUMIX_CRT_API double __cdecl ceil(double x); LUMIX_CRT_API float __cdecl cosf(float x); double __cdecl fabs(double x); LUMIX_CRT_API double __cdecl floor(double _X); #ifndef _INC_MATH #define _INC_MATH inline float __cdecl fabsf(float x) { return (float)fabs(x); } LUMIX_CRT_API float __cdecl floorf(float x); LUMIX_CRT_API float __cdecl ceilf(float x); #endif LUMIX_CRT_API float fmodf(float x, float y); double __cdecl fmod(double x, double y); LUMIX_CRT_API void __cdecl free(void* ptr); LUMIX_CRT_API int __cdecl _finite(double x); inline int __cdecl isinf(double x) { return !_finite(x); } double __cdecl log10(double x); LUMIX_CRT_API void* __cdecl malloc(size_t size); const void* __cdecl memchr(const void* buf, int val, size_t max_count); int __cdecl memcmp(const void* buf1, const void* buf2, size_t size); void* __cdecl memcpy(void* dst, void const* src, size_t size); __pragma(intrinsic(memcpy)) void* __cdecl memmove(void* dst, const void* src, size_t size); void* __cdecl memset(void* dst, int val, size_t size); __pragma(intrinsic(memmove)) LUMIX_CRT_API float __cdecl powf(float x, float y); double __cdecl pow(double x, double y); __pragma(intrinsic(pow)) LUMIX_CRT_API void __cdecl qsort(void* ptr, size_t count, size_t size, int(*cmp)(const void *, const void *)); LUMIX_CRT_API void* __cdecl realloc(void* ptr, size_t size); LUMIX_CRT_API float __cdecl sinf(float x); double __cdecl asin(double _X); LUMIX_CRT_API float __cdecl sqrtf(float x); double __cdecl sqrt(double _X); const char* __cdecl strchr(const char* str, int val); size_t __cdecl strlen(const char* str); int __cdecl strcmp(const char* str, const char* str2); char* strcpy(char* dest, const char* src); LUMIX_CRT_API int __cdecl strncmp(const char* str1, const char* str2, size_t max_count); LUMIX_CRT_API char* strncpy(char *dest, const char *src, size_t n); const char* __cdecl strstr(const char* str, const char* substr); LUMIX_CRT_API float __cdecl strtof(const char* str, char** end); double __cdecl tan(double _X); LUMIX_CRT_API float __cdecl tanf(float x); } #elif defined(__linux__) || defined(__clang__) #include <float.h> #include <inttypes.h> #include <limits.h> #include <math.h> #include <stdlib.h> #include <string.h> #ifndef __clang__ inline int stricmp(const char* a, const char* b) { return strcasecmp(a, b); } #endif #endif
3c2afba596550382ca09b654d999e5ded5a123c7
88ae8695987ada722184307301e221e1ba3cc2fa
/third_party/ffmpeg/libavformat/rtmppkt.h
a15d2a57732bc0e505a3132e3f5342d5b12cbfda
[ "LGPL-2.1-or-later", "BSD-2-Clause", "LGPL-2.1-only", "LGPL-3.0-only", "LGPL-2.0-or-later", "GPL-1.0-or-later", "GPL-2.0-only", "GPL-3.0-or-later", "LGPL-3.0-or-later", "IJG", "LicenseRef-scancode-other-permissive", "MIT", "GPL-2.0-or-later", "Apache-2.0", "GPL-3.0-only", "BSD-3-Clause" ]
permissive
iridium-browser/iridium-browser
71d9c5ff76e014e6900b825f67389ab0ccd01329
5ee297f53dc7f8e70183031cff62f37b0f19d25f
refs/heads/master
2023-08-03T16:44:16.844552
2023-07-20T15:17:00
2023-07-23T16:09:30
220,016,632
341
40
BSD-3-Clause
2021-08-13T13:54:45
2019-11-06T14:32:31
null
UTF-8
C
false
false
10,902
h
rtmppkt.h
/* * RTMP packet utilities * Copyright (c) 2009 Konstantin Shishkov * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef AVFORMAT_RTMPPKT_H #define AVFORMAT_RTMPPKT_H #include "libavcodec/bytestream.h" #include "avformat.h" #include "url.h" /** maximum possible number of different RTMP channels */ #define RTMP_CHANNELS 65599 /** * channels used to for RTMP packets with different purposes (i.e. data, network * control, remote procedure calls, etc.) */ enum RTMPChannel { RTMP_NETWORK_CHANNEL = 2, ///< channel for network-related messages (bandwidth report, ping, etc) RTMP_SYSTEM_CHANNEL, ///< channel for sending server control messages RTMP_AUDIO_CHANNEL, ///< channel for audio data RTMP_VIDEO_CHANNEL = 6, ///< channel for video data RTMP_SOURCE_CHANNEL = 8, ///< channel for a/v invokes }; /** * known RTMP packet types */ typedef enum RTMPPacketType { RTMP_PT_CHUNK_SIZE = 1, ///< chunk size change RTMP_PT_BYTES_READ = 3, ///< number of bytes read RTMP_PT_USER_CONTROL, ///< user control RTMP_PT_WINDOW_ACK_SIZE, ///< window acknowledgement size RTMP_PT_SET_PEER_BW, ///< peer bandwidth RTMP_PT_AUDIO = 8, ///< audio packet RTMP_PT_VIDEO, ///< video packet RTMP_PT_FLEX_STREAM = 15, ///< Flex shared stream RTMP_PT_FLEX_OBJECT, ///< Flex shared object RTMP_PT_FLEX_MESSAGE, ///< Flex shared message RTMP_PT_NOTIFY, ///< some notification RTMP_PT_SHARED_OBJ, ///< shared object RTMP_PT_INVOKE, ///< invoke some stream action RTMP_PT_METADATA = 22, ///< FLV metadata } RTMPPacketType; /** * possible RTMP packet header sizes */ enum RTMPPacketSize { RTMP_PS_TWELVEBYTES = 0, ///< packet has 12-byte header RTMP_PS_EIGHTBYTES, ///< packet has 8-byte header RTMP_PS_FOURBYTES, ///< packet has 4-byte header RTMP_PS_ONEBYTE ///< packet is really a next chunk of a packet }; /** * structure for holding RTMP packets */ typedef struct RTMPPacket { int channel_id; ///< RTMP channel ID (nothing to do with audio/video channels though) RTMPPacketType type; ///< packet payload type uint32_t timestamp; ///< packet full timestamp uint32_t ts_field; ///< 24-bit timestamp or increment to the previous one, in milliseconds (latter only for media packets). Clipped to a maximum of 0xFFFFFF, indicating an extended timestamp field. uint32_t extra; ///< probably an additional channel ID used during streaming data uint8_t *data; ///< packet payload int size; ///< packet payload size int offset; ///< amount of data read so far int read; ///< amount read, including headers } RTMPPacket; /** * Create new RTMP packet with given attributes. * * @param pkt packet * @param channel_id packet channel ID * @param type packet type * @param timestamp packet timestamp * @param size packet size * @return zero on success, negative value otherwise */ int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type, int timestamp, int size); /** * Free RTMP packet. * * @param pkt packet */ void ff_rtmp_packet_destroy(RTMPPacket *pkt); /** * Read RTMP packet sent by the server. * * @param h reader context * @param p packet * @param chunk_size current chunk size * @param prev_pkt previously read packet headers for all channels * (may be needed for restoring incomplete packet header) * @param nb_prev_pkt number of allocated elements in prev_pkt * @return number of bytes read on success, negative value otherwise */ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket **prev_pkt, int *nb_prev_pkt); /** * Read internal RTMP packet sent by the server. * * @param h reader context * @param p packet * @param chunk_size current chunk size * @param prev_pkt previously read packet headers for all channels * (may be needed for restoring incomplete packet header) * @param nb_prev_pkt number of allocated elements in prev_pkt * @param c the first byte already read * @return number of bytes read on success, negative value otherwise */ int ff_rtmp_packet_read_internal(URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket **prev_pkt, int *nb_prev_pkt, uint8_t c); /** * Send RTMP packet to the server. * * @param h reader context * @param p packet to send * @param chunk_size current chunk size * @param prev_pkt previously sent packet headers for all channels * (may be used for packet header compressing) * @param nb_prev_pkt number of allocated elements in prev_pkt * @return number of bytes written on success, negative value otherwise */ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket **prev_pkt, int *nb_prev_pkt); /** * Print information and contents of RTMP packet. * * @param ctx output context * @param p packet to dump */ void ff_rtmp_packet_dump(void *ctx, RTMPPacket *p); /** * Enlarge the prev_pkt array to fit the given channel * * @param prev_pkt array with previously sent packet headers * @param nb_prev_pkt number of allocated elements in prev_pkt * @param channel the channel number that needs to be allocated */ int ff_rtmp_check_alloc_array(RTMPPacket **prev_pkt, int *nb_prev_pkt, int channel); /** * @name Functions used to work with the AMF format (which is also used in .flv) * @see amf_* funcs in libavformat/flvdec.c * @{ */ /** * Calculate number of bytes taken by first AMF entry in data. * * @param data input data * @param data_end input buffer end * @return number of bytes used by first AMF entry */ int ff_amf_tag_size(const uint8_t *data, const uint8_t *data_end); /** * Retrieve value of given AMF object field in string form. * * @param data AMF object data * @param data_end input buffer end * @param name name of field to retrieve * @param dst buffer for storing result * @param dst_size output buffer size * @return 0 if search and retrieval succeeded, negative value otherwise */ int ff_amf_get_field_value(const uint8_t *data, const uint8_t *data_end, const uint8_t *name, uint8_t *dst, int dst_size); /** * Write boolean value in AMF format to buffer. * * @param dst pointer to the input buffer (will be modified) * @param val value to write */ void ff_amf_write_bool(uint8_t **dst, int val); /** * Write number in AMF format to buffer. * * @param dst pointer to the input buffer (will be modified) * @param num value to write */ void ff_amf_write_number(uint8_t **dst, double num); /** * Write string in AMF format to buffer. * * @param dst pointer to the input buffer (will be modified) * @param str string to write */ void ff_amf_write_string(uint8_t **dst, const char *str); /** * Write a string consisting of two parts in AMF format to a buffer. * * @param dst pointer to the input buffer (will be modified) * @param str1 first string to write, may be null * @param str2 second string to write, may be null */ void ff_amf_write_string2(uint8_t **dst, const char *str1, const char *str2); /** * Write AMF NULL value to buffer. * * @param dst pointer to the input buffer (will be modified) */ void ff_amf_write_null(uint8_t **dst); /** * Write marker for AMF object to buffer. * * @param dst pointer to the input buffer (will be modified) */ void ff_amf_write_object_start(uint8_t **dst); /** * Write string used as field name in AMF object to buffer. * * @param dst pointer to the input buffer (will be modified) * @param str string to write */ void ff_amf_write_field_name(uint8_t **dst, const char *str); /** * Write marker for end of AMF object to buffer. * * @param dst pointer to the input buffer (will be modified) */ void ff_amf_write_object_end(uint8_t **dst); /** * Read AMF number value. * *@param[in,out] gbc GetByteContext initialized with AMF-formatted data *@param[out] val read value *@return 0 on success or an AVERROR code on failure */ int ff_amf_read_number(GetByteContext *gbc, double *val); /** * Get AMF string value. * * This function behaves the same as ff_amf_read_string except that * it does not expect the AMF type prepended to the actual data. * Appends a trailing null byte to output string in order to * ease later parsing. * *@param[in,out] gbc GetByteContext initialized with AMF-formatted data *@param[out] str read string *@param[in] strsize buffer size available to store the read string *@param[out] length read string length *@return 0 on success or an AVERROR code on failure */ int ff_amf_get_string(GetByteContext *bc, uint8_t *str, int strsize, int *length); /** * Read AMF string value. * * Appends a trailing null byte to output string in order to * ease later parsing. * *@param[in,out] gbc GetByteContext initialized with AMF-formatted data *@param[out] str read string *@param[in] strsize buffer size available to store the read string *@param[out] length read string length *@return 0 on success or an AVERROR code on failure */ int ff_amf_read_string(GetByteContext *gbc, uint8_t *str, int strsize, int *length); /** * Read AMF NULL value. * *@param[in,out] gbc GetByteContext initialized with AMF-formatted data *@return 0 on success or an AVERROR code on failure */ int ff_amf_read_null(GetByteContext *gbc); /** * Match AMF string with a NULL-terminated string. * * @return 0 if the strings do not match. */ int ff_amf_match_string(const uint8_t *data, int size, const char *str); /** @} */ // AMF funcs #endif /* AVFORMAT_RTMPPKT_H */
c91fa13f085c73c001995ae21d7acba6bf7001d5
d84c7df450292867f8c7bb58d1507735479d746d
/tests/t509-operator.c
793f8d40e9c2f3517f12656b7a6ba6b5945b999f
[ "BSD-2-Clause", "BSD-3-Clause" ]
permissive
CEED/libCEED
c17e8b2f8e9ccfafc0505bb6db451e2f7cfed690
c6c10e0994b55ea1726a79024cd4c333c40de38a
refs/heads/main
2023-09-01T20:13:21.268643
2023-09-01T20:08:36
2023-09-01T20:08:36
113,349,904
167
54
BSD-2-Clause
2023-09-14T20:37:58
2017-12-06T17:57:40
C
UTF-8
C
false
false
2,577
c
t509-operator.c
/// @file /// Test creation, action, and destruction for identity operator /// \test Test creation, action, and destruction for identity operator #include <ceed.h> #include <math.h> #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { Ceed ceed; CeedElemRestriction elem_restriction_u, elem_restriction_u_i; CeedBasis basis_u; CeedQFunction qf_identity; CeedOperator op_identity; CeedVector u, v; CeedInt num_elem = 15, p = 5, q = 8; CeedInt elem_size = p, num_nodes = num_elem * (p - 1) + 1; CeedInt ind_u[num_elem * p]; CeedInit(argv[1], &ceed); CeedVectorCreate(ceed, num_nodes, &u); CeedVectorCreate(ceed, elem_size * num_elem, &v); // Restrictions for (CeedInt i = 0; i < num_elem; i++) { for (CeedInt j = 0; j < p; j++) { ind_u[p * i + j] = i * (p - 1) + j; } } CeedElemRestrictionCreate(ceed, num_elem, elem_size, 1, 1, num_nodes, CEED_MEM_HOST, CEED_USE_POINTER, ind_u, &elem_restriction_u); CeedInt strides_u_i[3] = {1, p, p}; CeedElemRestrictionCreateStrided(ceed, num_elem, elem_size, 1, elem_size * num_elem, strides_u_i, &elem_restriction_u_i); // Bases CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, p, q, CEED_GAUSS, &basis_u); // QFunction CeedQFunctionCreateIdentity(ceed, 1, CEED_EVAL_NONE, CEED_EVAL_NONE, &qf_identity); // Operators CeedOperatorCreate(ceed, qf_identity, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_identity); // -- Note: number of quadrature points for field set by elem_size of restriction when CEED_BASIS_NONE used CeedOperatorSetField(op_identity, "input", elem_restriction_u, CEED_BASIS_NONE, CEED_VECTOR_ACTIVE); CeedOperatorSetField(op_identity, "output", elem_restriction_u_i, CEED_BASIS_NONE, CEED_VECTOR_ACTIVE); CeedVectorSetValue(u, 3.0); CeedOperatorApply(op_identity, u, v, CEED_REQUEST_IMMEDIATE); // Check output { const CeedScalar *v_array; CeedVectorGetArrayRead(v, CEED_MEM_HOST, &v_array); for (CeedInt i = 0; i < elem_size * num_elem; i++) { if (fabs(v_array[i] - 3.) > 1e-14) printf("[%" CeedInt_FMT "] Computed Value: %f != True Value: 1.0\n", i, v_array[i]); } CeedVectorRestoreArrayRead(v, &v_array); } CeedVectorDestroy(&u); CeedVectorDestroy(&v); CeedElemRestrictionDestroy(&elem_restriction_u); CeedElemRestrictionDestroy(&elem_restriction_u_i); CeedBasisDestroy(&basis_u); CeedQFunctionDestroy(&qf_identity); CeedOperatorDestroy(&op_identity); CeedDestroy(&ceed); return 0; }
6dd95ba269630e36ad366a24302c32f79232de2f
76f9898ff7a555f4a729d725056a317af818375d
/src/code/z_fbdemo_wipe1.c
f77b53532a3eb0db0cfe8b606fb4d6f51650913b
[]
no_license
z64proto/sw97
0b65837ab2f2a4073faca5670761d7fe0e74d29d
f571505ade2cefd4a5b5d19da06d33e7c6b02c60
refs/heads/master
2023-08-01T02:47:42.895871
2022-05-15T20:29:08
2022-05-15T20:29:08
430,216,978
208
29
null
2021-11-22T12:23:50
2021-11-20T21:52:59
C
UTF-8
C
false
false
18,676
c
z_fbdemo_wipe1.c
#include "global.h" Vtx sWipeVtx[] = { VTX(-1299, 750, 0, 13653, 2048, 0xAD, 0x30, 0xB8, 0xFF), VTX(-750, 1299, 0, 15019, 2048, 0xD0, 0x53, 0xB8, 0xFF), VTX(0, 0, -500, 14336, 0, 0xCE, 0xCE, 0xA0, 0xFF), VTX(0, 1500, 0, 16384, 2048, 0x00, 0x60, 0xB8, 0xFF), VTX(0, 0, -500, 15701, 0, 0x3D, 0x3D, 0xAD, 0xFF), VTX(0, 1500, 0, 0, 2048, 0x00, 0x60, 0xB8, 0xFF), VTX(750, 1299, 0, 1365, 2048, 0x30, 0x53, 0xB8, 0xFF), VTX(0, 0, -500, 683, 0, 0x3D, 0x3D, 0xAD, 0xFF), VTX(1299, 750, 0, 2731, 2048, 0x53, 0x30, 0xB8, 0xFF), VTX(0, 0, -500, 2048, 0, 0x3D, 0x3D, 0xAD, 0xFF), VTX(1500, 0, 0, 4096, 2048, 0x60, 0x00, 0xB8, 0xFF), VTX(0, 0, -500, 3413, 0, 0x3D, 0x3D, 0xAD, 0xFF), VTX(1299, -750, 0, 5461, 2048, 0x53, 0xD0, 0xB8, 0xFF), VTX(0, 0, -500, 4779, 0, 0x3D, 0x3D, 0xAD, 0xFF), VTX(750, -1299, 0, 6827, 2048, 0x30, 0xAD, 0xB8, 0xFF), VTX(0, 0, -500, 6144, 0, 0xCE, 0xCE, 0xA0, 0xFF), VTX(0, -1500, 0, 8192, 2048, 0x00, 0xA0, 0xB8, 0xFF), VTX(0, 0, -500, 7509, 0, 0xCE, 0xCE, 0xA0, 0xFF), VTX(-750, -1299, 0, 9557, 2048, 0xD0, 0xAD, 0xB8, 0xFF), VTX(0, 0, -500, 8875, 0, 0xCE, 0xCE, 0xA0, 0xFF), VTX(-1299, -750, 0, 10923, 2048, 0xAD, 0xD0, 0xB8, 0xFF), VTX(0, 0, -500, 10240, 0, 0xCE, 0xCE, 0xA0, 0xFF), VTX(-1500, 0, 0, 12288, 2048, 0xA0, 0x00, 0xB8, 0xFF), VTX(0, 0, -500, 11605, 0, 0xCE, 0xCE, 0xA0, 0xFF), VTX(0, 0, -500, 12971, 0, 0xCE, 0xCE, 0xA0, 0xFF), }; char sWipeTexture[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x20, 0x01, 0x24, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x30, 0x12, 0x34, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x31, 0x23, 0x45, 0x21, 0x10, 0x00, 0x00, 0x01, 0x00, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x41, 0x34, 0x56, 0x31, 0x10, 0x00, 0x00, 0x01, 0x00, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x10, 0x02, 0x42, 0x35, 0x66, 0x32, 0x20, 0x00, 0x00, 0x02, 0x00, 0x32, 0x13, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x00, 0x10, 0x02, 0x53, 0x45, 0x67, 0x42, 0x20, 0x00, 0x00, 0x02, 0x01, 0x32, 0x23, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x12, 0x00, 0x10, 0x00, 0x10, 0x03, 0x64, 0x56, 0x77, 0x53, 0x30, 0x01, 0x00, 0x13, 0x12, 0x42, 0x24, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x01, 0x31, 0x13, 0x00, 0x11, 0x00, 0x10, 0x03, 0x64, 0x67, 0x77, 0x54, 0x41, 0x01, 0x00, 0x14, 0x12, 0x53, 0x35, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x41, 0x24, 0x11, 0x21, 0x00, 0x20, 0x14, 0x75, 0x67, 0x77, 0x64, 0x51, 0x12, 0x00, 0x24, 0x23, 0x53, 0x46, 0x30, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x52, 0x34, 0x11, 0x31, 0x01, 0x20, 0x15, 0x76, 0x77, 0x87, 0x65, 0x52, 0x13, 0x00, 0x25, 0x34, 0x64, 0x56, 0x31, 0x20, 0x00, 0x00, 0x00, 0x01, 0x31, 0x02, 0x10, 0x00, 0x00, 0x00, 0x10, 0x03, 0x52, 0x35, 0x22, 0x41, 0x02, 0x21, 0x26, 0x77, 0x77, 0x87, 0x75, 0x62, 0x13, 0x11, 0x36, 0x35, 0x65, 0x57, 0x41, 0x30, 0x00, 0x10, 0x00, 0x01, 0x31, 0x12, 0x10, 0x10, 0x00, 0x00, 0x10, 0x04, 0x62, 0x46, 0x23, 0x51, 0x02, 0x21, 0x36, 0x77, 0x78, 0x88, 0x76, 0x63, 0x24, 0x11, 0x46, 0x46, 0x75, 0x67, 0x52, 0x40, 0x01, 0x10, 0x00, 0x02, 0x42, 0x13, 0x10, 0x20, 0x01, 0x00, 0x21, 0x15, 0x63, 0x56, 0x34, 0x51, 0x13, 0x31, 0x47, 0x88, 0x78, 0x88, 0x77, 0x64, 0x24, 0x22, 0x56, 0x56, 0x76, 0x77, 0x53, 0x41, 0x02, 0x10, 0x10, 0x03, 0x53, 0x23, 0x21, 0x31, 0x01, 0x01, 0x31, 0x16, 0x74, 0x66, 0x35, 0x62, 0x14, 0x32, 0x47, 0x88, 0x88, 0x88, 0x87, 0x75, 0x34, 0x22, 0x57, 0x57, 0x76, 0x77, 0x54, 0x51, 0x03, 0x10, 0x11, 0x04, 0x63, 0x34, 0x22, 0x31, 0x02, 0x01, 0x42, 0x26, 0x74, 0x67, 0x46, 0x62, 0x25, 0x42, 0x57, 0x89, 0x88, 0x88, 0x98, 0x75, 0x35, 0x33, 0x67, 0x67, 0x77, 0x77, 0x65, 0x51, 0x03, 0x10, 0x21, 0x14, 0x64, 0x45, 0x33, 0x41, 0x12, 0x12, 0x52, 0x37, 0x75, 0x77, 0x56, 0x72, 0x36, 0x53, 0x67, 0x89, 0x88, 0x89, 0xA8, 0x76, 0x45, 0x44, 0x67, 0x67, 0x87, 0x77, 0x76, 0x62, 0x14, 0x21, 0x32, 0x15, 0x75, 0x55, 0x43, 0x52, 0x13, 0x13, 0x63, 0x47, 0x75, 0x77, 0x57, 0x73, 0x46, 0x54, 0x78, 0x8A, 0x88, 0x9A, 0xA8, 0x77, 0x56, 0x55, 0x77, 0x67, 0x88, 0x88, 0x76, 0x72, 0x25, 0x21, 0x42, 0x26, 0x75, 0x66, 0x54, 0x62, 0x24, 0x23, 0x64, 0x57, 0x76, 0x77, 0x67, 0x74, 0x57, 0x65, 0x78, 0x9B, 0x89, 0x9B, 0xB8, 0x87, 0x56, 0x55, 0x77, 0x78, 0x88, 0x88, 0x87, 0x73, 0x25, 0x21, 0x43, 0x36, 0x76, 0x67, 0x65, 0x63, 0x35, 0x24, 0x75, 0x57, 0x77, 0x77, 0x77, 0x75, 0x67, 0x65, 0x78, 0x9B, 0x89, 0xAB, 0xC8, 0x87, 0x67, 0x66, 0x77, 0x78, 0x98, 0x88, 0x98, 0x74, 0x36, 0x32, 0x54, 0x37, 0x76, 0x77, 0x66, 0x73, 0x45, 0x35, 0x75, 0x67, 0x77, 0x88, 0x77, 0x75, 0x67, 0x66, 0x78, 0xAC, 0x9A, 0xBC, 0xC8, 0x87, 0x67, 0x66, 0x77, 0x78, 0xA9, 0x88, 0x98, 0x75, 0x46, 0x33, 0x65, 0x47, 0x77, 0x77, 0x77, 0x74, 0x56, 0x46, 0x76, 0x77, 0x87, 0x89, 0x88, 0x76, 0x77, 0x76, 0x78, 0xBD, 0x9B, 0xCD, 0xD8, 0x98, 0x77, 0x76, 0x78, 0x78, 0xAA, 0x89, 0x98, 0x76, 0x56, 0x44, 0x66, 0x57, 0x77, 0x77, 0x77, 0x75, 0x67, 0x46, 0x77, 0x78, 0x88, 0x89, 0x88, 0x87, 0x78, 0x87, 0x78, 0xCD, 0x9C, 0xDE, 0xD9, 0x98, 0x77, 0x77, 0x78, 0x88, 0xBA, 0x99, 0xA8, 0x76, 0x66, 0x44, 0x76, 0x67, 0x88, 0x88, 0x88, 0x75, 0x77, 0x56, 0x77, 0x78, 0x99, 0x89, 0x88, 0x88, 0x88, 0x87, 0x88, 0xCD, 0x9D, 0xEE, 0xD9, 0xA8, 0x88, 0x87, 0x88, 0x88, 0xCB, 0x9A, 0xA8, 0x77, 0x67, 0x55, 0x77, 0x77, 0x88, 0x88, 0x88, 0x76, 0x77, 0x67, 0x78, 0x88, 0xAA, 0x8A, 0x98, 0x89, 0x88, 0x98, 0x88, 0xDD, 0xAD, 0xFE, 0xDA, 0xB9, 0x88, 0x98, 0x89, 0x88, 0xDC, 0xAB, 0xB8, 0x88, 0x77, 0x56, 0x77, 0x77, 0x89, 0x88, 0x98, 0x76, 0x77, 0x67, 0x88, 0x88, 0xAA, 0x8A, 0xA8, 0x9A, 0x88, 0xA8, 0x89, 0xDD, 0xAE, 0xFF, 0xDA, 0xC9, 0x88, 0x98, 0x89, 0x88, 0xDD, 0xAC, 0xB8, 0x88, 0x77, 0x66, 0x78, 0x78, 0x99, 0x88, 0x98, 0x77, 0x77, 0x77, 0x89, 0x88, 0xBB, 0x9B, 0xA8, 0x9B, 0x88, 0xB8, 0x8A, 0xED, 0xBE, 0xFF, 0xDB, 0xDA, 0x88, 0xA8, 0x8A, 0x89, 0xED, 0xBD, 0xC8, 0x89, 0x87, 0x67, 0x89, 0x88, 0x9A, 0x88, 0xA8, 0x87, 0x77, 0x77, 0x8A, 0x88, 0xCB, 0x9C, 0xB8, 0xAC, 0x88, 0xC9, 0x8A, 0xFD, 0xCF, 0xFF, 0xEC, 0xEB, 0x89, 0xB8, 0x9B, 0x89, 0xED, 0xCE, 0xC8, 0x9A, 0x87, 0x77, 0x89, 0x88, 0xAB, 0x89, 0xA8, 0x87, 0x88, 0x78, 0x8B, 0x89, 0xDC, 0x9C, 0xC9, 0xBC, 0x88, 0xDA, 0x8B, 0xFE, 0xCF, 0xFF, 0xEC, 0xEB, 0x8A, 0xC9, 0xAC, 0x9A, 0xEE, 0xCE, 0xD8, 0x9A, 0x87, 0x77, 0x8A, 0x88, 0xBC, 0x9A, 0xB8, 0x98, 0x88, 0x78, 0x8B, 0x8A, 0xED, 0x9D, 0xC9, 0xCD, 0x89, 0xEB, 0x8C, 0xFE, 0xDF, 0xFF, 0xFD, 0xFC, 0x9B, 0xD9, 0xBD, 0x9A, 0xFE, 0xDF, 0xE9, 0xAB, 0x88, 0x77, 0x8A, 0x88, 0xCD, 0x9B, 0xC8, 0xA9, 0x88, 0x88, 0x9C, 0x9A, 0xED, 0xAD, 0xD9, 0xDE, 0x89, 0xEB, 0x9C, 0xFE, 0xEF, 0xFF, 0xFE, 0xFD, 0x9B, 0xD9, 0xBD, 0xAB, 0xFE, 0xDF, 0xE9, 0xBC, 0x88, 0x88, 0x8B, 0x98, 0xDD, 0xAB, 0xC9, 0xAA, 0x88, 0x88, 0xAD, 0x9B, 0xED, 0xBE, 0xE9, 0xDE, 0x99, 0xEC, 0x9D, 0xFE, 0xFF, 0xFF, 0xFF, 0xFD, 0xAC, 0xE9, 0xCE, 0xAC, 0xFE, 0xDF, 0xE9, 0xCC, 0x89, 0x88, 0x8C, 0x99, 0xEE, 0xAC, 0xC9, 0xBB, 0x88, 0x88, 0xAE, 0x9B, 0xFD, 0xBF, 0xE9, 0xEE, 0x99, 0xEC, 0x9D, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xAD, 0xE9, 0xDE, 0xBD, 0xFE, 0xEF, 0xEA, 0xDD, 0x99, 0x88, 0x9D, 0xA9, 0xEE, 0xAD, 0xDA, 0xCC, 0x89, 0x88, 0xBE, 0xAC, 0xFE, 0xCF, 0xEA, 0xEE, 0xAA, 0xED, 0x9E, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBE, 0xEA, 0xDF, 0xCE, 0xFE, 0xEF, 0xEB, 0xED, 0x9A, 0x88, 0xAD, 0xAA, 0xFE, 0xBE, 0xDA, 0xDC, 0x99, 0x98, 0xCE, 0xBD, 0xFE, 0xDF, 0xEA, 0xFF, 0xAB, 0xFD, 0xAE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xCE, 0xDA, 0xEF, 0xCE, 0xFE, 0xFF, 0xFC, 0xED, 0x9A, 0x88, 0xBE, 0xBB, 0xFE, 0xBE, 0xDB, 0xED, 0xAA, 0xA9, 0xDF, 0xBD, 0xFD, 0xEF, 0xEB, 0xFF, 0xBC, 0xFE, 0xBE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xDF, 0xEB, 0xEF, 0xDF, 0xFF, 0xFF, 0xFD, 0xFC, 0x9B, 0x99, 0xCE, 0xBC, 0xFE, 0xCF, 0xEC, 0xFE, 0xBB, 0xB9, 0xEF, 0xCE, 0xFD, 0xEF, 0xEC, 0xFF, 0xCD, 0xFE, 0xCE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xDF, 0xEC, 0xEF, 0xDF, 0xFF, 0xFF, 0xFD, 0xFC, 0xAC, 0xAA, 0xCE, 0xCD, 0xFE, 0xDF, 0xEC, 0xFE, 0xCC, 0xBA, 0xEF, 0xDE, 0xED, 0xFF, 0xED, 0xFF, 0xDD, 0xEE, 0xCF, 0xEE, 0xFF, 0xFF, 0xFF, 0xFE, 0xEF, 0xEC, 0xEF, 0xEF, 0xFF, 0xFF, 0xFE, 0xFC, 0xBC, 0xAB, 0xDD, 0xDD, 0xFE, 0xDF, 0xED, 0xFE, 0xCD, 0xCB, 0xFF, 0xEE, 0xEC, 0xFF, 0xDD, 0xFF, 0xEE, 0xEE, 0xDF, 0xEE, 0xFF, 0xFF, 0xFF, 0xFE, 0xEF, 0xED, 0xFF, 0xEF, 0xFF, 0xFF, 0xFF, 0xFC, 0xCD, 0xAC, 0xED, 0xDE, 0xFE, 0xEF, 0xFE, 0xFE, 0xDE, 0xDC, 0xFF, 0xEF, 0xEC, 0xFF, 0xDE, 0xFF, 0xFF, 0xEE, 0xEF, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xCD, 0xAD, 0xFD, 0xDF, 0xFE, 0xEF, 0xFF, 0xFE, 0xEE, 0xED, 0xFF, 0xFF, 0xEC, 0xFF, 0xDF, 0xFE, 0xFF, 0xEF, 0xFF, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xDD, 0xBE, 0xFD, 0xEF, 0xFF, 0xFF, 0xFF, 0xFE, 0xEF, 0xED, 0xFF, 0xFF, 0xEB, 0xFF, 0xDF, 0xFE, 0xFF, 0xEF, 0xFF, 0xEF, 0xFF, 0xFF, 0xFF, 0xEF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xEE, 0xBE, 0xFD, 0xEF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xEE, 0xFF, 0xFF, 0xEB, 0xFF, 0xDF, 0xFE, 0xFF, 0xEF, 0xFF, 0xEF, 0xFF, 0xFF, 0xFF, 0xEF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFE, 0xBF, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xEF, 0xEE, 0xFF, 0xFF, 0xFC, 0xFF, 0xEF, 0xFE, 0xFF, 0xEF, 0xFF, 0xEF, 0xFF, 0xFF, 0xFF, 0xEF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xAF, 0xFE, 0xFF, 0xFF, 0xFF, 0xEF, 0xFE, 0xEF, 0xEE, 0xFF, 0xFF, 0xFC, 0xFF, 0xEF, 0xFE, 0xFF, 0xEF, 0xFF, 0xEF, 0xFF, 0xFF, 0xFF, 0xDF, 0xFF, 0xFF, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAF, 0xFE, 0xFF, 0xFF, 0xFF, 0xEF, 0xFE, 0xEF, 0xEE, 0xFF, 0xFF, 0xFC, 0xFF, 0xEF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDF, 0xFF, 0xFF, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xAE, 0xFE, 0xFF, 0xFF, 0xFF, 0xEF, 0xFF, 0xEF, 0xED, 0xFF, 0xFF, 0xFC, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }; Gfx sWipeDList[] = { gsDPPipeSync(), gsSPClearGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR | G_LOD | G_SHADING_SMOOTH), gsSPSetGeometryMode(G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH), gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_1PRIMITIVE, G_AC_NONE | G_ZS_PRIM | G_RM_PASS | G_RM_AA_ZB_TEX_EDGE2), gsDPSetCombineLERP(TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0, TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0, COMBINED, 0, PRIMITIVE, 0, COMBINED, 0, PRIMITIVE, 0), gsDPSetPrimDepth(0, 0), gsDPLoadTextureBlock_4b(sWipeTexture, G_IM_FMT_I, 64, 64, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_MIRROR | G_TX_WRAP, 6, 6, 11, G_TX_NOLOD), gsDPLoadMultiBlock_4b(sWipeTexture, 0x0100, 1, G_IM_FMT_I, 64, 64, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_MIRROR | G_TX_WRAP, 6, 6, 11, 1), gsDPSetTextureLUT(G_TT_NONE), gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON), gsSPDisplayList(0x08000000), gsSPVertex(sWipeVtx, 25, 0), gsSP2Triangles(0, 1, 2, 0, 1, 3, 4, 0), gsSP2Triangles(5, 6, 7, 0, 6, 8, 9, 0), gsSP2Triangles(8, 10, 11, 0, 10, 12, 13, 0), gsSP2Triangles(12, 14, 15, 0, 14, 16, 17, 0), gsSP2Triangles(16, 18, 19, 0, 18, 20, 21, 0), gsSP2Triangles(20, 22, 23, 0, 22, 0, 24, 0), gsSPEndDisplayList(), }; #define THIS ((TransitionWipe*)thisx) void TransitionWipe_Start(void* thisx) { TransitionWipe* this = THIS; this->isDone = 0; if (this->direction) { this->texY = 0x14D; } else { this->texY = 0x264; } guPerspective(&this->projection, &this->normal, 60.0f, (4.0 / 3.0f), 10.0f, 12800.0f, 1.0f); guLookAt(&this->lookAt, 0.0f, 0.0f, 400.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); } void* TransitionWipe_Init(void* thisx) { TransitionWipe* this = THIS; bzero(this, sizeof(*this)); return this; } void TransitionWipe_Destroy(void* thisx) { } void TransitionWipe_Update(void* thisx, s32 updateRate) { TransitionWipe* this = THIS; u8 unk1419; if (this->direction != 0) { unk1419 = gSaveContext.unk_1419; this->texY += (unk1419 * 3) / updateRate; if (this->texY >= 0x264) { this->texY = 0x264; this->isDone = 1; } } else { unk1419 = gSaveContext.unk_1419; this->texY -= (unk1419 * 3) / updateRate; if (this->texY < 0x14E) { this->texY = 0x14D; this->isDone = 1; } } } void TransitionWipe_Draw(void* thisx, Gfx** gfxP) { Gfx* gfx = *gfxP; Mtx* modelView; TransitionWipe* this = THIS; s32 pad[4]; Gfx* tex; modelView = this->modelView[this->frame]; this->frame ^= 1; guScale(&modelView[0], 0.56f, 0.56f, 1.0f); guRotate(&modelView[1], 0.0f, 0.0f, 0.0f, 1.0f); guTranslate(&modelView[2], 0.0f, 0.0f, 0.0f); gDPPipeSync(gfx++); tex = Gfx_BranchTexScroll(&gfx, this->texX, this->texY, 0, 0); gSPSegment(gfx++, 8, tex); gDPSetPrimColor(gfx++, 0, 0x80, this->color.r, this->color.g, this->color.b, 255); gSPMatrix(gfx++, &this->projection, G_MTX_LOAD | G_MTX_PROJECTION); gSPPerspNormalize(gfx++, this->normal); gSPMatrix(gfx++, &this->lookAt, G_MTX_MUL | G_MTX_PROJECTION); gSPMatrix(gfx++, &modelView[0], G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPMatrix(gfx++, &modelView[1], G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW); gSPMatrix(gfx++, &modelView[2], G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW); gSPDisplayList(gfx++, sWipeDList); gDPPipeSync(gfx++); *gfxP = gfx; } s32 TransitionWipe_IsDone(void* thisx) { TransitionWipe* this = THIS; return this->isDone; } void TransitionWipe_SetType(void* thisx, s32 type) { TransitionWipe* this = THIS; if (type == 1) { this->direction = 1; } else { this->direction = 0; } if (this->direction != 0) { this->texY = 0x14D; } else { this->texY = 0x264; } } void TransitionWipe_SetColor(void* thisx, u32 color) { TransitionWipe* this = THIS; this->color.rgba = color; } void TransitionWipe_SetEnvColor(void* thisx, u32 color) { TransitionWipe* this = THIS; this->envColor.rgba = color; }
33b40f1d4163429fe8da5d5d4b6cb441fd889a59
695180c14d136c1af33e50497c7957dc74835680
/tools/driver/drivers/char/tpu_common/tpuv4_driver.c
5e7ca53760381487f4a540749fb62ee6dd73ab49
[ "Apache-2.0" ]
permissive
tensorflow/tpu
4517c43b42c3dd98b8abafbbd9457384dd9639b1
0f7adb97a93ec3e3485c261d030c507eb16b33e4
refs/heads/master
2023-09-02T23:33:31.299394
2023-09-01T00:43:03
2023-09-01T00:43:03
96,946,693
5,627
2,107
Apache-2.0
2023-09-13T17:50:43
2017-07-11T23:54:39
Jupyter Notebook
UTF-8
C
false
false
5,239
c
tpuv4_driver.c
/* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (C) 2021 Google LLC. */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/pci.h> #include "drivers/asic_sw/asic_fw_state_offsets.h" #include "drivers/asic_sw/asic_fw_reinit_reset_offsets.h" #include "drivers/char/tpu_common/tpu_common.h" #include "drivers/char/tpu_common/tpuv4.h" #include "drivers/char/tpu_common/tpuv4/tpuv4.h" #include "drivers/char/tpu_common/tpuv4/tpuv4_bar0_ranges.h" #include "drivers/char/tpu_common/tpuv4/tpuv4_bar2_ranges.h" #include "drivers/char/tpu_common/tpuv4/tpuv4_device_owner_offsets.h" #include "drivers/char/tpu_common/tpuv4/tpuv4_mgr_error_loperf_offsets.h" #include "drivers/char/tpu_common/tpuv4/tpuv4_firmware_state_offsets.h" #include "drivers/char/tpu_common/tpuv4/tpuv4_firmware_version_offsets.h" #include "drivers/char/tpu_common/tpuv4/tpuv4_interrupt_desc.h" #include "drivers/char/tpu_common/tpuv4/tpuv4_userspace_firmware_indirect_accessor_offsets.h" #include "drivers/char/tpu_common/tpuv4/tpuv4_userspace_lst_port_indirect_offsets.h" #include "drivers/char/tpu_common/tpuv4/tpuv4_page_table_config.h" #include "drivers/char/tpu_common/tpuv4/tpuv4_pcie_flr_status_offsets.h" #include "drivers/char/tpu_common/tpuv4/tpuv4_reinit_reset_offsets.h" #include "drivers/char/tpu_common/tpuv4common.h" #include "drivers/char/tpu_common/tpuv4common/tpuv4common_mgr_error_loperf_offsets.h" #include "drivers/char/tpu_common/tpuv4common/tpuv4common_pcie_flr_status_offsets.h" #include "drivers/gasket/gasket_core.h" #include "drivers/gasket/gasket_logging.h" #define TPUV4_PCI_DEVICE_ID 0x005e #define TPUV4_PCI_VENDOR_ID 0x1ae0 static const struct pci_device_id tpuv4_pci_ids[] = { { PCI_DEVICE(TPUV4_PCI_VENDOR_ID, TPUV4_PCI_DEVICE_ID) }, { 0 }, }; static const struct gasket_mappable_region lbus_bar_regions[] = { { 0x0, TPUV4_LBUS_BAR_BYTES }, }; static const struct gasket_mappable_region csr_bar_regions[] = { { 0x0, TPUV4_CSR_BAR_BYTES }, }; static const struct tpuv4_setup_data setup_data = { .software_csr_bar_index = TPUV4_CSR_BAR_INDEX, .reinit_reset_value = TPUV4_CHIP_REINIT_RESET, .reset_accepted_value = TPUV4_RESET_ACCEPTED, .chip_init_done_value = TPUV4_CHIP_INIT_DONE, .reset_retry_value = TPUV4_RESET_RETRY, .reset_delay_value = TPUV4_RESET_DELAY, .error_offsets_get = tpuv4_mgr_error_loperf_offsets_get, .device_owner_offsets_get = tpuv4_device_owner_offsets_get, .indirect_register_offsets_get = tpuv4_userspace_firmware_indirect_accessor_offsets_get, .userspace_lst_port_indirect_offsets_count = tpuv4_userspace_lst_port_indirect_offsets_count, .userspace_lst_port_indirect_offsets_get = tpuv4_userspace_lst_port_indirect_offsets_get, .bar0_get_region_count = tpuv4_bar0_get_region_count, .bar0_get_regions = tpuv4_bar0_get_regions, .bar2_get_region_count = tpuv4_bar2_get_region_count, .bar2_get_regions = tpuv4_bar2_get_regions, .firmware_state_offsets_get = tpuv4_firmware_state_offsets_get, .firmware_version_offsets_get = tpuv4_firmware_version_offsets_get, .firmware_reinit_reset_offsets_get = tpuv4_reinit_reset_offsets_get, .pcie_flr_status_offsets_get = tpuv4_pcie_flr_status_offsets_get, }; static int add_dev_cb(struct gasket_dev *gasket_dev) { return tpuv4_initialize(gasket_dev, &setup_data); } static struct gasket_driver_desc tpuv4_driver_desc = { .driver_version = TPUV4_DRIVER_VERSION, .num_page_tables = ARRAY_SIZE(tpuv4_page_table_configs), .page_table_configs = tpuv4_page_table_configs, .bar_descriptions = { { TPUV4_LBUS_BAR_BYTES, VM_READ, TPUV4_LBUS_BAR_OFFSET, ARRAY_SIZE(lbus_bar_regions), lbus_bar_regions }, GASKET_UNUSED_BAR, { TPUV4_CSR_BAR_BYTES, VM_READ | VM_WRITE, TPUV4_CSR_BAR_OFFSET, ARRAY_SIZE(csr_bar_regions), csr_bar_regions}, GASKET_UNUSED_BAR, GASKET_UNUSED_BAR, GASKET_UNUSED_BAR, }, .legacy_interrupt_bar_index = 0, .num_msix_interrupts = TPUV4_NUM_MSIX_INTERRUPTS, .num_interrupts = ARRAY_SIZE(tpuv4_interrupts), .interrupts = tpuv4_interrupts, .legacy_interrupts = NULL, .add_dev_cb = add_dev_cb, .remove_dev_cb = tpuv4_remove_dev_cb, .enable_dev_cb = NULL, .disable_dev_cb = NULL, .sysfs_setup_cb = tpu_common_sysfs_setup, .sysfs_cleanup_cb = NULL, .device_open_cb = tpuv4_device_open_cb, .device_release_cb = NULL, .device_close_cb = tpuv4_device_close_cb, .get_mappable_regions_cb = tpuv4_get_mappable_regions_cb, .ioctl_handler_cb = NULL, .device_status_cb = tpuv4_get_status, .hardware_revision_cb = tpu_common_get_hardware_revision, .firmware_version_cb = tpu_common_get_firmware_version_cb, .device_reset_cb = tpuv4_reset, }; static void tpuv4_exit(void); static int __init tpuv4_init(void); static struct gasket_device_desc device_desc = { .name = TPU_COMMON_ACCEL_TYPE, .legacy_support = 0, .module = THIS_MODULE, .pci_id_table = tpuv4_pci_ids, .driver_desc = &tpuv4_driver_desc, }; MODULE_DESCRIPTION("Google tpu_v4 driver"); MODULE_VERSION(TPUV4_DRIVER_VERSION); MODULE_LICENSE("GPL"); MODULE_AUTHOR("asic-sw <noreply@google.com>"); MODULE_DEVICE_TABLE(pci, tpuv4_pci_ids); module_init(tpuv4_init); module_exit(tpuv4_exit); int __init tpuv4_init(void) { return gasket_register_device(&device_desc); } void tpuv4_exit(void) { gasket_unregister_device(&device_desc); }
b2ea174cea0ef6721cf549a8f43860479d3de64c
d61b532db0d3e08818338cfaac530a1ced1ffe3b
/util/LLgen/src/cclass.c
dfd7c7d5367a77c8b04a7cc2d1c65159f60414fb
[ "LicenseRef-scancode-other-permissive" ]
permissive
davidgiven/ack
61049c7a8e95ff61a77b1edd3c22bb290720e276
db5a32c68c4a60ca26a3927a799ea662b5b2b0e5
refs/heads/default
2023-08-29T07:33:12.771205
2023-07-08T20:17:27
2023-07-08T20:17:27
37,686,316
376
74
NOASSERTION
2023-07-08T20:17:28
2015-06-18T21:33:42
C
UTF-8
C
false
false
2,354
c
cclass.c
/* Copyright (c) 1991 by the Vrije Universiteit, Amsterdam, the Netherlands. * For full copyright and restrictions on use see the file COPYING in the top * level of the LLgen tree. */ /* $Id$ */ #include "cclass.h" char c_class[] = { 0, /* 00 */ 0, /* 01 */ 0, /* 02 */ 0, /* 03 */ 0, /* 04 */ 0, /* 05 */ 0, /* 06 */ 0, /* 07 */ 0, /* 010 */ ISSPA, /* 011 */ ISSPA, /* 012 */ 0, /* 013 */ ISSPA, /* 014 */ ISSPA, /* 015 */ 0, /* 016 */ 0, /* 017 */ 0, /* 020 */ 0, /* 021 */ 0, /* 022 */ 0, /* 023 */ 0, /* 024 */ 0, /* 025 */ 0, /* 026 */ 0, /* 027 */ 0, /* 030 */ 0, /* 031 */ 0, /* 032 */ 0, /* 033 */ 0, /* 034 */ 0, /* 035 */ 0, /* 036 */ 0, /* 037 */ ISSPA, /* ' ' */ 0, /* '!' */ 0, /* '"' */ 0, /* '#' */ 0, /* '$' */ ISKEY, /* '%' */ 0, /* '&' */ ISLIT, /* ''' */ ISACT, /* '(' */ 0, /* ')' */ ISTOK, /* '*' */ ISTOK, /* '+' */ ISTOK, /* ',' */ 0, /* '-' */ 0, /* '.' */ ISCOM, /* '/' */ ISDIG, /* '0' */ ISDIG, /* '1' */ ISDIG, /* '2' */ ISDIG, /* '3' */ ISDIG, /* '4' */ ISDIG, /* '5' */ ISDIG, /* '6' */ ISDIG, /* '7' */ ISDIG, /* '8' */ ISDIG, /* '9' */ ISTOK, /* ':' */ ISTOK, /* ';' */ 0, /* '<' */ 0, /* '=' */ 0, /* '>' */ ISTOK, /* '?' */ 0, /* '@' */ ISLET, /* 'A' */ ISLET, /* 'B' */ ISLET, /* 'C' */ ISLET, /* 'D' */ ISLET, /* 'E' */ ISLET, /* 'F' */ ISLET, /* 'G' */ ISLET, /* 'H' */ ISLET, /* 'I' */ ISLET, /* 'J' */ ISLET, /* 'K' */ ISLET, /* 'L' */ ISLET, /* 'M' */ ISLET, /* 'N' */ ISLET, /* 'O' */ ISLET, /* 'P' */ ISLET, /* 'Q' */ ISLET, /* 'R' */ ISLET, /* 'S' */ ISLET, /* 'T' */ ISLET, /* 'U' */ ISLET, /* 'V' */ ISLET, /* 'W' */ ISLET, /* 'X' */ ISLET, /* 'Y' */ ISLET, /* 'Z' */ ISTOK, /* '[' */ 0, /* '\' */ ISTOK, /* ']' */ 0, /* '^' */ ISLET, /* '_' */ 0, /* '`' */ ISLET, /* 'a' */ ISLET, /* 'b' */ ISLET, /* 'c' */ ISLET, /* 'd' */ ISLET, /* 'e' */ ISLET, /* 'f' */ ISLET, /* 'g' */ ISLET, /* 'h' */ ISLET, /* 'i' */ ISLET, /* 'j' */ ISLET, /* 'k' */ ISLET, /* 'l' */ ISLET, /* 'm' */ ISLET, /* 'n' */ ISLET, /* 'o' */ ISLET, /* 'p' */ ISLET, /* 'q' */ ISLET, /* 'r' */ ISLET, /* 's' */ ISLET, /* 't' */ ISLET, /* 'u' */ ISLET, /* 'v' */ ISLET, /* 'w' */ ISLET, /* 'x' */ ISLET, /* 'y' */ ISLET, /* 'z' */ ISACT, /* '{' */ ISTOK, /* '|' */ 0, /* '}' */ 0, /* '~' */ 0 /* 0177 */ };
d9d3f818b67f056780263eb1806e20e70f61ca12
bf9f350094a6bd4c4a5ddba22fa3671cf987d82e
/code_benches/mi_rsynth/aufile.c
843ffc6b51ef72d06711a1bd829c3b8dda1d74ec
[ "BSD-3-Clause" ]
permissive
gwsystems/aWsm
e16759a1d7d899660d07e83026b4c0f5a5d414d8
69c8b6116664d65a851cc459601bef6af3caeaea
refs/heads/master
2023-08-27T11:21:34.680919
2022-09-22T18:05:20
2022-09-22T18:05:20
139,072,240
248
21
BSD-3-Clause
2022-09-14T23:20:31
2018-06-28T21:58:42
C
UTF-8
C
false
false
4,307
c
aufile.c
#include <config.h> #include "proto.h" #include <stdio.h> #include <fcntl.h> #include <useconfig.h> #include "getargs.h" #include "l2u.h" #include "hplay.h" #include "file.h" #define SUN_MAGIC 0x2e736e64 /* Really '.snd' */ #define SUN_HDRSIZE 24 /* Size of minimal header */ #define SUN_UNSPEC ((unsigned)(~0)) /* Unspecified data size */ #define SUN_ULAW 1 /* u-law encoding */ #define SUN_LIN_8 2 /* Linear 8 bits */ #define SUN_LIN_16 3 /* Linear 16 bits */ file_write_p file_write = NULL; file_term_p file_term = NULL; static char *linear_file; static char *au_file; static int au_fd = -1; /* file descriptor for .au ulaw file */ static int linear_fd = -1; static unsigned au_encoding = SUN_ULAW; static unsigned au_size = 0; static void wblong PROTO((int fd, unsigned long x)); static void wblong(fd, x) int fd; unsigned long x; { int i; for (i = 24; i >= 0; i -= 8) { char byte = (char) ((x >> i) & 0xFF); write(fd, &byte, 1); } } extern void au_header PROTO((int fd,unsigned enc,unsigned rate,unsigned size,char *comment)); void au_header(fd, enc, rate, size, comment) int fd; unsigned enc; unsigned rate; unsigned size; char *comment; { if (!comment) comment = ""; wblong(fd, SUN_MAGIC); wblong(fd, SUN_HDRSIZE + strlen(comment)); wblong(fd, size); wblong(fd, enc); wblong(fd, rate); wblong(fd, 1); /* channels */ write(fd, comment, strlen(comment)); } static void aufile_write PROTO((int n,short *data)); static void aufile_write(n, data) int n; short *data; { if (n > 0) { if (linear_fd >= 0) { unsigned size = n * sizeof(short); if (write(linear_fd, data, n * sizeof(short)) != size) perror("write"); } if (au_fd >= 0) { if (au_encoding == SUN_LIN_16) { unsigned size = n * sizeof(short); if (write(au_fd, data, size) != size) perror("write"); else au_size += size; } else if (au_encoding == SUN_ULAW) { unsigned char *plabuf = (unsigned char *) malloc(n); if (plabuf) { unsigned char *p = plabuf; unsigned char *e = p + n; while (p < e) { *p++ = short2ulaw(*data++); } if (write(au_fd, plabuf, n) != n) perror(au_file); else au_size += n; free(plabuf); } else { fprintf(stderr, "%s : No memory for ulaw data\n", program); } } else { abort(); } } } } static void aufile_term PROTO((void)); static void aufile_term() { /* Finish ulaw file */ if (au_fd >= 0) { off_t here = lseek(au_fd, 0L, SEEK_CUR); if (here >= 0) { /* can seek this file - truncate it */ ftruncate(au_fd, here); /* Now go back and overwite header with actual size */ if (lseek(au_fd, 8L, SEEK_SET) == 8) { wblong(au_fd, au_size); } } if (au_fd != 1) close(au_fd); au_fd = -1; } /* Finish linear file */ if (linear_fd >= 0) { ftruncate(linear_fd, lseek(linear_fd, 0L, SEEK_CUR)); if (linear_fd != 1) close(linear_fd); linear_fd = -1; } } int file_init(argc, argv) int argc; char *argv[]; { argc = getargs("File output", argc, argv, "l", "", &linear_file, "Raw 16-bit linear pathname", "o", "", &au_file, "Sun/Next audio file name", NULL); if (help_only) return argc; if (au_file) { if (strcmp(au_file, "-") == 0) { au_fd = 1; /* stdout */ } else { au_fd = open(au_file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (au_fd < 0) perror(au_file); } if (au_fd >= 0) { if (samp_rate > 8000) au_encoding = SUN_LIN_16; else au_encoding = SUN_ULAW; au_header(au_fd, au_encoding, samp_rate, SUN_UNSPEC, ""); au_size = 0; } } if (linear_file) { if (strcmp(linear_file, "-") == 0) { linear_fd = 1 /* stdout */ ; } else { linear_fd = open(linear_file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (linear_fd < 0) perror(linear_file); } } if (au_fd >= 0 || linear_fd >= 0) { file_write = aufile_write; file_term = aufile_term; } return argc; }
4c6f2662ddb842f378d29630daf92084e6f00de6
c6759b857e55991fea3ef0b465dbcee53fa38714
/gap8/rtos/pulp/pulp-os/kernel/utils.c
c830dd39c77be7fa59e60be56967446adc298b2f
[ "Apache-2.0" ]
permissive
GreenWaves-Technologies/gap_sdk
1b343bba97b7a5ce62a24162bd72eef5cc67e269
3fea306d52ee33f923f2423c5a75d9eb1c07e904
refs/heads/master
2023-09-01T14:38:34.270427
2023-08-10T09:04:44
2023-08-10T09:04:44
133,324,605
145
96
Apache-2.0
2023-08-27T19:03:52
2018-05-14T07:50:29
C
UTF-8
C
false
false
4,937
c
utils.c
/* * Copyright (C) 2018 ETH Zurich and University of Bologna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* * Authors: Germain Haugou, ETH (germain.haugou@iis.ee.ethz.ch) */ #include "rt/rt_api.h" typedef struct rt_cbsys_s { int (*callback)(void *); void *arg; struct rt_cbsys_s *next; } rt_cbsys_t; RT_FC_DATA static rt_cbsys_t *cbsys_first[RT_CBSYS_NB]; void __rt_cbsys_del(__rt_cbsys_e cbsys_id, int (*cb)(void *), void *cb_arg) { rt_cbsys_t *cbsys = cbsys_first[cbsys_id]; rt_cbsys_t *prev = NULL; while(cbsys) { if (cbsys->callback == cb && cbsys->arg == cb_arg) { if (prev) { prev->next = cbsys->next; } else { cbsys_first[cbsys_id] = cbsys->next; } rt_free(RT_ALLOC_FC_RET_DATA, (void *)cbsys, sizeof(rt_cbsys_t)); return; } prev = cbsys; cbsys = cbsys->next; } } int __rt_cbsys_add(__rt_cbsys_e cbsys_id, int (*cb)(void *), void *cb_arg) { rt_cbsys_t *cbsys = (rt_cbsys_t *)rt_alloc(RT_ALLOC_FC_RET_DATA, sizeof(rt_cbsys_t)); if (cbsys == NULL) return -1; cbsys->callback = cb; cbsys->arg = cb_arg; cbsys->next = cbsys_first[cbsys_id]; cbsys_first[cbsys_id] = cbsys; return 0; } int __rt_cbsys_exec(__rt_cbsys_e cbsys_id) { rt_cbsys_t *cbsys = cbsys_first[cbsys_id]; while (cbsys) { if (cbsys->callback(cbsys->arg)) return -1; cbsys = cbsys->next; } return 0; } RT_FC_BOOT_CODE void __rt_utils_init() { for (int i=0; i<RT_CBSYS_NB; i++) { cbsys_first[i] = NULL; } } void __rt_fc_lock(rt_fc_lock_t *lock) { #if defined(ARCHI_HAS_FC) int irq = rt_irq_disable(); while(lock->locked) { //lock->fc_wait = __rt_thread_current; __rt_event_execute(rt_event_internal_sched(), 1); } lock->locked = 1; rt_irq_restore(irq); #else while (rt_tas_lock_32((uint32_t)&lock->lock) == -1) { } #endif } static int __rt_fc_unlock_to_cluster(rt_fc_lock_t *lock) { #if defined(ARCHI_HAS_CLUSTER) if (lock->waiting) { rt_fc_lock_req_t *req = lock->waiting; lock->waiting = req->next; rt_compiler_barrier(); req->done = 1; __rt_cluster_notif_req_done(req->cid); return 1; } #else #endif return 0; } void __rt_fc_unlock(rt_fc_lock_t *lock) { #if defined(ARCHI_HAS_FC) int irq = rt_irq_disable(); if (!__rt_fc_unlock_to_cluster(lock)) { lock->locked = 0; } rt_irq_restore(irq); #else rt_tas_unlock_32((uint32_t)&lock->lock, 0); #endif } #if defined(ARCHI_HAS_CLUSTER) static void __rt_fc_cluster_lock_req(void *_req) { int irq = rt_irq_disable(); rt_fc_lock_req_t *req = (rt_fc_lock_req_t *)_req; rt_fc_lock_t *lock = req->lock; if (req->req_lock) { // Request is a lock if (lock->locked) { // The lock is already taken, just register ourself in the wait list // and return if (lock->waiting) lock->last_waiting->next = req; else lock->waiting = req; lock->last_waiting = req; req->next = NULL; } else { rt_compiler_barrier(); // The lock is not taken, take it and reply to the cluster req->done = 1; lock->locked = 1; __rt_cluster_notif_req_done(req->cid); } } else { // Request is an unlock, first check if we can give it to a cluster if (__rt_fc_unlock_to_cluster(lock)) { } else { lock->locked = 0; } rt_compiler_barrier(); req->done = 1; __rt_cluster_notif_req_done(req->cid); } rt_irq_restore(irq); } #if defined(ARCHI_HAS_FC) void __rt_fc_cluster_lock(rt_fc_lock_t *lock, rt_fc_lock_req_t *req) { req->lock = lock; req->cid = rt_cluster_id(); req->done = 0; req->req_lock = 1; __rt_init_event(&req->event, __rt_cluster_sched_get(), __rt_fc_cluster_lock_req, (void *)req); __rt_cluster_push_fc_irq_event(&req->event); } void __rt_fc_cluster_unlock(rt_fc_lock_t *lock, rt_fc_lock_req_t *req) { req->lock = lock; req->cid = rt_cluster_id(); req->done = 0; req->req_lock = 0; __rt_init_event(&req->event, __rt_cluster_sched_get(), __rt_fc_cluster_lock_req, (void *)req); __rt_cluster_push_fc_irq_event(&req->event); } #else void __rt_fc_cluster_lock(rt_fc_lock_t *lock, rt_fc_lock_req_t *req) { while (rt_tas_lock_32((uint32_t)&lock->lock) == -1) { } } void __rt_fc_cluster_unlock(rt_fc_lock_t *lock, rt_fc_lock_req_t *req) { rt_tas_unlock_32((uint32_t)&lock->lock, 0); } #endif #endif
9c19a01efa803810a92d638c98bec186632f72a1
8a51a96f61699f0318315ccc89cef39f6866f2b5
/src/include/utils/snapshot.h
583a667a40ab51756c83451a5aff2df471c9b091
[ "PostgreSQL" ]
permissive
postgres/postgres
979febf2b41c00090d1256228f768f33e7ef3b6f
b5934bfd6071fed3a38cea0cfaa93afda63d9c0c
refs/heads/master
2023-08-31T00:10:01.373472
2023-08-30T23:07:48
2023-08-30T23:07:48
927,442
13,691
4,807
NOASSERTION
2023-09-09T13:59:15
2010-09-21T11:35:45
C
UTF-8
C
false
false
8,021
h
snapshot.h
/*------------------------------------------------------------------------- * * snapshot.h * POSTGRES snapshot definition * * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * src/include/utils/snapshot.h * *------------------------------------------------------------------------- */ #ifndef SNAPSHOT_H #define SNAPSHOT_H #include "access/htup.h" #include "access/xlogdefs.h" #include "datatype/timestamp.h" #include "lib/pairingheap.h" #include "storage/buf.h" /* * The different snapshot types. We use SnapshotData structures to represent * both "regular" (MVCC) snapshots and "special" snapshots that have non-MVCC * semantics. The specific semantics of a snapshot are encoded by its type. * * The behaviour of each type of snapshot should be documented alongside its * enum value, best in terms that are not specific to an individual table AM. * * The reason the snapshot type rather than a callback as it used to be is * that that allows to use the same snapshot for different table AMs without * having one callback per AM. */ typedef enum SnapshotType { /*------------------------------------------------------------------------- * A tuple is visible iff the tuple is valid for the given MVCC snapshot. * * Here, we consider the effects of: * - all transactions committed as of the time of the given snapshot * - previous commands of this transaction * * Does _not_ include: * - transactions shown as in-progress by the snapshot * - transactions started after the snapshot was taken * - changes made by the current command * ------------------------------------------------------------------------- */ SNAPSHOT_MVCC = 0, /*------------------------------------------------------------------------- * A tuple is visible iff the tuple is valid "for itself". * * Here, we consider the effects of: * - all committed transactions (as of the current instant) * - previous commands of this transaction * - changes made by the current command * * Does _not_ include: * - in-progress transactions (as of the current instant) * ------------------------------------------------------------------------- */ SNAPSHOT_SELF, /* * Any tuple is visible. */ SNAPSHOT_ANY, /* * A tuple is visible iff the tuple is valid as a TOAST row. */ SNAPSHOT_TOAST, /*------------------------------------------------------------------------- * A tuple is visible iff the tuple is valid including effects of open * transactions. * * Here, we consider the effects of: * - all committed and in-progress transactions (as of the current instant) * - previous commands of this transaction * - changes made by the current command * * This is essentially like SNAPSHOT_SELF as far as effects of the current * transaction and committed/aborted xacts are concerned. However, it * also includes the effects of other xacts still in progress. * * A special hack is that when a snapshot of this type is used to * determine tuple visibility, the passed-in snapshot struct is used as an * output argument to return the xids of concurrent xacts that affected * the tuple. snapshot->xmin is set to the tuple's xmin if that is * another transaction that's still in progress; or to * InvalidTransactionId if the tuple's xmin is committed good, committed * dead, or my own xact. Similarly for snapshot->xmax and the tuple's * xmax. If the tuple was inserted speculatively, meaning that the * inserter might still back down on the insertion without aborting the * whole transaction, the associated token is also returned in * snapshot->speculativeToken. See also InitDirtySnapshot(). * ------------------------------------------------------------------------- */ SNAPSHOT_DIRTY, /* * A tuple is visible iff it follows the rules of SNAPSHOT_MVCC, but * supports being called in timetravel context (for decoding catalog * contents in the context of logical decoding). */ SNAPSHOT_HISTORIC_MVCC, /* * A tuple is visible iff the tuple might be visible to some transaction; * false if it's surely dead to everyone, i.e., vacuumable. * * For visibility checks snapshot->min must have been set up with the xmin * horizon to use. */ SNAPSHOT_NON_VACUUMABLE } SnapshotType; typedef struct SnapshotData *Snapshot; #define InvalidSnapshot ((Snapshot) NULL) /* * Struct representing all kind of possible snapshots. * * There are several different kinds of snapshots: * * Normal MVCC snapshots * * MVCC snapshots taken during recovery (in Hot-Standby mode) * * Historic MVCC snapshots used during logical decoding * * snapshots passed to HeapTupleSatisfiesDirty() * * snapshots passed to HeapTupleSatisfiesNonVacuumable() * * snapshots used for SatisfiesAny, Toast, Self where no members are * accessed. * * TODO: It's probably a good idea to split this struct using a NodeTag * similar to how parser and executor nodes are handled, with one type for * each different kind of snapshot to avoid overloading the meaning of * individual fields. */ typedef struct SnapshotData { SnapshotType snapshot_type; /* type of snapshot */ /* * The remaining fields are used only for MVCC snapshots, and are normally * just zeroes in special snapshots. (But xmin and xmax are used * specially by HeapTupleSatisfiesDirty, and xmin is used specially by * HeapTupleSatisfiesNonVacuumable.) * * An MVCC snapshot can never see the effects of XIDs >= xmax. It can see * the effects of all older XIDs except those listed in the snapshot. xmin * is stored as an optimization to avoid needing to search the XID arrays * for most tuples. */ TransactionId xmin; /* all XID < xmin are visible to me */ TransactionId xmax; /* all XID >= xmax are invisible to me */ /* * For normal MVCC snapshot this contains the all xact IDs that are in * progress, unless the snapshot was taken during recovery in which case * it's empty. For historic MVCC snapshots, the meaning is inverted, i.e. * it contains *committed* transactions between xmin and xmax. * * note: all ids in xip[] satisfy xmin <= xip[i] < xmax */ TransactionId *xip; uint32 xcnt; /* # of xact ids in xip[] */ /* * For non-historic MVCC snapshots, this contains subxact IDs that are in * progress (and other transactions that are in progress if taken during * recovery). For historic snapshot it contains *all* xids assigned to the * replayed transaction, including the toplevel xid. * * note: all ids in subxip[] are >= xmin, but we don't bother filtering * out any that are >= xmax */ TransactionId *subxip; int32 subxcnt; /* # of xact ids in subxip[] */ bool suboverflowed; /* has the subxip array overflowed? */ bool takenDuringRecovery; /* recovery-shaped snapshot? */ bool copied; /* false if it's a static snapshot */ CommandId curcid; /* in my xact, CID < curcid are visible */ /* * An extra return value for HeapTupleSatisfiesDirty, not used in MVCC * snapshots. */ uint32 speculativeToken; /* * For SNAPSHOT_NON_VACUUMABLE (and hopefully more in the future) this is * used to determine whether row could be vacuumed. */ struct GlobalVisState *vistest; /* * Book-keeping information, used by the snapshot manager */ uint32 active_count; /* refcount on ActiveSnapshot stack */ uint32 regd_count; /* refcount on RegisteredSnapshots */ pairingheap_node ph_node; /* link in the RegisteredSnapshots heap */ TimestampTz whenTaken; /* timestamp when snapshot was taken */ XLogRecPtr lsn; /* position in the WAL stream when taken */ /* * The transaction completion count at the time GetSnapshotData() built * this snapshot. Allows to avoid re-computing static snapshots when no * transactions completed since the last GetSnapshotData(). */ uint64 snapXactCompletionCount; } SnapshotData; #endif /* SNAPSHOT_H */
db2a27dd218a5ee96226365e957a4e27fedc49b6
7c857119fe1505b1d80d6e62969661c06dc1a2f4
/MdePkg/Include/Library/ResourcePublicationLib.h
aa51b6ae1e0dfe6348fb5b1198e44e39e8fd41a4
[ "BSD-2-Clause" ]
permissive
CloverHackyColor/CloverBootloader
7042ca7dd6b513d22be591a295e49071ae1482ee
2711170df4f60b2ae5aa20add3e00f35cf57b7e5
refs/heads/master
2023-08-30T22:14:34.590134
2023-08-27T19:14:02
2023-08-27T19:14:02
205,810,121
4,734
770
BSD-2-Clause
2023-09-03T12:41:33
2019-09-02T08:22:14
C
UTF-8
C
false
false
1,259
h
ResourcePublicationLib.h
/** @file Provides a service to publish discovered system resources. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ #ifndef __RESOURCE_PUBLICATION_LIB__ #define __RESOURCE_PUBLICATION_LIB__ /** Declares the presence of permanent system memory in the platform. Declares that the system memory buffer specified by MemoryBegin and MemoryLength as permanent memory that may be used for general purpose use by software. The amount of memory available to software may be less than MemoryLength if published memory has alignment restrictions. If MemoryLength is 0, then ASSERT(). If MemoryLength is greater than (MAX_ADDRESS - MemoryBegin + 1), then ASSERT(). @param MemoryBegin The start address of the memory being declared. @param MemoryLength The number of bytes of memory being declared. @retval RETURN_SUCCESS The memory buffer was published. @retval RETURN_OUT_OF_RESOURCES There are not enough resources to publish the memory buffer **/ RETURN_STATUS EFIAPI PublishSystemMemory ( IN PHYSICAL_ADDRESS MemoryBegin, IN UINT64 MemoryLength ); #endif
75c49378539b02f7a6522c3d2d4f074e7a80f192
9f14c14c5a99cd79a917658e36db4232d1a41405
/compiler/test/runnable/test23347.c
d213a2b225e0d713406c08f3129ec628aa53d449
[ "BSL-1.0" ]
permissive
dlang/dmd
643941ef957949ec1bc62d8e431406afd64375b8
25d2741b86b1060ec43d80dbcc8dc190d5453322
refs/heads/master
2023-08-31T03:02:46.324487
2023-08-20T17:02:46
2023-08-30T09:27:23
1,257,070
2,074
486
BSL-1.0
2023-09-14T20:55:15
2011-01-15T06:53:53
D
UTF-8
C
false
false
244
c
test23347.c
/* DISABLED: osx32 osx64 win32 win64 * TEST_OUTPUT: --- --- */ // https://issues.dlang.org/show_bug.cgi?id=23347 void fork() { } #pragma pack(push, 4) void spoon() asm("fork"); #pragma pack(pop); int main() { spoon(); return 0; }
b9b3e8bd537fbe641a6f263f5d1a3b23bde27ca8
38bd1cf9e52ea23b43223d53d8139aad52bb1c70
/cpp/webdriver-interactions/translate_keycode_linux.h
6bee273a85e35c082151276ab4cfa35fd53f1d3e
[ "Apache-2.0" ]
permissive
SeleniumHQ/selenium
46d9553e3a45412a7540dd3f7d1f34be6ef42b1b
cc41a883b5138962c6b4408a0fdf4e932bd08071
refs/heads/trunk
2023-09-03T22:56:56.403484
2023-09-02T19:20:45
2023-09-02T19:20:45
7,613,257
30,383
9,671
Apache-2.0
2023-09-14T18:47:42
2013-01-14T21:40:56
Java
UTF-8
C
false
false
270
h
translate_keycode_linux.h
// Copyright 2009 Google Inc. All Rights Reserved. // Author: eranm@google.com (Eran Messeri) // // #ifndef _TRANSLATE_KEYCODE_LINUX_H #define _TRANSLATE_KEYCODE_LINUX_H guint translate_code_to_gdk_symbol(const wchar_t key_code); extern const wchar_t gNullKey; #endif
e780c392f2dcebd0a41f1bc3d87fe6bfc812d3fb
02f0a0e7da0b494f80af64b7e144bfd25e6d8703
/Pods/Headers/Public/VTMagic/UIViewController+VTMagic.h
601fd58bd613a81ac8c423924a06eef7673838b7
[ "MIT" ]
permissive
QuintGao/GKPageScrollView
f3e3160a83d020e0c7f4617c01395b2b7573fd41
189fee6672daae0c13359fb9e322836dc1ad00a9
refs/heads/master
2023-08-09T20:38:02.105512
2023-08-03T08:06:09
2023-08-03T08:06:09
155,068,255
1,547
285
MIT
2022-12-07T03:46:22
2018-10-28T12:23:55
Objective-C
UTF-8
C
false
false
51
h
UIViewController+VTMagic.h
../../../VTMagic/VTMagic/UIViewController+VTMagic.h
19747650e629219d5b4d49999d8c4e5bf7491b6a
6223530200223fd0add9a081a25cb6daf3a8d3c3
/src/preprocess/btorelimapplies.c
f56b5dd8d9c08f79e4cd54a20c2fd8568994e711
[ "MIT", "LicenseRef-scancode-dco-1.1" ]
permissive
Boolector/boolector
959aec7715c3122763f803733f0af4f6124801d9
13a8a06d561041cafcaf5458e404c1ec354b2841
refs/heads/master
2023-06-08T03:52:44.634825
2023-01-10T22:48:06
2023-01-10T22:48:06
134,006,909
280
58
NOASSERTION
2023-09-11T23:31:41
2018-05-18T21:44:21
SMT
UTF-8
C
false
false
5,227
c
btorelimapplies.c
/* Boolector: Satisfiability Modulo Theories (SMT) solver. * * Copyright (C) 2007-2021 by the authors listed in the AUTHORS file. * * This file is part of Boolector. * See COPYING for more information on using this software. */ #include "preprocess/btorelimapplies.h" #include "btorbeta.h" #include "btorcore.h" #include "btordbg.h" #include "btorlog.h" #include "btorsubst.h" #include "preprocess/btorpputils.h" #include "preprocess/btorpreprocess.h" #include "utils/btornodeiter.h" #include "utils/btorutil.h" static void eliminate_update_nodes (Btor *btor) { uint32_t i; BtorNode *cur, *subst; btor_init_substitutions (btor); for (i = 1; i < BTOR_COUNT_STACK (btor->nodes_id_table); i++) { cur = BTOR_PEEK_STACK (btor->nodes_id_table, i); if (!cur || !btor_node_is_update (cur) || btor_node_is_simplified (cur)) continue; subst = btor_exp_lambda_write (btor, cur->e[0], cur->e[1]->e[0], cur->e[2]); btor_insert_substitution (btor, cur, subst, 0); btor_node_release (btor, subst); } btor_substitute_and_rebuild (btor, btor->substitutions); btor_delete_substitutions (btor); } void btor_eliminate_applies (Btor *btor) { assert (btor); size_t i; uint32_t num_applies, num_applies_total = 0, round; double start, delta; BtorNode *app, *fun, *subst; BtorNodeIterator it; BtorNodePtrStack lambdas; BtorPtrHashTableIterator h_it; BtorPtrHashTable *cache; BtorPtrHashTable *substs; BtorIntHashTable *app_cache; if (btor_opt_get (btor, BTOR_OPT_BETA_REDUCE) == BTOR_BETA_REDUCE_ALL) { eliminate_update_nodes (btor); } if (btor->lambdas->count == 0) return; start = btor_util_time_stamp (); round = 1; cache = btor_hashptr_table_new (btor->mm, (BtorHashPtr) btor_node_pair_hash, (BtorCmpPtr) btor_node_pair_compare); app_cache = btor_hashint_table_new (btor->mm); BTOR_INIT_STACK (btor->mm, lambdas); /* NOTE: in some cases substitute_and_rebuild creates applies that can be * beta-reduced. this can happen when parameterized applies become not * parameterized. hence, we beta-reduce applies until fix point. */ do { BTORLOG (1, "start apply elimination (round %u)", round); num_applies = 0; substs = btor_hashptr_table_new (btor->mm, (BtorHashPtr) btor_node_hash_by_id, (BtorCmpPtr) btor_node_compare_by_id); btor_pputils_collect_lambdas (btor, &lambdas); /* collect function applications */ for (i = 0; i < BTOR_COUNT_STACK (lambdas); i++) { fun = BTOR_PEEK_STACK (lambdas, i); btor_iter_apply_parent_init (&it, fun); while (btor_iter_apply_parent_has_next (&it)) { app = btor_iter_apply_parent_next (&it); if (btor_node_is_simplified (app)) continue; if (btor_hashint_table_contains (app_cache, btor_node_get_id (app))) continue; /* If we have quantifiers, we always want to eliminate lambdas. */ if (btor->quantifiers->count == 0 && app->parameterized) continue; num_applies++; subst = btor_beta_reduce_full (btor, app, cache); assert (!btor_hashptr_table_get (substs, app)); btor_hashptr_table_add (substs, app)->data.as_ptr = subst; btor_hashint_table_add (app_cache, btor_node_get_id (app)); } } BTOR_RESET_STACK (lambdas); num_applies_total += num_applies; BTOR_MSG (btor->msg, 1, "eliminate %u applications in round %u", num_applies, round); btor_substitute_and_rebuild (btor, substs); btor_iter_hashptr_init (&h_it, substs); while (btor_iter_hashptr_has_next (&h_it)) { btor_node_release (btor, btor_iter_hashptr_next_data (&h_it)->as_ptr); } btor_hashptr_table_delete (substs); BTORLOG (1, "end apply elimination (round %u)", round); round++; } while (num_applies > 0); btor_hashint_table_delete (app_cache); btor_iter_hashptr_init (&h_it, cache); while (btor_iter_hashptr_has_next (&h_it)) { btor_node_release (btor, h_it.bucket->data.as_ptr); btor_node_pair_delete (btor, btor_iter_hashptr_next (&h_it)); } btor_hashptr_table_delete (cache); #ifndef NDEBUG BTOR_RESET_STACK (lambdas); btor_pputils_collect_lambdas (btor, &lambdas); for (i = 0; i < BTOR_COUNT_STACK (lambdas); i++) { fun = BTOR_PEEK_STACK (lambdas, i); btor_iter_apply_parent_init (&it, fun); while (btor_iter_apply_parent_has_next (&it)) { app = btor_iter_apply_parent_next (&it); assert (app->parameterized || btor_opt_get (btor, BTOR_OPT_NONDESTR_SUBST)); } } #endif BTOR_RELEASE_STACK (lambdas); delta = btor_util_time_stamp () - start; btor->time.elimapplies += delta; BTOR_MSG (btor->msg, 1, "eliminated %d function applications in %.1f seconds", num_applies_total, delta); assert (btor_dbg_check_all_hash_tables_proxy_free (btor)); assert (btor_dbg_check_all_hash_tables_simp_free (btor)); assert (btor_dbg_check_unique_table_children_proxy_free (btor)); }
e7578d360865a55759be45725585059d787f49a1
03666e5f961946fc1a0ac67781ac1425562ef0d7
/src/databases/Enzo/avtEnzoFileFormat.C
d096d8f70ea3befe879c3fd1a1d42e03e0fa499e
[ "BSD-3-Clause", "LicenseRef-scancode-unknown-license-reference" ]
permissive
visit-dav/visit
e9f81b4d4b9b9930a0db9d5282cd1bcabf465e2e
601ae46e0bef2e18425b482a755d03490ade0493
refs/heads/develop
2023-09-06T08:19:38.397058
2023-09-05T21:29:32
2023-09-05T21:29:32
165,565,988
335
120
BSD-3-Clause
2023-09-14T00:53:37
2019-01-13T23:27:26
C
UTF-8
C
false
false
59,956
c
avtEnzoFileFormat.C
// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt // Project developers. See the top-level LICENSE file for dates and other // details. No copyright assignment is required to contribute to VisIt. // ************************************************************************* // // avtEnzoFileFormat.C // // ************************************************************************* // #include <avtEnzoFileFormat.h> #include <visit-config.h> #include <string> #include <vector> #include <vtkFloatArray.h> #include <vtkRectilinearGrid.h> #include <vtkUnstructuredGrid.h> #include <vtkDataSetWriter.h> #include <vtkCellType.h> #include <avtDatabase.h> #include <avtDatabaseMetaData.h> #include <avtStructuredDomainBoundaries.h> #include <avtStructuredDomainNesting.h> #include <avtVariableCache.h> #include <avtIntervalTree.h> #include <avtResolutionSelection.h> #include <InvalidVariableException.h> #include <InvalidFilesException.h> #include <Expression.h> #include <DebugStream.h> #include <FileFunctions.h> // Define this symbol BEFORE including hdf5.h to indicate the HDF5 code // in this file uses version 1.6 of the HDF5 API. This is harmless for // versions of HDF5 before 1.8 and ensures correct compilation with // version 1.8 and thereafter. When, and if, the HDF5 code in this file // is explicitly upgraded to the 1.8 API, this symbol should be removed. #define H5_USE_16_API #include <hdf5.h> #include <visit-hdf5.h> using std::string; using std::vector; void avtEnzoFileFormat::Grid::PrintRecursive(vector<Grid> &grids, int level) { string indent(level*3, ' '); cerr << indent << ID << endl; for (size_t i=0; i<childrenID.size(); i++) { grids[childrenID[i]].PrintRecursive(grids,level+1); } } void avtEnzoFileFormat::Grid::Print() { cerr << "ID: "<<ID<<endl; cerr << "zdims: "<<zdims[0]<<","<<zdims[1]<<","<<zdims[2]<<endl; cerr << "minSpatialExtents:"<<minSpatialExtents[0]<<","<<minSpatialExtents[1]<<","<<minSpatialExtents[2]<<endl; cerr << "maxSpatialExtents:"<<maxSpatialExtents[0]<<","<<maxSpatialExtents[1]<<","<<maxSpatialExtents[2]<<endl; cerr << "parentID: "<<parentID<<endl; cerr << "level: "<<level<<endl; cerr << "parMinExt: "<<minLogicalExtentsInParent[0]<<","<<minLogicalExtentsInParent[1]<<","<<minLogicalExtentsInParent[2]<<endl; cerr << "parMaxExt: "<<maxLogicalExtentsInParent[0]<<","<<maxLogicalExtentsInParent[1]<<","<<maxLogicalExtentsInParent[2]<<endl; cerr << "globMinExt:"<<minLogicalExtentsGlobally[0]<<","<<minLogicalExtentsGlobally[1]<<","<<minLogicalExtentsGlobally[2]<<endl; cerr << "globMaxExt:"<<maxLogicalExtentsGlobally[0]<<","<<maxLogicalExtentsGlobally[1]<<","<<maxLogicalExtentsGlobally[2]<<endl; cerr << "parRatio: "<<refinementRatio[0]<<","<<refinementRatio[1]<<","<<refinementRatio[2]<<endl; cerr << "gridFileName:"<<gridFileName<<endl; cerr << "particleFileName:"<<particleFileName<<endl; cerr << endl; } // **************************************************************************** // Method: avtEnzoFileFormat::Grid::DetermineExtentsInParent // // Purpose: // Use our spatial extents and the spatial extents of our parent, as well // as our dimensions, to determine our logical extents within our parent. // // Programmer: Jeremy Meredith // Creation: January 3, 2005 // // Modifications: // Jeremy Meredith, Wed Feb 23 15:18:48 PST 2005 // May have multiple root grids; identify by parentID==0, not by ID==1. // // Jeremy Meredith, Wed Aug 3 10:22:36 PDT 2005 // Added support for 2D files. // // Jeremy Meredith, Thu Aug 11 14:35:00 PDT 2005 // Fixed logical extents when there are multiple root grids. // // Eric Brugger, Tue Oct 17 09:49:26 PDT 2006 // Removed coding to throw an exception if a non 2:1 refinement ratio // was encountered. // // **************************************************************************** void avtEnzoFileFormat::Grid::DetermineExtentsInParent(vector<Grid> &grids) { if (parentID != 0) { Grid &p = grids[parentID]; minLogicalExtentsInParent[0] = int(.5 + double(p.zdims[0]) * (minSpatialExtents[0] - p.minSpatialExtents[0])/(p.maxSpatialExtents[0] - p.minSpatialExtents[0])); maxLogicalExtentsInParent[0] = int(.5 + double(p.zdims[0]) * (maxSpatialExtents[0] - p.minSpatialExtents[0])/(p.maxSpatialExtents[0] - p.minSpatialExtents[0])); minLogicalExtentsInParent[1] = int(.5 + double(p.zdims[1]) * (minSpatialExtents[1] - p.minSpatialExtents[1])/(p.maxSpatialExtents[1] - p.minSpatialExtents[1])); maxLogicalExtentsInParent[1] = int(.5 + double(p.zdims[1]) * (maxSpatialExtents[1] - p.minSpatialExtents[1])/(p.maxSpatialExtents[1] - p.minSpatialExtents[1])); if (dimension == 3) { minLogicalExtentsInParent[2] = int(.5 + double(p.zdims[2]) * (minSpatialExtents[2] - p.minSpatialExtents[2])/(p.maxSpatialExtents[2] - p.minSpatialExtents[2])); maxLogicalExtentsInParent[2] = int(.5 + double(p.zdims[2]) * (maxSpatialExtents[2] - p.minSpatialExtents[2])/(p.maxSpatialExtents[2] - p.minSpatialExtents[2])); } else { minLogicalExtentsInParent[2] = 0; maxLogicalExtentsInParent[2] = 0; } refinementRatio[0] = double(zdims[0]) / double(maxLogicalExtentsInParent[0]-minLogicalExtentsInParent[0]); refinementRatio[1] = double(zdims[1]) / double(maxLogicalExtentsInParent[1]-minLogicalExtentsInParent[1]); if (dimension == 3) refinementRatio[2] = double(zdims[2]) / double(maxLogicalExtentsInParent[2]-minLogicalExtentsInParent[2]); else refinementRatio[2] = 1; } else { Grid &p = grids[0]; double xpct = (maxSpatialExtents[0] - minSpatialExtents[0])/(p.maxSpatialExtents[0] - p.minSpatialExtents[0]); minLogicalExtentsInParent[0] = int(.5 + (double(zdims[0])/xpct) * (minSpatialExtents[0] - p.minSpatialExtents[0])/(p.maxSpatialExtents[0] - p.minSpatialExtents[0])); maxLogicalExtentsInParent[0] = int(.5 + (double(zdims[0])/xpct) * (maxSpatialExtents[0] - p.minSpatialExtents[0])/(p.maxSpatialExtents[0] - p.minSpatialExtents[0])); double ypct = (maxSpatialExtents[1] - minSpatialExtents[1])/(p.maxSpatialExtents[1] - p.minSpatialExtents[1]); minLogicalExtentsInParent[1] = int(.5 + (double(zdims[1])/ypct) * (minSpatialExtents[1] - p.minSpatialExtents[1])/(p.maxSpatialExtents[1] - p.minSpatialExtents[1])); maxLogicalExtentsInParent[1] = int(.5 + (double(zdims[1])/ypct) * (maxSpatialExtents[1] - p.minSpatialExtents[1])/(p.maxSpatialExtents[1] - p.minSpatialExtents[1])); if (dimension == 3) { double zpct = (maxSpatialExtents[2] - minSpatialExtents[2])/(p.maxSpatialExtents[2] - p.minSpatialExtents[2]); minLogicalExtentsInParent[2] = int(.5 + (double(zdims[2])/zpct) * (minSpatialExtents[2] - p.minSpatialExtents[2])/(p.maxSpatialExtents[2] - p.minSpatialExtents[2])); maxLogicalExtentsInParent[2] = int(.5 + (double(zdims[2])/zpct) * (maxSpatialExtents[2] - p.minSpatialExtents[2])/(p.maxSpatialExtents[2] - p.minSpatialExtents[2])); } else { minLogicalExtentsInParent[2] = 0; maxLogicalExtentsInParent[2] = 0; } refinementRatio[0] = refinementRatio[1] = refinementRatio[2] = 1; } } // **************************************************************************** // Method: avtEnzoFileFormat::Grid::DetermineExtentsGlobally // // Purpose: // Use the global extents from the parent, and our local extens within // our parent, to determine our global extents. // // Programmer: Jeremy Meredith // Creation: January 3, 2005 // // Modifications: // Jeremy Meredith, Wed Feb 23 15:18:48 PST 2005 // May have multiple root grids; identify by parentID==0, not by ID==1. // // Jeremy Meredith, Thu Aug 11 14:35:00 PDT 2005 // Fixed logical extents when there are multiple root grids. // // **************************************************************************** void avtEnzoFileFormat::Grid::DetermineExtentsGlobally(int numLevels, vector<Grid> &grids) { if (parentID != 0) { Grid &p = grids[parentID]; minLogicalExtentsGlobally[0] = int((p.minLogicalExtentsGlobally[0] + minLogicalExtentsInParent[0])*refinementRatio[0]); minLogicalExtentsGlobally[1] = int((p.minLogicalExtentsGlobally[1] + minLogicalExtentsInParent[1])*refinementRatio[1]); minLogicalExtentsGlobally[2] = int((p.minLogicalExtentsGlobally[2] + minLogicalExtentsInParent[2])*refinementRatio[2]); maxLogicalExtentsGlobally[0] = int((p.minLogicalExtentsGlobally[0] + maxLogicalExtentsInParent[0])*refinementRatio[0]); maxLogicalExtentsGlobally[1] = int((p.minLogicalExtentsGlobally[1] + maxLogicalExtentsInParent[1])*refinementRatio[1]); maxLogicalExtentsGlobally[2] = int((p.minLogicalExtentsGlobally[2] + maxLogicalExtentsInParent[2])*refinementRatio[2]); } else { minLogicalExtentsGlobally[0] = minLogicalExtentsInParent[0]; minLogicalExtentsGlobally[1] = minLogicalExtentsInParent[1]; minLogicalExtentsGlobally[2] = minLogicalExtentsInParent[2]; maxLogicalExtentsGlobally[0] = maxLogicalExtentsInParent[0]; maxLogicalExtentsGlobally[1] = maxLogicalExtentsInParent[1]; maxLogicalExtentsGlobally[2] = maxLogicalExtentsInParent[2]; } } // **************************************************************************** // Method: avtEnzoFileFormat::ReadHierachyFile // // Purpose: // Read the .hierarchy file and get the grid/level hierarchy. // // Arguments: // none // // Programmer: Jeremy Meredith // Creation: January 6, 2005 // // Modifications: // Jeremy Meredith, Wed Aug 3 10:22:36 PDT 2005 // Added support for 2D files. // // Jeremy Meredith, Thu Aug 11 16:59:19 PDT 2005 // Moved the determination of the grid logical extents up a level // (to ReadAllMetaData), because when there are multiple root- // level grids, all of the root level grid extents must be unified // to determine any individual grid's logical extents. // // Jeremy Meredith, Fri Oct 14 14:34:54 PDT 2005 // Fixed bug where the last line of the .hierarchy file was assumed // to be a known item. // // Jeremy Meredith, Mon Apr 6 14:36:58 EDT 2009 // Added support for particle and grid file names. // This is for support for the new "Packed AMR" format. // // **************************************************************************** void avtEnzoFileFormat::ReadHierachyFile() { // PARSE HIERARCHY ifstream h(fnameH.c_str()); if (!h) EXCEPTION1(InvalidFilesException, fnameH.c_str()); // Set something reasonable for a grid with id==0 Grid root; root.ID = 0; root.level = -1; root.parentID = -1; root.dimension = dimension; root.minSpatialExtents[0] = root.minSpatialExtents[1] = root.minSpatialExtents[2] = -1e37; root.maxSpatialExtents[0] = root.maxSpatialExtents[1] = root.maxSpatialExtents[2] = 1e37; root.minLogicalExtentsGlobally[0] = 0; root.minLogicalExtentsGlobally[1] = 0; root.minLogicalExtentsGlobally[2] = 0; root.gridFileName = ""; root.particleFileName = ""; grids.push_back(root); string buff = ""; int level = 0; int parent = 0; while (h) { while (h && buff != "Grid" && buff != "Pointer:" && buff != "Time") h >> buff; if (buff == "Grid") { Grid g; g.dimension = dimension; h >> buff; // '=' h >> g.ID; int min3[3]; int max3[3]; while (buff != "GridStartIndex") { h >> buff; } h >> buff; // '=' if (dimension == 3) h >> min3[0] >> min3[1] >> min3[2]; else h >> min3[0] >> min3[1]; while (buff != "GridEndIndex") { h >> buff; } h >> buff; // '=' if (dimension == 3) h >> max3[0] >> max3[1] >> max3[2]; else h >> max3[0] >> max3[1]; g.zdims[0] = max3[0]-min3[0] + 1; g.zdims[1] = max3[1]-min3[1] + 1; if (dimension == 3) g.zdims[2] = max3[2]-min3[2] + 1; else g.zdims[2] = 1; g.ndims[0] = g.zdims[0]+1; g.ndims[1] = g.zdims[1]+1; if (dimension == 3) g.ndims[2] = g.zdims[2]+1; else g.ndims[2] = 1; while (buff != "GridLeftEdge") { h >> buff; } h >> buff; // '=' if (dimension == 3) h >> g.minSpatialExtents[0] >> g.minSpatialExtents[1] >> g.minSpatialExtents[2]; else { h >> g.minSpatialExtents[0] >> g.minSpatialExtents[1]; g.minSpatialExtents[2] = 0; } while (buff != "GridRightEdge") { h >> buff; } h >> buff; // '=' if (dimension == 3) h >> g.maxSpatialExtents[0] >> g.maxSpatialExtents[1] >> g.maxSpatialExtents[2]; else { h >> g.maxSpatialExtents[0] >> g.maxSpatialExtents[1]; g.maxSpatialExtents[2] = 0; } string fullpath; while (buff != "BaryonFileName") { h >> buff; } h >> buff; // '=' h >> fullpath; g.gridFileName = fname_dir + "/" + FileFunctions::Basename(fullpath.c_str()); while (buff != "NumberOfParticles") { h >> buff; } h >> buff; // '=' h >> g.numberOfParticles; if (g.numberOfParticles > 0) { while (buff != "ParticleFileName") { h >> buff; } h >> buff; // '=' h >> fullpath; g.particleFileName = fname_dir + "/" + FileFunctions::Basename(fullpath.c_str()); } g.level = level; g.parentID = parent; if ((int)grids.size() != g.ID) { EXCEPTION2(InvalidFilesException, fnameH.c_str(), "The grids in the hierarchy are currently " "expected to be listed in order."); } grids.push_back(g); grids[parent].childrenID.push_back(g.ID); numGrids = (int)grids.size()-1; } else if (buff == "Pointer:") { char c; buff = ""; while ((c=h.get()) != '['); while ((c=h.get()) != ']') buff += c; int gridID = atoi(buff.c_str()); h.get(); // - h.get(); // > h >> buff; if (buff == "NextGridNextLevel") { h >> buff; // '=' int n; h >> n; if (n == 0) { } else { level = grids[gridID].level + 1; numLevels = level+1 > numLevels ? level+1 : numLevels; parent = gridID; } } else // buff == "NextGridThisLevel" { h >> buff; // '=' int n; h >> n; if (n == 0) { } else { } } } else if (buff == "Time") { h >> buff; // '=' h >> curTime; } h >> buff; } h.close(); } // **************************************************************************** // Method: avtEnzoFileFormat::ReadParameterFile // // Purpose: // The parameter file is the one without an extension, and it // has some problem setup stuff in it. We are currently only // using it to get the cycle and time. // // Arguments: // none // // Programmer: Jeremy Meredith // Creation: January 6, 2005 // // Modifications: // Jeremy Meredith, Wed Aug 3 10:22:36 PDT 2005 // Added support for 2D files. // // **************************************************************************** void avtEnzoFileFormat::ReadParameterFile() { // PARSE PARAMETER FILE ifstream r(fname_base.c_str()); if (!r) EXCEPTION2(InvalidFilesException, fname_base.c_str(), "This parameter file did not exist."); string buff(""); while (r) { r >> buff; if (buff == "InitialCycleNumber") { r >> buff; // '=' r >> curCycle; } else if (buff == "InitialTime") { r >> buff; // '=' r >> curTime; } else if (buff == "TopGridRank") { r >> buff; // '=' r >> dimension; } } r.close(); } // **************************************************************************** // Method: avtEnzoFileFormat::DetermineVariablesFromGridFile // // Purpose: // Find the smallest grid that contains some particles, or just the smallest // grid if none have any particles. // // Arguments: // none // // Programmer: Jeremy Meredith // Creation: January 6, 2005 // // Modifications: // Jeremy Meredith, Fri Feb 11 18:15:49 PST 2005 // Added HDF5 support. // // Brad Whitlock, Mon Apr 3 11:04:09 PDT 2006 // Added tracer particle support. // // Mark C. Miller, Fri Mar 20 16:07:14 PST 2009 // Made HDF5 related code conditionally compiled on HAVE_LIBHDF5 // // Jeremy Meredith, Mon Apr 6 14:36:58 EDT 2009 // Added support for explicit particle and grid file names. // Also, try to descend into a top-level Group if its name // matches the format for a grid-group in the new format. // This is for support for the new "Packed AMR" format. // // Jeremy Meredith, Wed Jan 6 14:57:18 EST 2010 // Make HDF4 code conditionally compiled so we can support an // HDF5-only build for this plugin as well. // // Kathleen Biagas, Mon Sep 26, 2022 // Remove HDF4 support. Remove #ifdef wrapper for HDF5, since this plugin // is listed as unconditionally dependent on HDF5. // // **************************************************************************** void avtEnzoFileFormat::DetermineVariablesFromGridFile() { int smallest_grid = 0; int smallest_grid_nzones = INT_MAX; bool found_grid_with_particles = false; for (size_t i=1; i<grids.size(); i++) { Grid &g = grids[i]; if (found_grid_with_particles && g.numberOfParticles <= 0) continue; int numZones = g.zdims[0]*g.zdims[1]*g.zdims[2]; if ((!found_grid_with_particles && g.numberOfParticles > 0) || (numZones < smallest_grid_nzones)) { if (!found_grid_with_particles || (found_grid_with_particles && g.numberOfParticles > 0)) { smallest_grid_nzones = numZones; smallest_grid = g.ID; found_grid_with_particles = (g.numberOfParticles > 0); } } } string gridFileName = grids[smallest_grid].gridFileName; debug3 << "Smallest Enzo grid with particles was # "<<smallest_grid<<endl; hid_t fileId = H5Fopen(gridFileName.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); if (fileId < 0) { EXCEPTION2(InvalidFilesException, gridFileName.c_str(), "The HDF5 library failed to open this file and this" "installation of the Enzo plugin is NOT compiled with " "HDF4 support. So, the file may be an HDF4 file but if " "so, it cannot be opened with this installation."); } fileType = ENZO_FT_HDF5; // NOTE: H5Gget_num_objs fails using a file id in HDF51.6.0, but // works correctly (as the documentation says it should) in // 1.6.3. Since we're going for portability, just open the // darn root group and use that instead. hid_t rootId = H5Gopen(fileId, "/"); hid_t rootId_tmp; // Make a pass over the contents of the root directory // looking for a group corresponding to our grid name, and // open it if necessary. hsize_t n_objs; H5Gget_num_objs(rootId, &n_objs); for (hsize_t var = 0 ; var < n_objs ; var++) { if (H5Gget_objtype_by_idx(rootId, var) == H5G_GROUP) { int gridindex; char name[65]; H5Gget_objname_by_idx(rootId, var, name, 64); if (sscanf(name, "Grid%d", &gridindex) == 1 && gridindex == smallest_grid) { rootId_tmp = rootId; rootId = H5Gopen(rootId, name); H5Gclose(rootId_tmp); break; } } } // In case we opened a subdirectory, get the num items again. H5Gget_num_objs(rootId, &n_objs); // Okay, actually do the parsing work. for (size_t var = 0 ; var < n_objs ; var++) { if (H5Gget_objtype_by_idx(rootId, var) == H5G_DATASET) { char name[65]; H5Gget_objname_by_idx(rootId, var, name, 64); // NOTE: to do the same diligence as HDF4 here, we should // really H5Dopen, H5Dget_space, H5Sget_simple_extent_ndims // and make sure it is a 3D (or 2D?) object before assuming // it is a mesh variable. For now, assume away! if (strlen(name) > 8 && strncmp(name,"particle",8)==0) { // it's a particle variable; skip over coordinate arrays if (strncmp(name,"particle_position_",18) != 0) { particleVarNames.push_back(name); } } else if (strlen(name) > 16 && strncmp(name,"tracer_particles",16)==0) { // it's a particle variable; skip over coordinate arrays if (strncmp(name,"tracer_particle_position_",25) != 0) { tracerparticleVarNames.push_back(name); } } else { varNames.push_back(name); } } } H5Gclose(rootId); H5Fclose(fileId); } // **************************************************************************** // Method: avtEnzoFileFormat constructor // // Programmer: Jeremy Meredith // Creation: January 3, 2005 // // Modifications: // Jeremy Meredith, Fri Feb 11 18:15:49 PST 2005 // Added HDF5 support. // // Jeremy Meredith, Wed Aug 3 10:22:36 PDT 2005 // Added support for 2D files. // // Jeremy Meredith, Mon Apr 6 14:40:37 EDT 2009 // Save the directory name off; we'll need to add it back on // later to open some other files. // // **************************************************************************** avtEnzoFileFormat::avtEnzoFileFormat(const char *filename) : avtSTMDFileFormat(&filename, 1) { fileType = ENZO_FT_UNKNOWN; dimension = 0; numGrids = 0; numLevels = 0; curTime = 0; string fname(filename); string extH(".hierarchy"); string extB(".boundary"); if (fname.length() > extH.length() && fname.substr(fname.length()-extH.length()) == extH) { fname_base = fname.substr(0,fname.length()-extH.length()); fnameH = fname; fnameB = fname_base + extB; } else if (fname.length() > extB.length() && fname.substr(fname.length()-extB.length()) == extB) { fname_base = fname.substr(0,fname.length()-extB.length()); fnameB = fname; fnameH = fname_base + extH; } else { EXCEPTION2(InvalidFilesException, fname.c_str(), "It was not a .hierarchy or .boundary file."); } fname_dir = FileFunctions::Dirname(fname_base.c_str()); } // **************************************************************************** // Method: avtEnzoFileFormat destructure // // Programmer: Jeremy Meredith // Creation: January 6, 2005 // // **************************************************************************** avtEnzoFileFormat::~avtEnzoFileFormat() { } // **************************************************************************** // Method: avtEnzoFileFormat::UnifyGlobalExtents // // Purpose: // Gets the total spatial extents for the whole problem. Uses only the // root level grids since they are guaranteed to cover the spatial extents. // // Arguments: // none // // Programmer: Jeremy Meredith // Creation: August 11, 2005 // // **************************************************************************** void avtEnzoFileFormat::UnifyGlobalExtents() { Grid &root = grids[0]; root.minSpatialExtents[0] = grids[1].minSpatialExtents[0]; root.maxSpatialExtents[0] = grids[1].maxSpatialExtents[0]; root.minSpatialExtents[1] = grids[1].minSpatialExtents[1]; root.maxSpatialExtents[1] = grids[1].maxSpatialExtents[1]; if (dimension == 3) { root.minSpatialExtents[2] = grids[1].minSpatialExtents[2]; root.maxSpatialExtents[2] = grids[1].maxSpatialExtents[2]; } else { root.minSpatialExtents[2] = 0; root.maxSpatialExtents[2] = 0; } // now loop over all level zero grids for (int g = 2 ; g <= numGrids && grids[g].parentID == 0 ; g++) { for (int j = 0 ; j < dimension ; j++) { if (grids[g].minSpatialExtents[j] < root.minSpatialExtents[j]) root.minSpatialExtents[j] = grids[g].minSpatialExtents[j]; if (grids[g].maxSpatialExtents[j] > root.maxSpatialExtents[j]) root.maxSpatialExtents[j] = grids[g].maxSpatialExtents[j]; } } } // **************************************************************************** // Method: avtEnzoFileFormat::ReadAllMetaData // // Purpose: // Read the metadata if we have not done so yet. // // Arguments: // none // // Programmer: Jeremy Meredith // Creation: January 6, 2005 // // Modifications: // Jeremy Meredith, Thu Aug 11 16:59:19 PDT 2005 // Moved the determination of the grid logical extents to here from // ReadHierachyFile, because when there are multiple root- // level grids, all of the root level grid extents must be unified // to determine any individual grid's logical extents. // // **************************************************************************** void avtEnzoFileFormat::ReadAllMetaData() { // Check to see if we've read it yet if (numGrids > 0) return; // The parameter file ReadParameterFile(); // Read the hierarchy file, and simultaneously // convert spatial extents into logical extents ReadHierachyFile(); // We need to get the whole global extents before we // can determine logical extents UnifyGlobalExtents(); // Convert the parent logical extents for (size_t i=1; i<grids.size(); i++) { grids[i].DetermineExtentsInParent(grids); grids[i].DetermineExtentsGlobally(numLevels, grids); } // Open the smallest grid file and determine what variables // are in it DetermineVariablesFromGridFile(); } // **************************************************************************** // Method: avtEnzoFileFormat::GetCycle // // Purpose: // Return the cycle. // // Arguments: // none // // Programmer: Jeremy Meredith // Creation: January 6, 2005 // // **************************************************************************** int avtEnzoFileFormat::GetCycle() { return curCycle; } // **************************************************************************** // Method: avtEnzoFileFormat::GetCycleFromFilename // // Purpose: // Do a better job at guessing the cycle number for an Enzo file. // // Arguments: // none // // Programmer: Jeremy Meredith // Creation: July 15, 2005 // // **************************************************************************** int avtEnzoFileFormat::GetCycleFromFilename(const char *cfilename) const { string f = cfilename; string::size_type last_slash = f.rfind('/'); if (last_slash != string::npos) f = f.substr(last_slash+1); string::size_type last_dot = f.rfind('.'); if (last_dot != string::npos) f = f.substr(0, last_dot); string::size_type last_nondigit = f.find_last_not_of("0123456789"); if (last_nondigit != string::npos) f = f.substr(last_nondigit+1); if (f.empty()) return 0; if (f.length() > 4) f = f.substr(f.length() - 4); return atoi(f.c_str()); } // **************************************************************************** // Method: avtEnzoFileFormat::ActivateTimestep // // Purpose: // This is called by the generic database to signal that this file format // is going to be used soon. It is important that each file format defer // as much work as possible, since there can be many (one per timestep), // and we won't need all their work at once, if at all. // // Programmer: Jeremy Meredith // Creation: July 15, 2005 // // **************************************************************************** void avtEnzoFileFormat::ActivateTimestep(void) { // Nothing to do } // **************************************************************************** // Method: avtEnzoFileFormat::FreeUpResources // // Purpose: // When VisIt is done focusing on a particular timestep, it asks that // timestep to free up any resources (memory, file descriptors) that // it has associated with it. This method is the mechanism for doing // that. // // Programmer: Jeremy Meredith // Creation: January 4, 2005 // // Modifications: // Brad Whitlock, Mon Apr 3 11:05:13 PDT 2006 // Added tracerparticleVarNames. // // **************************************************************************** void avtEnzoFileFormat::FreeUpResources(void) { grids.clear(); varNames.clear(); particleVarNames.clear(); tracerparticleVarNames.clear(); numGrids=0; numLevels=0; } // **************************************************************************** // Method: avtEnzoFileFormat::PopulateDatabaseMetaData // // Purpose: // This database meta-data object is like a table of contents for the // file. By populating it, you are telling the rest of VisIt what // information it can request from you. // // Programmer: meredith -- generated by xml2avt // Creation: Fri Dec 3 17:19:52 PST 2004 // // Modifications: // // Hank Childs, Thu Jan 13 15:31:08 PST 2005 // Generate domain nesting object. // // Jeremy Meredith, February 23, 2005 // May have more than one root-level grid. Unify extents over all of them. // // Jeremy Meredith, Fri Jul 15 15:29:14 PDT 2005 // Added cycle and time to the metadata. // // Jeremy Meredith, Wed Aug 3 10:22:36 PDT 2005 // Added support for 2D files. Fixed problem with single-grid files. // Fixed dimensionality of point meshes. // // Jeremy Meredith, Thu Aug 11 17:09:22 PDT 2005 // Moved the unification of the problem spatial extents to a new method. // This is because it had to be calculated much earlier in the process. // // Hank Childs, Wed Jan 11 09:40:17 PST 2006 // Change mesh type to AMR. // // Brad Whitlock, Mon Apr 3 11:07:11 PDT 2006 // Added tracer particle support. // // Mark C. Miller, Mon Dec 8 22:20:35 PST 2008 // Fixed obvious typo in particle velocity expression and made attempt // (without test data in hand) to ensure expressions get specified // correctly on 2D meshes. // // Jean Favre, Wed Jul 27 09:29:46 PDT 2011 // Add support for resolution selection contract. // // **************************************************************************** void avtEnzoFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md) { // read in the metadata if we have not done so yet ReadAllMetaData(); if (!avtDatabase::OnlyServeUpMetaData()) BuildDomainNesting(); avtMeshMetaData *mesh = new avtMeshMetaData; mesh->name = "mesh"; mesh->originalName = "mesh"; mesh->meshType = AVT_AMR_MESH; mesh->topologicalDimension = dimension; mesh->spatialDimension = dimension; mesh->hasSpatialExtents = true; mesh->minSpatialExtents[0] = grids[0].minSpatialExtents[0]; mesh->maxSpatialExtents[0] = grids[0].maxSpatialExtents[0]; mesh->minSpatialExtents[1] = grids[0].minSpatialExtents[1]; mesh->maxSpatialExtents[1] = grids[0].maxSpatialExtents[1]; mesh->minSpatialExtents[2] = grids[0].minSpatialExtents[2]; mesh->maxSpatialExtents[2] = grids[0].maxSpatialExtents[2]; // spoof a group/domain mesh mesh->numBlocks = numGrids; mesh->blockTitle = "Grids"; mesh->blockPieceName = "grid"; mesh->numGroups = numLevels; mesh->groupTitle = "Levels"; mesh->groupPieceName = "level"; vector<int> groupIds(numGrids); vector<string> blockPieceNames(numGrids); int levels_of_detail = 0; for (int i = 1; i <= numGrids; i++) { char tmpName[64]; sprintf(tmpName,"level%d,grid%d",grids[i].level, grids[i].ID); groupIds[i-1] = grids[i].level; blockPieceNames[i-1] = tmpName; levels_of_detail = std::max(levels_of_detail, grids[i].level); } mesh->LODs = levels_of_detail; this->resolution = levels_of_detail; // current acceptable res = max res mesh->blockNames = blockPieceNames; mesh->numGroups = numLevels; mesh->groupIds = groupIds; md->Add(mesh); avtMeshMetaData *pmesh = new avtMeshMetaData; pmesh->name = "particles"; pmesh->originalName = "particles"; pmesh->meshType = AVT_POINT_MESH; pmesh->topologicalDimension = 0; pmesh->spatialDimension = dimension; pmesh->hasSpatialExtents = false; pmesh->numBlocks = numGrids; pmesh->blockTitle = "Grids"; pmesh->blockPieceName = "grid"; pmesh->numGroups = numLevels; pmesh->groupTitle = "Levels"; pmesh->groupPieceName = "level"; pmesh->blockNames = blockPieceNames; pmesh->numGroups = numLevels; pmesh->groupIds = groupIds; md->Add(pmesh); pmesh = new avtMeshMetaData; pmesh->name = "tracer_particles"; pmesh->originalName = "tracer_particles"; pmesh->meshType = AVT_POINT_MESH; pmesh->topologicalDimension = 0; pmesh->spatialDimension = dimension; pmesh->hasSpatialExtents = false; pmesh->numBlocks = numGrids; pmesh->blockTitle = "Grids"; pmesh->blockPieceName = "grid"; pmesh->numGroups = numLevels; pmesh->groupTitle = "Levels"; pmesh->groupPieceName = "level"; pmesh->blockNames = blockPieceNames; pmesh->numGroups = numLevels; pmesh->groupIds = groupIds; md->Add(pmesh); // grid variables for (size_t v = 0 ; v < varNames.size(); v++) { AddScalarVarToMetaData(md, varNames[v], "mesh", AVT_ZONECENT); } // particle variables for (size_t p = 0 ; p < particleVarNames.size(); p++) { AddScalarVarToMetaData(md, particleVarNames[p], "particles", AVT_NODECENT); } // tracer particle variables for (size_t tp = 0 ; tp < tracerparticleVarNames.size(); tp++) { AddScalarVarToMetaData(md, tracerparticleVarNames[tp], "tracer_particles", AVT_NODECENT); } // Add Expressions Expression vel; vel.SetName("velocity"); if (dimension == 2) vel.SetDefinition("{<x-velocity>,<y-velocity>}"); else vel.SetDefinition("{<x-velocity>,<y-velocity>,<z-velocity>}"); vel.SetType(Expression::VectorMeshVar); Expression pvel; pvel.SetName("particle_velocity"); if (dimension == 2) pvel.SetDefinition("{particle_velocity_x,particle_velocity_y}"); else pvel.SetDefinition("{particle_velocity_x,particle_velocity_y,particle_velocity_z}"); pvel.SetType(Expression::VectorMeshVar); md->AddExpression(&vel); md->AddExpression(&pvel); // Populate cycle and time md->SetCycle(timestep, curCycle); md->SetTime(timestep, curTime); md->SetCycleIsAccurate(true, timestep); md->SetTimeIsAccurate(true, timestep); } // **************************************************************************** // Method: avtEnzoFileFormat::GetMesh // // Purpose: // Gets the mesh associated with this file. The mesh is returned as a // derived type of vtkDataSet (ie vtkRectilinearGrid, vtkStructuredGrid, // vtkUnstructuredGrid, etc). // // Arguments: // domain The index of the domain. If there are NDomains, this // value is guaranteed to be between 0 and NDomains-1, // regardless of block origin. // meshname The name of the mesh of interest. This can be ignored if // there is only one mesh. // // Programmer: Jeremy Meredith // Creation: January 6, 2005 // // Modifications: // Hank Childs, Thu Jan 13 15:31:08 PST 2005 // Remove hack where domain boundary nesting structure is removed from // cache to accomodate incorrect applications in generic database. // // Jeremy Meredith, Fri Feb 11 18:15:49 PST 2005 // Added HDF5 support. // // Jeremy Meredith, Wed Aug 3 10:22:36 PDT 2005 // Added support for 2D files. Added support for single-level files. // // Jeremy Meredith, Thu Sep 8 12:03:55 PDT 2005 // Added support for float32 coordinates in HDF4. // // Brad Whitlock, Mon Apr 3 11:00:15 PDT 2006 // Added support for tracer_particles. // // Mark C. Miller, Fri Mar 20 16:07:14 PST 2009 // Made HDF5 related code conditionally compiled on HAVE_LIBHDF5 // // Jeremy Meredith, Mon Apr 6 14:36:58 EDT 2009 // Added support for explicit particle and grid file names. // Also, try to descend into a top-level Group if its name // matches the format for a grid-group in the new format. // This is for support for the new "Packed AMR" format. // // Jeremy Meredith, Wed Jan 6 14:57:18 EST 2010 // Make HDF4 code conditionally compiled so we can support an // HDF5-only build for this plugin as well. // // Kathleen Biagas, Mon Sep 26, 2022 // Remove HDF4 support. Remove #ifdef wrapper for HDF5, since this plugin // is listed as unconditionally dependent on HDF5. // // **************************************************************************** vtkDataSet * avtEnzoFileFormat::GetMesh(int domain, const char *meshname) { ReadAllMetaData(); if (string(meshname) == "mesh") { // rectilinear mesh vtkFloatArray *coords[3]; int i; int d = domain+1; for (i = 0 ; i < 3 ; i++) { coords[i] = vtkFloatArray::New(); coords[i]->SetNumberOfTuples(grids[d].ndims[i]); for (int j = 0 ; j < grids[d].ndims[i] ; j++) { if (i+1 > dimension) { coords[i]->SetComponent(j, 0, 0); } else { double c = grids[d].minSpatialExtents[i] + double(j) * (grids[d].maxSpatialExtents[i]-grids[d].minSpatialExtents[i]) / double(grids[d].ndims[i]-1); coords[i]->SetComponent(j, 0, c); } } } vtkRectilinearGrid *rGrid = vtkRectilinearGrid::New(); rGrid->SetDimensions(grids[d].ndims); rGrid->SetXCoordinates(coords[0]); coords[0]->Delete(); rGrid->SetYCoordinates(coords[1]); coords[1]->Delete(); rGrid->SetZCoordinates(coords[2]); coords[2]->Delete(); return rGrid; } else if (fileType == ENZO_FT_HDF5) { // particle mesh string particleFileName = grids[domain+1].particleFileName; if (particleFileName == "") { return NULL; } hid_t fileId = H5Fopen(particleFileName.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); if (fileId < 0) { EXCEPTION1(InvalidFilesException, particleFileName.c_str()); } // Make a pass over the contents of the root directory // looking for a group corresponding to our grid name, and // open it if necessary. hid_t rootId = H5Gopen(fileId, "/"); hid_t rootId_tmp; hsize_t n_objs; H5Gget_num_objs(rootId, &n_objs); for (hsize_t var = 0 ; var < n_objs ; var++) { if (H5Gget_objtype_by_idx(rootId, var) == H5G_GROUP) { int gridindex; char name[65]; H5Gget_objname_by_idx(rootId, var, name, 64); if (sscanf(name, "Grid%d", &gridindex) == 1 && gridindex == domain+1) { rootId_tmp = rootId; rootId = H5Gopen(rootId, name); H5Gclose(rootId_tmp); break; } } } // temporarily disable error reporting H5E_auto_t old_errorfunc; void *old_clientdata; H5Eget_auto(&old_errorfunc, &old_clientdata); H5Eset_auto(NULL, NULL); bool is_particle = (strcmp(meshname, "particles") == 0); const char *xn = is_particle ? "particle_position_x" : "tracer_particle_position_x"; const char *yn = is_particle ? "particle_position_y" : "tracer_particle_position_y"; const char *zn = is_particle ? "particle_position_z" : "tracer_particle_position_z"; // find the coordinate variables (if they exist) hid_t var_id_x = H5Dopen(rootId, xn); hid_t var_id_y = H5Dopen(rootId, yn); hid_t var_id_z = dimension==3 ? H5Dopen(rootId, zn) : -1; // turn back on error reporting H5Eset_auto(old_errorfunc, old_clientdata); // check if the variables exist if (var_id_x < 0 || var_id_y < 0 || (dimension==3 && var_id_z < 0)) { // This grid didn't have any particles. No problem -- particles // won't exist in every grid. Just close the file and return // NULL. H5Gclose(rootId); H5Fclose(fileId); return NULL; } // Get the number of particles hid_t spaceId = H5Dget_space(var_id_x); hsize_t dims[3]; H5Sget_simple_extent_dims(spaceId, dims, NULL); // It's one-dimensional int npart = dims[0]; vtkPoints *points = vtkPoints::New(); points->SetNumberOfPoints(npart); float *pts = (float *) points->GetVoidPointer(0); int i; double *ddata = new double[npart]; H5Dread(var_id_x, H5T_NATIVE_DOUBLE,H5S_ALL,H5S_ALL,H5P_DEFAULT, ddata); for (i=0; i<npart; i++) pts[i*3+0] = float(ddata[i]); H5Dread(var_id_y, H5T_NATIVE_DOUBLE,H5S_ALL,H5S_ALL,H5P_DEFAULT, ddata); for (i=0; i<npart; i++) pts[i*3+1] = float(ddata[i]); if (dimension == 3) { H5Dread(var_id_z, H5T_NATIVE_DOUBLE,H5S_ALL,H5S_ALL,H5P_DEFAULT, ddata); for (i=0; i<npart; i++) pts[i*3+2] = float(ddata[i]); } else { for (i=0; i<npart; i++) pts[i*3+2] = 0; } H5Dclose(var_id_x); H5Dclose(var_id_y); if (dimension == 3) H5Dclose(var_id_z); H5Sclose(spaceId); vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New(); ugrid->SetPoints(points); ugrid->Allocate(npart); vtkIdType onevertex; for(i = 0; i < npart; ++i) { onevertex = i; ugrid->InsertNextCell(VTK_VERTEX, 1, &onevertex); } points->Delete(); // For now, always close the file H5Gclose(rootId); H5Fclose(fileId); return ugrid; } return NULL; } // **************************************************************************** // Method: avtEnzoFileFormat::BuildDomainNesting // // Purpose: // Generates the domain nesting object needed to remove coarse zones in // an AMR mesh. // // Programmer: Jeremy Meredith // Creation: January 6, 2005 // // Modifications: // Hank Childs, Thu Jan 13 15:31:08 PST 2005 // Renamed "any_mesh" to "mesh", since the generic database can now use this // information. // // Jeremy Meredith, Thu May 5 10:28:28 PDT 2005 // Skip the whole thing if there's only one grid. // // Jeremy Meredith, Wed Aug 3 10:22:36 PDT 2005 // Added support for 2D files. // // Eric Brugger, Tue Oct 17 09:49:26 PDT 2006 // Replaced the coding that hardcoded the refinement ratio at 2 with // the actual refinement ratio. // // **************************************************************************** void avtEnzoFileFormat::BuildDomainNesting() { if (numGrids <= 1) return; // first, look to see if we don't already have it cached void_ref_ptr vrTmp = cache->GetVoidRef("mesh", AUXILIARY_DATA_DOMAIN_NESTING_INFORMATION, timestep, -1); if ((*vrTmp == NULL)) { int i; avtRectilinearDomainBoundaries *rdb = new avtRectilinearDomainBoundaries(true); rdb->SetNumDomains(numGrids); for (i = 1; i <= numGrids; i++) { int logExts[6]; logExts[0] = grids[i].minLogicalExtentsGlobally[0]; logExts[1] = grids[i].maxLogicalExtentsGlobally[0]; logExts[2] = grids[i].minLogicalExtentsGlobally[1]; logExts[3] = grids[i].maxLogicalExtentsGlobally[1]; logExts[4] = grids[i].minLogicalExtentsGlobally[2]; logExts[5] = grids[i].maxLogicalExtentsGlobally[2]; rdb->SetIndicesForAMRPatch(i-1, grids[i].level, logExts); } rdb->CalculateBoundaries(); void_ref_ptr vrdb = void_ref_ptr(rdb, avtStructuredDomainBoundaries::Destruct); cache->CacheVoidRef("any_mesh", AUXILIARY_DATA_DOMAIN_BOUNDARY_INFORMATION, timestep, -1, vrdb); // // build the avtDomainNesting object // if (numLevels > 0) { avtStructuredDomainNesting *dn = new avtStructuredDomainNesting(numGrids, numLevels); dn->SetNumDimensions(dimension); // // Set refinement level ratio information // // NOTE: this appears to be on a per-level basis, not a // per-grid basis. There is no reason internally // that refinement ratios could not change on a // per-grid basis, but it is only stored on a per- // level basis. Since the refinement ratios are // per-level and they are stored per-grid in the // reader, the per-grid ratios must be mapped to // a per-level basis and checked to make sure that // all the per-grid ratios are the same for a given // level. int *levelRatios = new int[numLevels*3]; for (i = 0; i < numLevels*3; i++) { levelRatios[i] = -1; } for (i = 1; i <= numGrids; i++) { int level = grids[i].level; if (levelRatios[level*3] == -1) { levelRatios[level*3] = int(grids[i].refinementRatio[0]); levelRatios[level*3+1] = int(grids[i].refinementRatio[1]); levelRatios[level*3+2] = int(grids[i].refinementRatio[2]); } else if (levelRatios[level*3] != grids[i].refinementRatio[0] || levelRatios[level*3+1] != grids[i].refinementRatio[1] || levelRatios[level*3+2] != grids[i].refinementRatio[2]) { EXCEPTION1(ImproperUseException, "Refinement ratios not uniform for a level."); } } vector<int> ratios(3); for (i = 0; i < numLevels; i++) { ratios[0] = levelRatios[i*3]; ratios[1] = levelRatios[i*3+1]; ratios[2] = levelRatios[i*3+2]; dn->SetLevelRefinementRatios(i, ratios); } delete [] levelRatios; // // set each domain's level, children and logical extents // for (i = 1; i <= numGrids; i++) { vector<int> childGrids; for (size_t j = 0; j < grids[i].childrenID.size(); j++) { // if this is allowed to be 1-origin, we will just pass // the "children" array up -- the "-1" here at least needs // to be removed childGrids.push_back(grids[i].childrenID[j] - 1); } vector<int> logExts(6); logExts[0] = grids[i].minLogicalExtentsGlobally[0]; logExts[1] = grids[i].minLogicalExtentsGlobally[1]; logExts[2] = grids[i].minLogicalExtentsGlobally[2]; logExts[3] = grids[i].maxLogicalExtentsGlobally[0]-1; logExts[4] = grids[i].maxLogicalExtentsGlobally[1]-1; if (dimension == 3) logExts[5] = grids[i].maxLogicalExtentsGlobally[2]-1; else logExts[5] = grids[i].minLogicalExtentsGlobally[2]; dn->SetNestingForDomain(i-1, grids[i].level, childGrids, logExts); } void_ref_ptr vr = void_ref_ptr(dn, avtStructuredDomainNesting::Destruct); cache->CacheVoidRef("mesh", AUXILIARY_DATA_DOMAIN_NESTING_INFORMATION, timestep, -1, vr); } } } // **************************************************************************** // Method: avtEnzoFileFormat::GetVar // // Purpose: // Gets a scalar variable associated with this file. Although VTK has // support for many different types, the best bet is vtkFloatArray, since // that is supported everywhere through VisIt. // // Arguments: // domain The index of the domain. If there are NDomains, this // value is guaranteed to be between 0 and NDomains-1, // regardless of block origin. // varname The name of the variable requested. // // Programmer: Jeremy Meredith // Creation: January 6, 2005 // // Modifications: // Jeremy Meredith, Fri Feb 11 18:15:49 PST 2005 // Added HDF5 support. // // Jeremy Meredith, Wed Aug 3 10:22:36 PDT 2005 // Added support for 2D files. // // Mark C. Miller, Fri Mar 20 16:07:14 PST 2009 // Made HDF5 related code conditionally compiled on HAVE_LIBHDF5 // // Jeremy Meredith, Mon Apr 6 14:36:58 EDT 2009 // Added support for explicit particle and grid file names. // Also, try to descend into a top-level Group if its name // matches the format for a grid-group in the new format. // This is for support for the new "Packed AMR" format. // Also, no longer return an error if a grid was missing. Some // times, this happens (e.g. Dark_Matter_Density), and it seems // to work okay if we just return NULL here. // // Jeremy Meredith, Wed Jan 6 14:57:18 EST 2010 // Make HDF4 code conditionally compiled so we can support an // HDF5-only build for this plugin as well. // // Kathleen Biagas, Mon Sep 26, 2022 // Remove HDF4 support. Remove #ifdef wrapper for HDF5, since this plugin // is listed as unconditionally dependent on HDF5. // // **************************************************************************** vtkDataArray * avtEnzoFileFormat::GetVar(int domain, const char *varname) { ReadAllMetaData(); // HDF5 STUFF string gridFileName = grids[domain+1].gridFileName; hid_t fileId = H5Fopen(gridFileName.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); if (fileId < 0) { EXCEPTION1(InvalidFilesException, gridFileName.c_str()); } // Make a pass over the contents of the root directory // looking for a group corresponding to our grid name, and // open it if necessary. hid_t rootId = H5Gopen(fileId, "/"); hid_t rootId_tmp; hsize_t n_objs; H5Gget_num_objs(rootId, &n_objs); for (hsize_t var = 0 ; var < n_objs ; var++) { if (H5Gget_objtype_by_idx(rootId, var) == H5G_GROUP) { int gridindex; char name[65]; H5Gget_objname_by_idx(rootId, var, name, 64); if (sscanf(name, "Grid%d", &gridindex) == 1 && gridindex == domain+1) { rootId_tmp = rootId; rootId = H5Gopen(rootId, name); H5Gclose(rootId_tmp); break; } } } // temporarily disable error reporting H5E_auto_t old_errorfunc; void *old_clientdata; H5Eget_auto(&old_errorfunc, &old_clientdata); H5Eset_auto(NULL, NULL); // find the variable (if it exists) hid_t varId = H5Dopen(rootId, varname); // turn back on error reporting H5Eset_auto(old_errorfunc, old_clientdata); // check if the variable exists if (varId < 0) { // This is apparently okay. We could populate with zeros, but // it's easier to just return NULL, which seems to work. H5Gclose(rootId); H5Fclose(fileId); return NULL; } hid_t spaceId = H5Dget_space(varId); hsize_t dims[3]; H5Sget_simple_extent_dims(spaceId, dims, NULL); hsize_t ndims = H5Sget_simple_extent_ndims(spaceId); int ntuples; if (ndims == 1) ntuples = dims[0]; else if (ndims == 2) ntuples = dims[0]*dims[1]; else if (ndims == 3) ntuples = dims[0]*dims[1]*dims[2]; else EXCEPTION1(InvalidVariableException, varname); vtkFloatArray * fa = vtkFloatArray::New(); fa->SetNumberOfTuples(ntuples); float *data = fa->GetPointer(0); double *d_data; int *i_data; unsigned int *ui_data; int i; for (i = 0 ; i < ntuples ; i++) data[i] = 1; hid_t raw_data_type = H5Dget_type(varId); hid_t data_type = H5Tget_native_type(raw_data_type, H5T_DIR_ASCEND); if (H5Tequal(data_type, H5T_NATIVE_FLOAT)>0) { H5Dread(varId, data_type,H5S_ALL,H5S_ALL,H5P_DEFAULT, data); } else if (H5Tequal(data_type, H5T_NATIVE_DOUBLE)>0) { d_data = new double[ntuples]; H5Dread(varId, data_type,H5S_ALL,H5S_ALL,H5P_DEFAULT, d_data); for (i = 0 ; i < ntuples ; i++) data[i] = d_data[i]; delete[] d_data; } else if (H5Tequal(data_type, H5T_NATIVE_INT)) { i_data = new int[ntuples]; H5Dread(varId, data_type,H5S_ALL,H5S_ALL,H5P_DEFAULT, i_data); for (i = 0 ; i < ntuples ; i++) data[i] = i_data[i]; delete[] i_data; } else if (H5Tequal(data_type, H5T_NATIVE_UINT)) { ui_data = new unsigned int[ntuples]; H5Dread(varId, data_type,H5S_ALL,H5S_ALL,H5P_DEFAULT, ui_data); for (i = 0 ; i < ntuples ; i++) data[i] = ui_data[i]; delete[] ui_data; } else { // ERROR: UKNOWN TYPE } // Done with the type H5Tclose(data_type); H5Tclose(raw_data_type); // Done with the variable; don't leak it H5Dclose(varId); H5Sclose(spaceId); // For now, always close the file H5Gclose(rootId); H5Fclose(fileId); return fa; } // **************************************************************************** // Method: avtEnzoFileFormat::GetVectorVar // // Purpose: // Gets a vector variable associated with this file. Although VTK has // support for many different types, the best bet is vtkFloatArray, since // that is supported everywhere through VisIt. // // Arguments: // domain The index of the domain. If there are NDomains, this // value is guaranteed to be between 0 and NDomains-1, // regardless of block origin. // varname The name of the variable requested. // // Programmer: Jeremy Meredith // Creation: January 4, 2005 // // **************************************************************************** vtkDataArray * avtEnzoFileFormat::GetVectorVar(int domain, const char *varname) { return NULL; } // **************************************************************************** // Method: avtEnzoFileFormat::GetAuxiliaryData // // Purpose: // Right now this only supports spatial interval trees. There is no // other information like materials and species available. // // Arguments: // type the kind of auxiliary data to create // // Programmer: Jeremy Meredith // Creation: January 6, 2005 // // Modifications: // Kathleen Bonnell, Mon Aug 14 16:40:30 PDT 2006 // API change for avtIntervalTree. // // **************************************************************************** void * avtEnzoFileFormat::GetAuxiliaryData(const char *var, int dom, const char * type, void *, DestructorFunction &df) { if (type != AUXILIARY_DATA_SPATIAL_EXTENTS) return NULL; avtIntervalTree *itree = new avtIntervalTree(numGrids, 3); for (int grid = 1 ; grid <= numGrids ; grid++) { double bounds[6]; bounds[0] = grids[grid].minSpatialExtents[0]; bounds[1] = grids[grid].maxSpatialExtents[0]; bounds[2] = grids[grid].minSpatialExtents[1]; bounds[3] = grids[grid].maxSpatialExtents[1]; bounds[4] = grids[grid].minSpatialExtents[2]; bounds[5] = grids[grid].maxSpatialExtents[2]; itree->AddElement(grid-1, bounds); } itree->Calculate(true); df = avtIntervalTree::Destruct; return ((void *) itree); } // **************************************************************************** // Method: avtEnzoFileFormat::RegisterDataSelections // // Purpose: // Tries to read requests for specific resolutions. // // Programmer: Jean Favre // Creation: July 27, 2011 // // Modifications: // // **************************************************************************** void avtEnzoFileFormat::RegisterDataSelections(const std::vector<avtDataSelection_p>& sels, std::vector<bool>* applied) { for(size_t i=0; i < sels.size(); ++i) { if(strcmp(sels[i]->GetType(), "avtResolutionSelection") == 0) { const avtResolutionSelection* sel = static_cast<const avtResolutionSelection*>(*sels[i]); this->resolution = sel->resolution(); (*applied)[i] = true; } } }
e6e3d550fd804d9db1330c2c72b8218b1c5d44af
57d0f7e4c74f2f50fa9c4dc4e8227e4c014b4414
/src/parse_table.c
ebf7e7159d819b20d615b8e0bae229f32f0fdb1b
[ "BSD-3-Clause" ]
permissive
dharple/detox
4e568272b7ea5c8d1c1acda3f0ca48b2debf9583
df0c0781b76c1f96b0018d8f376d4674f0cb607f
refs/heads/main
2023-03-24T06:09:24.417994
2023-03-10T12:33:23
2023-03-10T12:33:23
82,884,753
252
23
BSD-3-Clause
2023-09-13T10:13:15
2017-02-23T04:38:21
C
UTF-8
C
false
false
4,622
c
parse_table.c
/** * This file is part of the Detox package. * * Copyright (c) Doug Harple <detox.dharple@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ #include <sys/stat.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <locale.h> #include "table.h" #include "wrapped.h" #define LINE_LENGTH 6 enum { BASE_STATE, INSIDE_STATE }; table_t *parse_table(char *filename) { FILE *table_file; char *work; int code; int offset; char *parsed; int err; int size; int ret; int state; char *system_ctype; table_t *table; struct stat table_stat; err = stat(filename, &table_stat); if (err == -1) { return NULL; } system_ctype = setlocale(LC_CTYPE, ""); if (system_ctype == NULL) { system_ctype = ""; // I don't think we can free the return from setlocale() } size = 0; if (table_stat.st_size > 0) { size = table_stat.st_size / LINE_LENGTH; } #ifdef HAVE_STRUCT_STAT_ST_BLOCKS else { size = (512 * table_stat.st_blocks) / LINE_LENGTH; } #endif if (size < 500) { size = 500; } table = table_init(size); if (table == NULL) { return NULL; } table_file = fopen(filename, "r"); if (table_file == NULL) { fprintf(stderr, "Unable to open translation table: %s\n", strerror(errno)); return NULL; } work = wrapped_malloc(1024); parsed = wrapped_malloc(1024); state = BASE_STATE; while (fgets(work, 1024, table_file) != NULL) { if (*work == '#') { /* * Don't even bother */ continue; } parsed[0] = '\0'; if (state == BASE_STATE) { ret = sscanf(work, " %s %n", parsed, &offset); if (ret == 0) { continue; } if (strncasecmp(parsed, "start", 5) == 0) { if (work[offset] == '\0') { // All languages state = INSIDE_STATE; continue; } if (work[offset] == '"') { sscanf(work + offset + 1, "%[^\"]", parsed); } else if (work[offset] == '\'') { sscanf(work + offset + 1, "%[^']", parsed); } else { sscanf(work + offset, "%s", parsed); } if (strncasecmp(parsed, system_ctype, strlen(parsed)) == 0) { state = INSIDE_STATE; } // else ignore this start/end block continue; } if (strncasecmp(parsed, "default", 7) == 0) { if (work[offset] == '\0') { table->default_translation = NULL; continue; } if (work[offset] == '"') { sscanf(work + offset + 1, "%[^\"]", parsed); } else if (work[offset] == '\'') { sscanf(work + offset + 1, "%[^']", parsed); } else { sscanf(work + offset, "%s", parsed); } table->default_translation = wrapped_strdup(parsed); continue; } continue; } /* * Inside state */ code = -1; ret = sscanf(work, "%i %n", &code, &offset); if (ret == 0 || code < 0 || offset < 0) { /* * Check for end */ ret = sscanf(work, " %s %n", parsed, &offset); if (ret > 0 && strncasecmp(parsed, "end", 5) == 0) { state = BASE_STATE; } continue; } if (work[offset] == '\0') { continue; } if (work[offset] == '"') { sscanf(work + offset + 1, "%[^\"]", parsed); } else if (work[offset] == '\'') { sscanf(work + offset + 1, "%[^']", parsed); } else { sscanf(work + offset, "%s", parsed); } ret = table_put(table, code, parsed); if (ret == -1) { fprintf(stderr, "Failed to add row 0x%04x \"%s\" to translation table\n", code, parsed); table_free(table); fclose(table_file); free(work); free(parsed); return NULL; } } free(work); free(parsed); fclose(table_file); return table; }
e68cc4ee3d431d64a8f3286550d8d87c06f7fe1b
3816f1ba0ff7eca9cc324f4ad5ac8c5b54028eeb
/source/src/ports/nvdata/conffile.c
771c6e6294d03ab3ad0fb29c5bd81bdf17fa2404
[ "BSD-3-Clause" ]
permissive
EIPStackGroup/OpENer
d70064ad8d99406afab648a5985aacf3f3ef38fe
fc0179e9969a85a20fb907e3043062755b7a38d2
refs/heads/master
2023-08-26T10:09:49.085224
2022-03-08T21:05:02
2023-07-11T16:57:43
12,129,915
573
263
NOASSERTION
2023-09-03T21:47:47
2013-08-15T08:22:41
C
UTF-8
C
false
false
3,712
c
conffile.c
/******************************************************************************* * Copyright (c) 2019, Rockwell Automation, Inc. * All rights reserved. * ******************************************************************************/ /** @file nvqos.c * @brief This file implements the functions to handle QoS object's NV data. * * This is only proof-of-concept code. Don't use it in a real product. * Please think about atomic update of the external file and doing something * like fsync() to flush the data really to disk. */ /* COMPILATION SWITCHES */ #define ENABLE_VERBOSE 0 /* Enable this to observe internal operation */ /* INCLUDES */ #include "conffile.h" #include <errno.h> #include <string.h> #if defined _WIN32 #include <direct.h> #else #include <sys/stat.h> #include <sys/types.h> #endif /* if defined _WIN32 */ #include "trace.h" #include "opener_error.h" /** Base path for configuration file store */ #define CFG_BASE "nvdata/" #if ENABLE_VERBOSE != 0 #define VERBOSE(pFile, pFmt, ...) do { fprintf(pFile, pFmt, ## __VA_ARGS__); \ } while (0) #else #define VERBOSE(pFile, pFmt, ...) #endif /** @brief Portable wrapper for mkdir(). Internally used by RecMkdir() * * @param[in] path the full path of the directory to create * @return zero on success, otherwise -1 and errno set */ static inline int Mkdir(const char *path) { #ifdef _WIN32 return _mkdir(path); #else /* The mode of 0777 will be constrained by umask. */ return mkdir(path, 0777); #endif } static void RecMkdir(char *const p_path) { char *sep = strrchr(p_path, '/' ); if(sep && p_path != sep) { /* "p_path != sep" avoids mkdir("/")! */ *sep = '\0'; RecMkdir(p_path); *sep = '/'; } VERBOSE(stdout, " ->mkdir('%s')", p_path); if(Mkdir(p_path) && EEXIST != errno) { char *error_message = GetErrorMessage(errno); OPENER_TRACE_ERR("error while trying to create '%s', %d - %s\n", p_path, errno, error_message); FreeErrorMessage(error_message); } } static FILE *FopenMkdir(char *p_path, char *mode) { char *sep = strrchr(p_path, '/' ); /* In write mode create missing directories. */ if(sep && 'w' == *mode) { *sep = '\0'; RecMkdir(p_path); *sep = '/'; VERBOSE(stdout, "%s", "\n"); } /* Disable VS fopen depreciation warning. */ #ifdef _MSC_VER #pragma warning(disable : 4996) #endif /* _MSC_VER */ return fopen(p_path, mode); /* Restore default depreciation warning behavior. */ #ifdef _MSC_VER #pragma warning(default : 4996) #endif /* _MSC_VER */ } /** @brief Open the named configuration file possibly for write operation * * @param write Open for write? * @param p_name pointer to file name string * @return valid file handle: success; NULL: failure, errno set * * This function open a configuration file, possibly for write operation, * in the NV data storage directory. */ FILE *ConfFileOpen(const bool write, const char *const p_name) { char path_buf[64]; int rc; rc = snprintf(path_buf, sizeof path_buf, "%s%s", CFG_BASE, p_name); if (rc > 0) { return FopenMkdir(path_buf, write ? "w" : "r"); } return NULL; } /** @brief Close the configuration file associated with the FILE* given * * @param p_filep pointer to FILE* to close * @return kEipStatusOk: success; kEipStatusError: failure and errno set * * Closes the configuration file associated to p_filep. No data * synchronization to disk yet. */ EipStatus ConfFileClose(FILE **p_filep) { EipStatus eip_status = kEipStatusOk; if( 0 != fclose(*p_filep) ) { eip_status = kEipStatusError; } *p_filep = NULL; return eip_status; }
5cd1e371c558b259a24e2b417fb4ec7caff29140
f085956afa0ff005e887a079eab410242865d831
/thirdparty/libatomic_ops/atomic_ops/sysdeps/ao_t_is_int.h
295998ef2c9b7f90da8473c2f0bf93a745fe7bf9
[ "MIT", "Boehm-GC", "GPL-1.0-or-later", "GPL-2.0-only" ]
permissive
vlang/v
844f108863477626a61bd7580a7fb8f3365ec3e5
93d54651b5aae1299239d30b1276439d8c142d88
refs/heads/master
2023-09-01T05:13:11.841452
2023-08-31T23:04:58
2023-08-31T23:04:58
169,677,297
38,639
3,871
MIT
2023-09-14T21:45:03
2019-02-08T02:57:06
V
UTF-8
C
false
false
23,584
h
ao_t_is_int.h
/* * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /* Inclusion of this file signifies that AO_t is in fact int. */ /* Hence any AO_... operation can also serve as AO_int_... operation. */ #if defined(AO_HAVE_load) && !defined(AO_HAVE_int_load) # define AO_int_load(addr) \ (unsigned)AO_load((const volatile AO_t *)(addr)) # define AO_HAVE_int_load #endif #if defined(AO_HAVE_store) && !defined(AO_HAVE_int_store) # define AO_int_store(addr, val) \ AO_store((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_store #endif #if defined(AO_HAVE_fetch_and_add) \ && !defined(AO_HAVE_int_fetch_and_add) # define AO_int_fetch_and_add(addr, incr) \ (unsigned)AO_fetch_and_add((volatile AO_t *)(addr), \ (AO_t)(incr)) # define AO_HAVE_int_fetch_and_add #endif #if defined(AO_HAVE_fetch_and_add1) \ && !defined(AO_HAVE_int_fetch_and_add1) # define AO_int_fetch_and_add1(addr) \ (unsigned)AO_fetch_and_add1((volatile AO_t *)(addr)) # define AO_HAVE_int_fetch_and_add1 #endif #if defined(AO_HAVE_fetch_and_sub1) \ && !defined(AO_HAVE_int_fetch_and_sub1) # define AO_int_fetch_and_sub1(addr) \ (unsigned)AO_fetch_and_sub1((volatile AO_t *)(addr)) # define AO_HAVE_int_fetch_and_sub1 #endif #if defined(AO_HAVE_and) && !defined(AO_HAVE_int_and) # define AO_int_and(addr, val) \ AO_and((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_and #endif #if defined(AO_HAVE_or) && !defined(AO_HAVE_int_or) # define AO_int_or(addr, val) \ AO_or((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_or #endif #if defined(AO_HAVE_xor) && !defined(AO_HAVE_int_xor) # define AO_int_xor(addr, val) \ AO_xor((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_xor #endif #if defined(AO_HAVE_fetch_compare_and_swap) \ && !defined(AO_HAVE_int_fetch_compare_and_swap) # define AO_int_fetch_compare_and_swap(addr, old, new_val) \ (unsigned)AO_fetch_compare_and_swap((volatile AO_t *)(addr), \ (AO_t)(old), (AO_t)(new_val)) # define AO_HAVE_int_fetch_compare_and_swap #endif #if defined(AO_HAVE_compare_and_swap) \ && !defined(AO_HAVE_int_compare_and_swap) # define AO_int_compare_and_swap(addr, old, new_val) \ AO_compare_and_swap((volatile AO_t *)(addr), \ (AO_t)(old), (AO_t)(new_val)) # define AO_HAVE_int_compare_and_swap #endif /* * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /* Inclusion of this file signifies that AO_t is in fact int. */ /* Hence any AO_... operation can also serve as AO_int_... operation. */ #if defined(AO_HAVE_load_full) && !defined(AO_HAVE_int_load_full) # define AO_int_load_full(addr) \ (unsigned)AO_load_full((const volatile AO_t *)(addr)) # define AO_HAVE_int_load_full #endif #if defined(AO_HAVE_store_full) && !defined(AO_HAVE_int_store_full) # define AO_int_store_full(addr, val) \ AO_store_full((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_store_full #endif #if defined(AO_HAVE_fetch_and_add_full) \ && !defined(AO_HAVE_int_fetch_and_add_full) # define AO_int_fetch_and_add_full(addr, incr) \ (unsigned)AO_fetch_and_add_full((volatile AO_t *)(addr), \ (AO_t)(incr)) # define AO_HAVE_int_fetch_and_add_full #endif #if defined(AO_HAVE_fetch_and_add1_full) \ && !defined(AO_HAVE_int_fetch_and_add1_full) # define AO_int_fetch_and_add1_full(addr) \ (unsigned)AO_fetch_and_add1_full((volatile AO_t *)(addr)) # define AO_HAVE_int_fetch_and_add1_full #endif #if defined(AO_HAVE_fetch_and_sub1_full) \ && !defined(AO_HAVE_int_fetch_and_sub1_full) # define AO_int_fetch_and_sub1_full(addr) \ (unsigned)AO_fetch_and_sub1_full((volatile AO_t *)(addr)) # define AO_HAVE_int_fetch_and_sub1_full #endif #if defined(AO_HAVE_and_full) && !defined(AO_HAVE_int_and_full) # define AO_int_and_full(addr, val) \ AO_and_full((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_and_full #endif #if defined(AO_HAVE_or_full) && !defined(AO_HAVE_int_or_full) # define AO_int_or_full(addr, val) \ AO_or_full((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_or_full #endif #if defined(AO_HAVE_xor_full) && !defined(AO_HAVE_int_xor_full) # define AO_int_xor_full(addr, val) \ AO_xor_full((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_xor_full #endif #if defined(AO_HAVE_fetch_compare_and_swap_full) \ && !defined(AO_HAVE_int_fetch_compare_and_swap_full) # define AO_int_fetch_compare_and_swap_full(addr, old, new_val) \ (unsigned)AO_fetch_compare_and_swap_full((volatile AO_t *)(addr), \ (AO_t)(old), (AO_t)(new_val)) # define AO_HAVE_int_fetch_compare_and_swap_full #endif #if defined(AO_HAVE_compare_and_swap_full) \ && !defined(AO_HAVE_int_compare_and_swap_full) # define AO_int_compare_and_swap_full(addr, old, new_val) \ AO_compare_and_swap_full((volatile AO_t *)(addr), \ (AO_t)(old), (AO_t)(new_val)) # define AO_HAVE_int_compare_and_swap_full #endif /* * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /* Inclusion of this file signifies that AO_t is in fact int. */ /* Hence any AO_... operation can also serve as AO_int_... operation. */ #if defined(AO_HAVE_load_acquire) && !defined(AO_HAVE_int_load_acquire) # define AO_int_load_acquire(addr) \ (unsigned)AO_load_acquire((const volatile AO_t *)(addr)) # define AO_HAVE_int_load_acquire #endif #if defined(AO_HAVE_store_acquire) && !defined(AO_HAVE_int_store_acquire) # define AO_int_store_acquire(addr, val) \ AO_store_acquire((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_store_acquire #endif #if defined(AO_HAVE_fetch_and_add_acquire) \ && !defined(AO_HAVE_int_fetch_and_add_acquire) # define AO_int_fetch_and_add_acquire(addr, incr) \ (unsigned)AO_fetch_and_add_acquire((volatile AO_t *)(addr), \ (AO_t)(incr)) # define AO_HAVE_int_fetch_and_add_acquire #endif #if defined(AO_HAVE_fetch_and_add1_acquire) \ && !defined(AO_HAVE_int_fetch_and_add1_acquire) # define AO_int_fetch_and_add1_acquire(addr) \ (unsigned)AO_fetch_and_add1_acquire((volatile AO_t *)(addr)) # define AO_HAVE_int_fetch_and_add1_acquire #endif #if defined(AO_HAVE_fetch_and_sub1_acquire) \ && !defined(AO_HAVE_int_fetch_and_sub1_acquire) # define AO_int_fetch_and_sub1_acquire(addr) \ (unsigned)AO_fetch_and_sub1_acquire((volatile AO_t *)(addr)) # define AO_HAVE_int_fetch_and_sub1_acquire #endif #if defined(AO_HAVE_and_acquire) && !defined(AO_HAVE_int_and_acquire) # define AO_int_and_acquire(addr, val) \ AO_and_acquire((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_and_acquire #endif #if defined(AO_HAVE_or_acquire) && !defined(AO_HAVE_int_or_acquire) # define AO_int_or_acquire(addr, val) \ AO_or_acquire((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_or_acquire #endif #if defined(AO_HAVE_xor_acquire) && !defined(AO_HAVE_int_xor_acquire) # define AO_int_xor_acquire(addr, val) \ AO_xor_acquire((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_xor_acquire #endif #if defined(AO_HAVE_fetch_compare_and_swap_acquire) \ && !defined(AO_HAVE_int_fetch_compare_and_swap_acquire) # define AO_int_fetch_compare_and_swap_acquire(addr, old, new_val) \ (unsigned)AO_fetch_compare_and_swap_acquire((volatile AO_t *)(addr), \ (AO_t)(old), (AO_t)(new_val)) # define AO_HAVE_int_fetch_compare_and_swap_acquire #endif #if defined(AO_HAVE_compare_and_swap_acquire) \ && !defined(AO_HAVE_int_compare_and_swap_acquire) # define AO_int_compare_and_swap_acquire(addr, old, new_val) \ AO_compare_and_swap_acquire((volatile AO_t *)(addr), \ (AO_t)(old), (AO_t)(new_val)) # define AO_HAVE_int_compare_and_swap_acquire #endif /* * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /* Inclusion of this file signifies that AO_t is in fact int. */ /* Hence any AO_... operation can also serve as AO_int_... operation. */ #if defined(AO_HAVE_load_release) && !defined(AO_HAVE_int_load_release) # define AO_int_load_release(addr) \ (unsigned)AO_load_release((const volatile AO_t *)(addr)) # define AO_HAVE_int_load_release #endif #if defined(AO_HAVE_store_release) && !defined(AO_HAVE_int_store_release) # define AO_int_store_release(addr, val) \ AO_store_release((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_store_release #endif #if defined(AO_HAVE_fetch_and_add_release) \ && !defined(AO_HAVE_int_fetch_and_add_release) # define AO_int_fetch_and_add_release(addr, incr) \ (unsigned)AO_fetch_and_add_release((volatile AO_t *)(addr), \ (AO_t)(incr)) # define AO_HAVE_int_fetch_and_add_release #endif #if defined(AO_HAVE_fetch_and_add1_release) \ && !defined(AO_HAVE_int_fetch_and_add1_release) # define AO_int_fetch_and_add1_release(addr) \ (unsigned)AO_fetch_and_add1_release((volatile AO_t *)(addr)) # define AO_HAVE_int_fetch_and_add1_release #endif #if defined(AO_HAVE_fetch_and_sub1_release) \ && !defined(AO_HAVE_int_fetch_and_sub1_release) # define AO_int_fetch_and_sub1_release(addr) \ (unsigned)AO_fetch_and_sub1_release((volatile AO_t *)(addr)) # define AO_HAVE_int_fetch_and_sub1_release #endif #if defined(AO_HAVE_and_release) && !defined(AO_HAVE_int_and_release) # define AO_int_and_release(addr, val) \ AO_and_release((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_and_release #endif #if defined(AO_HAVE_or_release) && !defined(AO_HAVE_int_or_release) # define AO_int_or_release(addr, val) \ AO_or_release((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_or_release #endif #if defined(AO_HAVE_xor_release) && !defined(AO_HAVE_int_xor_release) # define AO_int_xor_release(addr, val) \ AO_xor_release((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_xor_release #endif #if defined(AO_HAVE_fetch_compare_and_swap_release) \ && !defined(AO_HAVE_int_fetch_compare_and_swap_release) # define AO_int_fetch_compare_and_swap_release(addr, old, new_val) \ (unsigned)AO_fetch_compare_and_swap_release((volatile AO_t *)(addr), \ (AO_t)(old), (AO_t)(new_val)) # define AO_HAVE_int_fetch_compare_and_swap_release #endif #if defined(AO_HAVE_compare_and_swap_release) \ && !defined(AO_HAVE_int_compare_and_swap_release) # define AO_int_compare_and_swap_release(addr, old, new_val) \ AO_compare_and_swap_release((volatile AO_t *)(addr), \ (AO_t)(old), (AO_t)(new_val)) # define AO_HAVE_int_compare_and_swap_release #endif /* * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /* Inclusion of this file signifies that AO_t is in fact int. */ /* Hence any AO_... operation can also serve as AO_int_... operation. */ #if defined(AO_HAVE_load_write) && !defined(AO_HAVE_int_load_write) # define AO_int_load_write(addr) \ (unsigned)AO_load_write((const volatile AO_t *)(addr)) # define AO_HAVE_int_load_write #endif #if defined(AO_HAVE_store_write) && !defined(AO_HAVE_int_store_write) # define AO_int_store_write(addr, val) \ AO_store_write((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_store_write #endif #if defined(AO_HAVE_fetch_and_add_write) \ && !defined(AO_HAVE_int_fetch_and_add_write) # define AO_int_fetch_and_add_write(addr, incr) \ (unsigned)AO_fetch_and_add_write((volatile AO_t *)(addr), \ (AO_t)(incr)) # define AO_HAVE_int_fetch_and_add_write #endif #if defined(AO_HAVE_fetch_and_add1_write) \ && !defined(AO_HAVE_int_fetch_and_add1_write) # define AO_int_fetch_and_add1_write(addr) \ (unsigned)AO_fetch_and_add1_write((volatile AO_t *)(addr)) # define AO_HAVE_int_fetch_and_add1_write #endif #if defined(AO_HAVE_fetch_and_sub1_write) \ && !defined(AO_HAVE_int_fetch_and_sub1_write) # define AO_int_fetch_and_sub1_write(addr) \ (unsigned)AO_fetch_and_sub1_write((volatile AO_t *)(addr)) # define AO_HAVE_int_fetch_and_sub1_write #endif #if defined(AO_HAVE_and_write) && !defined(AO_HAVE_int_and_write) # define AO_int_and_write(addr, val) \ AO_and_write((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_and_write #endif #if defined(AO_HAVE_or_write) && !defined(AO_HAVE_int_or_write) # define AO_int_or_write(addr, val) \ AO_or_write((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_or_write #endif #if defined(AO_HAVE_xor_write) && !defined(AO_HAVE_int_xor_write) # define AO_int_xor_write(addr, val) \ AO_xor_write((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_xor_write #endif #if defined(AO_HAVE_fetch_compare_and_swap_write) \ && !defined(AO_HAVE_int_fetch_compare_and_swap_write) # define AO_int_fetch_compare_and_swap_write(addr, old, new_val) \ (unsigned)AO_fetch_compare_and_swap_write((volatile AO_t *)(addr), \ (AO_t)(old), (AO_t)(new_val)) # define AO_HAVE_int_fetch_compare_and_swap_write #endif #if defined(AO_HAVE_compare_and_swap_write) \ && !defined(AO_HAVE_int_compare_and_swap_write) # define AO_int_compare_and_swap_write(addr, old, new_val) \ AO_compare_and_swap_write((volatile AO_t *)(addr), \ (AO_t)(old), (AO_t)(new_val)) # define AO_HAVE_int_compare_and_swap_write #endif /* * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /* Inclusion of this file signifies that AO_t is in fact int. */ /* Hence any AO_... operation can also serve as AO_int_... operation. */ #if defined(AO_HAVE_load_read) && !defined(AO_HAVE_int_load_read) # define AO_int_load_read(addr) \ (unsigned)AO_load_read((const volatile AO_t *)(addr)) # define AO_HAVE_int_load_read #endif #if defined(AO_HAVE_store_read) && !defined(AO_HAVE_int_store_read) # define AO_int_store_read(addr, val) \ AO_store_read((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_store_read #endif #if defined(AO_HAVE_fetch_and_add_read) \ && !defined(AO_HAVE_int_fetch_and_add_read) # define AO_int_fetch_and_add_read(addr, incr) \ (unsigned)AO_fetch_and_add_read((volatile AO_t *)(addr), \ (AO_t)(incr)) # define AO_HAVE_int_fetch_and_add_read #endif #if defined(AO_HAVE_fetch_and_add1_read) \ && !defined(AO_HAVE_int_fetch_and_add1_read) # define AO_int_fetch_and_add1_read(addr) \ (unsigned)AO_fetch_and_add1_read((volatile AO_t *)(addr)) # define AO_HAVE_int_fetch_and_add1_read #endif #if defined(AO_HAVE_fetch_and_sub1_read) \ && !defined(AO_HAVE_int_fetch_and_sub1_read) # define AO_int_fetch_and_sub1_read(addr) \ (unsigned)AO_fetch_and_sub1_read((volatile AO_t *)(addr)) # define AO_HAVE_int_fetch_and_sub1_read #endif #if defined(AO_HAVE_and_read) && !defined(AO_HAVE_int_and_read) # define AO_int_and_read(addr, val) \ AO_and_read((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_and_read #endif #if defined(AO_HAVE_or_read) && !defined(AO_HAVE_int_or_read) # define AO_int_or_read(addr, val) \ AO_or_read((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_or_read #endif #if defined(AO_HAVE_xor_read) && !defined(AO_HAVE_int_xor_read) # define AO_int_xor_read(addr, val) \ AO_xor_read((volatile AO_t *)(addr), (AO_t)(val)) # define AO_HAVE_int_xor_read #endif #if defined(AO_HAVE_fetch_compare_and_swap_read) \ && !defined(AO_HAVE_int_fetch_compare_and_swap_read) # define AO_int_fetch_compare_and_swap_read(addr, old, new_val) \ (unsigned)AO_fetch_compare_and_swap_read((volatile AO_t *)(addr), \ (AO_t)(old), (AO_t)(new_val)) # define AO_HAVE_int_fetch_compare_and_swap_read #endif #if defined(AO_HAVE_compare_and_swap_read) \ && !defined(AO_HAVE_int_compare_and_swap_read) # define AO_int_compare_and_swap_read(addr, old, new_val) \ AO_compare_and_swap_read((volatile AO_t *)(addr), \ (AO_t)(old), (AO_t)(new_val)) # define AO_HAVE_int_compare_and_swap_read #endif
397af5cd8c5a428362781da5b6c675e3709ebe38
376e1818d427b5e4d32fa6dd6c7b71e9fd88afdb
/editors/xwpe/patches/patch-edit.h
09e0c6d321c9d1ee8f9e9abd418f06a124b29433
[]
no_license
NetBSD/pkgsrc
a0732c023519650ef821ab89c23ab6ab59e25bdb
d042034ec4896cc5b47ed6f2e5b8802d9bc5c556
refs/heads/trunk
2023-09-01T07:40:12.138283
2023-09-01T05:25:19
2023-09-01T05:25:19
88,439,572
321
138
null
2023-07-12T22:34:14
2017-04-16T20:04:15
null
UTF-8
C
false
false
339
h
patch-edit.h
$NetBSD: patch-edit.h,v 1.2 2022/12/08 10:31:08 vins Exp $ Fix typo in int declaration. --- edit.h.orig 2005-07-07 01:53:09.000000000 +0000 +++ edit.h @@ -793,7 +793,7 @@ int e_d_reinit_watches(FENSTER *f,char * /* we_gpm.c */ #ifdef HAVE_LIBGPM -int WpeGpmInit(void); +int WpeGpmMouseInit(void); int WpeGpmMouse(int *g); #endif
032d7c4482c64622355a214c03379f1fbac849ca
41eb0837713f297134529591b66f3d4d82bcf98e
/src/Raine/source/games/taitosnd.c
12ee0b8fd2740fed7c626f919dc12d642b1a64ca
[]
no_license
AlexxandreFS/Batocera.PLUS
27b196b3cbb781b6fc99e62cad855396d1d5f8f2
997ee763ae7135fdf0c34a081e789918bd2eb169
refs/heads/master
2023-08-17T21:52:39.083687
2023-08-17T15:03:44
2023-08-17T15:03:44
215,869,486
135
57
null
2023-08-14T14:46:14
2019-10-17T19:23:42
C
UTF-8
C
false
false
31,679
c
taitosnd.c
/******************************************************************************/ /* */ /* TAITO SOUND SYSTEMS (C) 1986-1996 TAITO CORPORATION */ /* */ /******************************************************************************/ /* answer of hiroshi ----------------- YM30?? series is Serial DAC convertor. FM chip output is Serial DAC. This DAC input to YM30??. It change to Analog data. Antiriad: Thanks!! Changes ------- 17-02-99: - Reduce volume of YM2151 emulation. 11-02-99: - z80 emulator and banking was changed some days ago... - added tc0140syt_reset() calls. 18-01-99: - tc0140syt emulation is moved to tc140syt.c/h. 14-01-99: - Merge changes from Hiroshi source (M6295 bank, ym2151: reg -> reg2151). 09-01-99: - Add debug message if 68000 sends data before z80 has read the current data. 27-12-98: - Add Hiroshi changes (Volume and Panning). - What is YM3016? Is this the chip for panning/volume control? 17-12-98: - Added latest Hiro-Shi changes. - Removed YM2610_Frame(), no longer needed. - Removed Z80 debug as there is already Z80 bad read/write/io routines in mz80help.c. 16-12-98: - Added YM2203 (Taito B-System). Used by Master of Weapons etc... */ #include "gameinc.h" #include "taitosnd.h" #include "fm.h" #include "sasound.h" // sample support routines #include "2610intf.h" #include "2151intf.h" #include "2203intf.h" #include "adpcm.h" #include "timer.h" #include "streams.h" static UINT8 *ROMBANK=NULL; // Pointer to start of z80 rom bank data static UINT8 *BANKLIST[8]; // Pointers to start of each bank (0-7) /************************************************************/ // YM2151 Handler // -------------- static int reg2151; UINT16 YM2151ReadZ80(UINT16 offset) { #if 0 if( (offset&0x01) ){ return YM2151_status_port_0_r(0); } else return 0; #else static int ta=0; ta^=255; return(ta); #endif } UINT16 YM2151ReadZ80_Timer(UINT16 offset) { #if 1 if( (offset&0x01) ){ return YM2151_status_port_0_r(0); } else return 0; #else static int ta=0; ta^=255; return(ta); #endif } void YM2151WriteZ80(UINT16 offset, UINT8 data) { if((offset&1)==0){ reg2151=data; } else{ YM2151_register_port_0_w(offset,reg2151); // It's faster to wait for the data like this!! YM2151_data_port_0_w(offset,data); } } // Banking via YM2151 - TAITO void YM2151TaitoWriteZ80(UINT16 offset, UINT8 data) { if((offset&1)==0){ reg2151=data; } else{ if(reg2151==0x1B){ TaitoSoundSetBank(offset, (UINT8) ((data>>6)&3) ); } YM2151_register_port_0_w(offset,reg2151); // It's faster to wait for the data like this!! YM2151_data_port_0_w(offset,data); } } /************************************************************/ // YM2203A Handler // --------------- UINT16 YM2203AReadZ80(UINT16 offset) { #if 0 if((offset&1)==0){ return YM2203_status_port_0_r(0); } else{ return YM2203_read_port_0_r(0); } #else static int ta=0; ta^=255; return(ta); #endif } void YM2203AWriteZ80(UINT16 offset, UINT8 data) { static int reg; if((offset&1)==0){ reg=data; } else{ YM2203_control_port_0_w(offset,reg); YM2203_write_port_0_w(offset,data); } } // Banking via YM2203 - TAITO void YM2203ATaitoWriteZ80(UINT16 offset, UINT8 data) { static int reg; if((offset&1)==0){ reg=data; } else{ if(reg==0x0E){ TaitoSoundSetBank(offset, (UINT8) (data&3) ); } YM2203_control_port_0_w(offset,reg); YM2203_write_port_0_w(offset,data); } } // YM2203A Handler // --------------- UINT16 YM2203BReadZ80(UINT16 offset) { #if 0 if((offset&1)==0){ return YM2203_status_port_1_r(0); } else{ return YM2203_read_port_1_r(0); } #else // Cadash and Rainbow Extra only work with this code>>> static int ta=0; ta^=255; return(ta); #endif } void YM2203BWriteZ80(UINT16 offset, UINT8 data) { static int reg; if((offset&1)==0){ reg=data; } else{ YM2203_control_port_1_w(offset,reg); YM2203_write_port_1_w(offset,data); } } /************************************************************ Taito Z80+YM2610 Interface -------------------------- For 99% of Taito sound Z80s using a YM2610 ************************************************************/ // YM2610 Handler // -------------- UINT16 YM2610ReadZ80(UINT16 offset) { #if 1 switch(offset&3){ case 0x00: return(YM2610_status_port_0_A_r(offset)); case 0x01: return(YM2610_read_port_0_r(offset)); case 0x02: return(YM2610_status_port_0_B_r(offset)); default: return(YM2610_read_port_0_r(offset)); } #else static int ta=0; ta^=255; return(ta); #endif } UINT16 YM2610ReadZ80SP(UINT16 offset){ // Speed patch static int ta = 0; switch(offset&3){ case 0x00: ta ^= 0x03; return YM2610_status_port_0_A_r(offset) | ta; //return(YM2610_status_port_0_A_r(offset)); case 0x02: return(YM2610_status_port_0_B_r(offset)); break; default: return(YM2610_read_port_0_r(offset)); break; } } void YM2610WriteZ80(UINT16 offset, UINT8 data) { switch(offset&3){ case 0x00: YM2610_control_port_0_A_w(offset,data); break; case 0x01: YM2610_data_port_0_A_w(offset,data); break; case 0x02: YM2610_control_port_0_B_w(offset,data); break; default: YM2610_data_port_0_B_w(offset,data); break; } } static int taitoym2610pan[4]; void Pan2610WriteZ80(UINT16 offset, UINT8 data){ int vol, pan, cen; taitoym2610pan[offset&0x03] = data&0x00ff; if( !(offset&0x02) ){ /**** channel 0 (YM3016 Left channel) ****/ if( taitoym2610pan[0] > taitoym2610pan[1] ) pan = taitoym2610pan[0]; else pan = taitoym2610pan[1]; if (pan == 0x1f) pan = 0xff; vol = (taitoym2610pan[0] + taitoym2610pan[1]) / 2; if( pan ){ pan = 0x80 + (((0x7f00/pan) * (taitoym2610pan[0] - taitoym2610pan[1]))>>8); cen = pan < 0x80 ? 0x80 - pan : -(0x80 - pan); vol = vol - ((vol * cen)>>(8)); // vol is sometimes 0x1f. It is a bad mapping if (vol == 0x1f) vol = 0xff; stream_set_volume( YM2610_get_stream_num(0), vol ); stream_set_pan( YM2610_get_stream_num(0), pan ); //print_ingame(120,gettext("Make ch0 vol:%02x pan:%02x"), vol, pan ); } else{ if (vol == 0x1f) vol = 0xff; stream_set_volume( YM2610_get_stream_num(0), vol>>1 ); stream_set_pan( YM2610_get_stream_num(0), 0x80 ); /* center */ } } else{ /**** channel 1 (YM3016 Right channel) ****/ if( taitoym2610pan[2] > taitoym2610pan[3] ) pan = taitoym2610pan[2]; else pan = taitoym2610pan[3]; if (pan == 0x1f) pan = 0xff; vol = (taitoym2610pan[2] + taitoym2610pan[3]) / 2; if( pan ){ pan = 0x80 + (((0x7f00/pan) * (taitoym2610pan[2] - taitoym2610pan[3]))>>8); cen = pan < 0x80 ? 0x80 - pan : -(0x80 - pan); vol = vol - ((vol * cen)>>(8)); if (vol == 0x1f) vol = 0xff; stream_set_volume( YM2610_get_stream_num(0)+1, vol ); stream_set_pan( YM2610_get_stream_num(0)+1, pan ); //print_ingame(120,gettext("Make ch1 vol:%02x pan:%02x"), vol, pan ); } else{ if (vol == 0x1f) vol = 0xff; stream_set_volume( YM2610_get_stream_num(0)+1, vol>>1 ); stream_set_pan( YM2610_get_stream_num(0)+1, 0x80 ); /* center */ } } } static int volume_offset; void Pan2610_OffsetVol( int data ){ volume_offset = data; } void Pan2610WriteZ80_OffsetVol(UINT16 offset, UINT8 data){ int vol, pan, cen; taitoym2610pan[offset&0x03] = data&0x00ff; if( !(offset&0x02) ){ /**** channel 0 (YM3016 Left channel) ****/ if( taitoym2610pan[0] > taitoym2610pan[1] ) pan = taitoym2610pan[0]; else pan = taitoym2610pan[1]; if (pan == 0x1f) pan = 0xff; vol = ((taitoym2610pan[0] + taitoym2610pan[1]) / 2)<<volume_offset; if( pan ){ pan = 0x80 + (((0x7f00/pan) * (taitoym2610pan[0] - taitoym2610pan[1]))>>8); cen = pan < 0x80 ? 0x80 - pan : -(0x80 - pan); vol = vol - ((vol * cen)>>(8)); if (vol == 0x1f) vol = 0xff; stream_set_volume( YM2610_get_stream_num(0), vol ); stream_set_pan( YM2610_get_stream_num(0), pan ); //print_ingame(120,gettext("Make ch0 vol:%02x pan:%02x"), vol, pan ); } else{ if (vol == 0x1f) vol = 0xff; stream_set_volume( YM2610_get_stream_num(0), vol>>1 ); stream_set_pan( YM2610_get_stream_num(0), 0x80 ); /* center */ } } else{ /**** channel 1 (YM3016 Right channel) ****/ if( taitoym2610pan[2] > taitoym2610pan[3] ) pan = taitoym2610pan[2]; else pan = taitoym2610pan[3]; if (pan == 0x1f) pan = 0xff; vol = ((taitoym2610pan[2] + taitoym2610pan[3]) / 2)<<volume_offset; if( pan ){ pan = 0x80 + (((0x7f00/pan) * (taitoym2610pan[2] - taitoym2610pan[3]))>>8); cen = pan < 0x80 ? 0x80 - pan : -(0x80 - pan); vol = vol - ((vol * cen)>>(8)); if (vol == 0x1f) vol = 0xff; stream_set_volume( YM2610_get_stream_num(0)+1, vol ); stream_set_pan( YM2610_get_stream_num(0)+1, pan ); //print_ingame(120,gettext("Make ch1 vol:%02x pan:%02x"), vol, pan ); } else{ if (vol == 0x1f) vol = 0xff; stream_set_volume( YM2610_get_stream_num(0)+1, vol>>1 ); stream_set_pan( YM2610_get_stream_num(0)+1, 0x80 ); /* center */ } } } static UINT8 TYM = 0x07; UINT16 TaitoYM2610Test(UINT16 offset){ return TYM; } static struct YM2610interface ym2610_interface = { 1, 8000000, { (100 | (OSD_PAN_CENTER<<8) ) }, { 0 }, { 0 }, { 0 }, { 0 }, { z80_irq_handler }, { REGION_SOUND2 }, /* Delta-T */ { REGION_SOUND1 }, /* ADPCM */ { YM3012_VOL(255,OSD_PAN_LEFT,255,OSD_PAN_RIGHT) }, }; struct SOUND_INFO taito_ym2610_sound[] = { { SOUND_YM2610, &ym2610_interface, }, { 0, NULL, }, }; // the ay8910 emits an annoying sound as soon as the race starts // no idea why, but the easiest solution is to mute it ! static struct YM2610interface ym2610_interface_mute_ay8910 = { 1, 8000000, { YM2203_VOL(0,0) }, { 0 }, { 0 }, { 0 }, { 0 }, { z80_irq_handler }, { REGION_SOUND2 }, /* Delta-T */ { REGION_SOUND1 }, /* ADPCM */ { YM3012_VOL(255,OSD_PAN_LEFT,255,OSD_PAN_RIGHT) }, }; struct SOUND_INFO contcirc_ym2610_sound[] = { { SOUND_YM2610, &ym2610_interface_mute_ay8910, }, { 0, NULL, }, }; struct SOUND_INFO taito_ym2610b_sound[] = { { SOUND_YM2610B, &ym2610_interface, }, { 0, NULL, }, }; /**** not pan control (lock volume) ****/ void Taito2610_Frame(void){ //cpu_execute_cycles(CPU_Z80_0, (4000000/60)*2); // Sound Z80 execute_z80_audio_frame(); // How short ! } /*******************************************************/ /* YM2610 mem map control (normal type) */ /*******************************************************/ void TaitoYM2610Memmap( void ) { /* The z80 ram is in the middle of the rom banks ! This has been done by Antiriad, which means that the z80 ram is not saved in the savegames Since the ym2610 is not saved neither yet, it does not seem to make any harm. It does not overwrite any code because the rom has been copyed to banks before that */ /* UINT8 *z80ram = RAM + RAMSize; */ /* RAMSize += 0x2000; */ AddZ80AROMBase(Z80ROM, 0x0038, 0x0066); AddZ80AReadByte(0x0000, 0x7FFF, NULL, NULL); // BANK ROM AddZ80AReadByte(0xC000, 0xDFFF, NULL, Z80ROM+0x00C000); // Z80 RAM AddZ80AReadByte(0xE000, 0xE003, YM2610ReadZ80, NULL); // YM2610 AddZ80AReadByte(0xE200, 0xE201, tc0140syt_read_sub_z80, NULL); // 68000 COMM AddZ80AReadByte(0xEA00, 0xEA00, TaitoYM2610Test, NULL); AddZ80AReadByte(0x0000, 0xFFFF, DefBadReadZ80, NULL); AddZ80AReadByte( -1, -1, NULL, NULL); AddZ80AWriteByte(0xC000, 0xDFFF, NULL, Z80ROM+0x00C000); // Z80 RAM AddZ80AWriteByte(0xE000, 0xE003, YM2610WriteZ80, NULL); // YM2610 AddZ80AWriteByte(0xE200, 0xE201, tc0140syt_write_sub_z80, NULL); // 68000 COMM if (!is_current_game("psyforce")) AddZ80AWriteByte(0xE400, 0xE403, Pan2610WriteZ80, NULL); // PANNING AddZ80AWriteByte(0xF200, 0xF200, TaitoSoundSetBank, NULL); // BANK SELECT AddZ80AWriteByte(0x0000, 0xFFFF, DefBadWriteZ80, NULL); AddZ80AWriteByte( -1, -1, NULL, NULL); AddZ80AReadPort(0x00, 0xFF, DefBadReadZ80, NULL); AddZ80AReadPort( -1, -1, NULL, NULL); AddZ80AWritePort(0xAA, 0xAA, StopZ80Mode2, NULL); AddZ80AWritePort(0x00, 0xFF, DefBadWriteZ80, NULL); AddZ80AWritePort( -1, -1, NULL, NULL); AddZ80AInit(); TaitoSoundSetBank(0,1); taitoym2610pan[0] = 0x00; taitoym2610pan[1] = 0x00; taitoym2610pan[2] = 0x00; taitoym2610pan[3] = 0x00; tc0140syt_reset(); } /*******************************************************/ /* YM2610 mem map control (normal type) */ /*******************************************************/ void TaitoYM2610MemmapOffsetVol( void ) { AddZ80AROMBase(Z80ROM, 0x0038, 0x0066); AddZ80AReadByte(0x0000, 0x7FFF, NULL, NULL); // BANK ROM AddZ80AReadByte(0xC000, 0xDFFF, NULL, Z80ROM+0x00C000); // Z80 RAM AddZ80AReadByte(0xE000, 0xE003, YM2610ReadZ80, NULL); // YM2610 AddZ80AReadByte(0xE200, 0xE201, tc0140syt_read_sub_z80, NULL); // 68000 COMM AddZ80AReadByte(0xEA00, 0xEA00, TaitoYM2610Test, NULL); AddZ80AReadByte(0x0000, 0xFFFF, DefBadReadZ80, NULL); AddZ80AReadByte( -1, -1, NULL, NULL); AddZ80AWriteByte(0xC000, 0xDFFF, NULL, Z80ROM+0x00C000); // Z80 RAM AddZ80AWriteByte(0xE000, 0xE003, YM2610WriteZ80, NULL); // YM2610 AddZ80AWriteByte(0xE200, 0xE201, tc0140syt_write_sub_z80, NULL); // 68000 COMM AddZ80AWriteByte(0xE400, 0xE403, Pan2610WriteZ80_OffsetVol, NULL); // PANNING AddZ80AWriteByte(0xF200, 0xF200, TaitoSoundSetBank, NULL); // BANK SELECT AddZ80AWriteByte(0x0000, 0xFFFF, DefBadWriteZ80, NULL); AddZ80AWriteByte( -1, -1, NULL, NULL); AddZ80AReadPort(0x00, 0xFF, DefBadReadZ80, NULL); AddZ80AReadPort( -1, -1, NULL, NULL); AddZ80AWritePort(0xAA, 0xAA, StopZ80Mode2, NULL); AddZ80AWritePort(0x00, 0xFF, DefBadWriteZ80, NULL); AddZ80AWritePort( -1, -1, NULL, NULL); AddZ80AInit(); TaitoSoundSetBank(0,1); taitoym2610pan[0] = 0x00; taitoym2610pan[1] = 0x00; taitoym2610pan[2] = 0x00; taitoym2610pan[3] = 0x00; tc0140syt_reset(); } /*******************************************************/ /* YM2610 sound system init */ /*******************************************************/ void AddTaitoYM2610(UINT32 p1, UINT32 p2, UINT32 romsize){ // Apply Speed Patch // ----------------- print_debug( "AddYM2610System\n" ); if (p1) { Z80ROM[p1+0]=0xD3; // OUTA (AAh) Z80ROM[p1+1]=0xAA; // SetStopZ80Mode2( (UINT16) p2); } // Setup rom banking system // ------------------------ AddTaitoSoundBanking( Z80ROM, romsize ); // Setup Z80 memory map // -------------------- TaitoYM2610Memmap(); print_debug( "AddYM2610System end\n" ); } /*******************************************************/ /* YM2610B sound system init */ /*******************************************************/ void AddTaitoYM2610B(UINT32 p1, UINT32 p2, UINT32 romsize){ // Apply Speed Patch // ----------------- print_debug( "AddYM2610System\n" ); Z80ROM[p1+0]=0xD3; // OUTA (AAh) Z80ROM[p1+1]=0xAA; // SetStopZ80Mode2( (UINT16) p2); // Setup rom banking system // ------------------------ AddTaitoSoundBanking( Z80ROM, romsize ); // Setup Z80 memory map // -------------------- TaitoYM2610Memmap(); print_debug( "AddYM2610System end\n" ); } /*******************************************************/ /* YM2610B sound system init */ /*******************************************************/ void AddTaitoYM2610B_OffsetVol(UINT32 p1, UINT32 p2, UINT32 romsize, int vol){ // Apply Speed Patch // ----------------- print_debug( "AddYM2610System\n" ); Z80ROM[p1+0]=0xD3; // OUTA (AAh) Z80ROM[p1+1]=0xAA; // SetStopZ80Mode2( (UINT16) p2); // Setup rom banking system // ------------------------ AddTaitoSoundBanking( Z80ROM, romsize ); // Setup Z80 memory map // -------------------- TaitoYM2610MemmapOffsetVol(); Pan2610_OffsetVol( vol ); /* set volume shift size */ print_debug( "AddYM2610System end\n" ); } /************************************************************/ /************************************************************/ void RemoveTaitoYM2610(void) { RemoveTaitoSoundBanking(); } #if 0 static void TaitoYM2151WriteBank( int ctw ){ //print_ingame(120,gettext("NowBank = %02x"), ctw ); TaitoSoundSetBank( 0, (UINT8) (ctw&0x03) ); /* bank change */ } static void TaitoYM2151_irq_handler(void){ //print_ingame(120,gettext("IRQ") ); //cpu_interrupt(CPU_Z80_0, 0x0038); } #endif static struct YM2151interface ym2151_interface = { 1, // 1 chip 4000000, // 4 MHz { YM3012_VOL(160,OSD_PAN_LEFT,160,OSD_PAN_RIGHT) }, { z80_irq_handler }, { NULL } }; struct SOUND_INFO taito_ym2151_sound[] = { { SOUND_YM2151J, &ym2151_interface, }, { 0, NULL, }, }; void Taito2151_Frame(void) { if(tc0140syt_want_nmi()) cpu_int_nmi(CPU_Z80_0); execute_z80_audio_frame(); } void Taito2151_FrameFast(void) { if(tc0140syt_want_nmi()!=0) cpu_int_nmi(CPU_Z80_0); cpu_execute_cycles(CPU_Z80_0, CPU_FRAME_MHz(6,60)); // Z80 6MHz (60fps) /*#ifdef RAINE_DEBUG print_debug("Z80PC0:%04x\n",z80pc); #endif*/ cpu_interrupt(CPU_Z80_0, 0x38); } void Taito2151_FrameRI(void) { if(tc0140syt_want_nmi()!=0){ if(tc0140syt_get_port01()!=0x00){ // Temp fix for Rainbow Islands cpu_int_nmi(CPU_Z80_0); } } cpu_execute_cycles(CPU_Z80_0, CPU_FRAME_MHz(6,60)); // Z80 6MHz (60fps) /*#ifdef RAINE_DEBUG print_debug("Z80PC0:%04x\n",z80pc); #endif*/ cpu_interrupt(CPU_Z80_0, 0x38); } void Taito2151_Frame_xsystem(void) { /* cpu_execute_cycles(CPU_Z80_0, CPU_FRAME_MHz(8,60)); // Z80 8MHz (60fps) */ /* cpu_interrupt(CPU_Z80_0, 0x38); */ execute_z80_audio_frame(); } void AddTaitoYM2151(UINT32 p1, UINT32 p2, UINT32 romsize, UINT8 *adpcmA, UINT8 *adpcmB) { // Apply Speed Patch // ----------------- Z80ROM[p1+0]=0xD3; // OUTA (AAh) Z80ROM[p1+1]=0xAA; // SetStopZ80Mode2( (UINT16) p2); // Setup rom banking system // ------------------------ AddTaitoSoundBanking(Z80ROM, romsize); // Setup Z80 memory map // -------------------- AddZ80AROMBase(Z80ROM, 0x38, 0x66); AddZ80AReadByte(0x0000, 0x7FFF, NULL, NULL); // BANK ROM AddZ80AReadByte(0x8000, 0x8FFF, NULL, Z80ROM+0x008000); // Z80 RAM AddZ80AReadByte(0x9000, 0x9001, YM2151ReadZ80, NULL); // YM2151 AddZ80AReadByte(0xA000, 0xA001, tc0140syt_read_sub_z80, NULL); // 68000 COMM AddZ80AReadByte(0x0000, 0xFFFF, DefBadReadZ80, NULL); AddZ80AReadByte(-1, -1, NULL, NULL); AddZ80AWriteByte(0x8000, 0x8FFF, NULL, Z80ROM+0x008000); // Z80 RAM AddZ80AWriteByte(0x9000, 0x9001, YM2151TaitoWriteZ80, NULL); // YM2151+BANKING AddZ80AWriteByte(0xA000, 0xA001, tc0140syt_write_sub_z80, NULL); // 68000 COMM if(adpcmA!=NULL){ AddZ80AWriteByte(0xB000, 0xB006, adpcmA, NULL); // ADPCM CHANNEL A } if(adpcmB!=NULL){ AddZ80AWriteByte(0xC000, 0xC006, adpcmB, NULL); // ADPCM CHANNEL B } AddZ80AWriteByte(0x0000, 0xFFFF, DefBadWriteZ80, NULL); AddZ80AWriteByte(-1, -1, NULL, NULL); AddZ80AReadPort(0x00, 0xFF, DefBadReadZ80, NULL); AddZ80AReadPort( -1, -1, NULL, NULL); AddZ80AWritePort(0xAA, 0xAA, StopZ80Mode2, NULL); AddZ80AWritePort(0x00, 0xFF, DefBadWriteZ80, NULL); AddZ80AWritePort( -1, -1, NULL, NULL); AddZ80AInit(); TaitoSoundSetBank(0,1); tc0140syt_reset(); } void AddTaitoYM2151_Timer(UINT32 p1, UINT32 p2, UINT32 romsize, UINT8 *adpcmA, UINT8 *adpcmB) { // Apply Speed Patch // ----------------- Z80ROM[p1+0]=0xD3; // OUTA (AAh) Z80ROM[p1+1]=0xAA; // SetStopZ80Mode2( (UINT16) p2); // Setup rom banking system // ------------------------ AddTaitoSoundBanking(Z80ROM, romsize); // Setup Z80 memory map // -------------------- AddZ80AROMBase(Z80ROM, 0x38, 0x66); AddZ80AReadByte(0x0000, 0x7FFF, NULL, NULL); // BANK ROM AddZ80AReadByte(0x8000, 0x8FFF, NULL, Z80ROM+0x008000); // Z80 RAM AddZ80AReadByte(0x9000, 0x9001, YM2151ReadZ80_Timer, NULL); // YM2151 AddZ80AReadByte(0xA000, 0xA001, tc0140syt_read_sub_z80, NULL); // 68000 COMM AddZ80AReadByte(0x0000, 0xFFFF, DefBadReadZ80, NULL); AddZ80AReadByte(-1, -1, NULL, NULL); AddZ80AWriteByte(0x8000, 0x8FFF, NULL, Z80ROM+0x008000); // Z80 RAM AddZ80AWriteByte(0x9000, 0x9001, YM2151TaitoWriteZ80, NULL); // YM2151+BANKING AddZ80AWriteByte(0xA000, 0xA001, tc0140syt_write_sub_z80, NULL); // 68000 COMM if(adpcmA!=NULL){ AddZ80AWriteByte(0xB000, 0xB006, adpcmA, NULL); // ADPCM CHANNEL A } if(adpcmB!=NULL){ AddZ80AWriteByte(0xC000, 0xC006, adpcmB, NULL); // ADPCM CHANNEL B } AddZ80AWriteByte(0x0000, 0xFFFF, DefBadWriteZ80, NULL); AddZ80AWriteByte(-1, -1, NULL, NULL); AddZ80AReadPort(0x00, 0xFF, DefBadReadZ80, NULL); AddZ80AReadPort( -1, -1, NULL, NULL); AddZ80AWritePort(0xAA, 0xAA, StopZ80Mode2, NULL); AddZ80AWritePort(0x00, 0xFF, DefBadWriteZ80, NULL); AddZ80AWritePort( -1, -1, NULL, NULL); AddZ80AInit(); TaitoSoundSetBank(0,1); tc0140syt_reset(); } /* more recent memory map: - it resembles the ym2610 one - banking is not via ym2151 - no nmi (nmi will reset the cpu) - ym30xx volume and panning support? */ void AddTaitoYM2151_xsystem(UINT32 p1, UINT32 p2, UINT32 romsize) { // Apply Speed Patch // ----------------- Z80ROM[p1+0]=0xD3; // OUTA (AAh) Z80ROM[p1+1]=0xAA; // SetStopZ80Mode2( (UINT16) p2); // Setup rom banking system // ------------------------ AddTaitoSoundBanking(Z80ROM, romsize); // Setup Z80 memory map // -------------------- AddZ80AROMBase(Z80ROM, 0x38, 0x66); AddZ80AReadByte(0x0000, 0x7FFF, NULL, NULL); // BANK ROM AddZ80AReadByte(0xC000, 0xDFFF, NULL, Z80ROM+0x00C000); // Z80 RAM AddZ80AReadByte(0xE000, 0xE001, YM2151ReadZ80_Timer, NULL); // YM2610 AddZ80AReadByte(0xE200, 0xE201, tc0140syt_read_sub_z80, NULL); // 68000 COMM //AddZ80AReadByte(0xEA00, 0xEA00, TaitoYM2610Test, NULL); AddZ80AReadByte(0x0000, 0xFFFF, DefBadReadZ80, NULL); AddZ80AReadByte( -1, -1, NULL, NULL); AddZ80AWriteByte(0xC000, 0xDFFF, NULL, Z80ROM+0x00C000); // Z80 RAM AddZ80AWriteByte(0xE000, 0xE001, YM2151WriteZ80, NULL); // YM2610 AddZ80AWriteByte(0xE200, 0xE201, tc0140syt_write_sub_z80, NULL); // 68000 COMM //AddZ80AWriteByte(0xE400, 0xE403, Pan2610WriteZ80_OffsetVol,NULL); // PANNING AddZ80AWriteByte(0xF200, 0xF200, TaitoSoundSetBank, NULL); // BANK SELECT AddZ80AWriteByte(0x0000, 0xFFFF, DefBadWriteZ80, NULL); AddZ80AWriteByte( -1, -1, NULL, NULL); AddZ80AReadPort(0x00, 0xFF, DefBadReadZ80, NULL); AddZ80AReadPort( -1, -1, NULL, NULL); AddZ80AWritePort(0xAA, 0xAA, StopZ80Mode2, NULL); AddZ80AWritePort(0x00, 0xFF, DefBadWriteZ80, NULL); AddZ80AWritePort( -1, -1, NULL, NULL); AddZ80AInit(); TaitoSoundSetBank(0,1); tc0140syt_reset(); } void RemoveTaitoYM2151(void) { RemoveTaitoSoundBanking(); } /******************************************************************************/ /* */ /* YM2203; M6295 / Taito B-System */ /* ------------------------------ */ /* */ /* - Master of Weapons, Hit the Ice, Violence Fight */ /* */ /******************************************************************************/ static struct YM2203interface ym2203_interface = { 1, // 1 x YM2203 3000000, // Rate - Guessed { YM2203_VOL(200,50) }, // Volume Control { 0 }, { 0 }, { 0 }, { 0 }, { z80_irq_handler } }; struct SOUND_INFO taito_ym2203_sound[] = { { SOUND_YM2203, &ym2203_interface, }, { 0, NULL, }, }; static struct OKIM6295interface m6295_interface = { 1, // 1 chip { 8500 }, // rate { 0 }, // rom list { 250 }, }; struct SOUND_INFO taito_ym2203_m6295_sound[] = { { SOUND_YM2203, &ym2203_interface, }, { SOUND_M6295, &m6295_interface, }, { 0, NULL, }, }; void M6295_Init(UINT8 *src, UINT32 size) { ADPCMSetBuffers(((struct ADPCMinterface*)&m6295_interface),src,0x40000); } void Taito2203_Frame(void) { execute_z80_audio_frame(); /* cpu_execute_cycles(CPU_Z80_0, (4000000/60)*2); */ /* /\*#ifdef RAINE_DEBUG */ /* print_debug("Z80PC0:%04x\n",z80pc); */ /* #endif*\/ */ /* cpu_interrupt(CPU_Z80_0, 0x0038); */ } void AddTaitoYM2203(UINT32 p1, UINT32 p2, UINT32 romsize, UINT8 *adpcm, UINT32 adpcmsize) { // Apply Speed Patch // ----------------- Z80ROM[p1+0]=0xD3; // OUTA (AAh) Z80ROM[p1+1]=0xAA; // SetStopZ80Mode2( (UINT16) p2); // Setup rom banking system // ------------------------ AddTaitoSoundBanking(Z80ROM, romsize); // Setup Z80 memory map // -------------------- AddZ80AROMBase(Z80ROM, 0x0038, 0x0066); AddZ80AReadByte(0x0000, 0x7FFF, NULL, NULL); // BANK ROM AddZ80AReadByte(0x8000, 0x8FFF, NULL, Z80ROM+0x008000); // Z80 RAM AddZ80AReadByte(0x9000, 0x9001, YM2203AReadZ80, NULL); // YM2203 AddZ80AReadByte(0xA000, 0xA001, tc0140syt_read_sub_z80, NULL); // 68000 COMM if(adpcm!=NULL){ AddZ80AReadByte(0xB000, 0xB000, M6295_A_Read_Z80, NULL); // ADPCM CHANNEL A } AddZ80AReadByte(0x0000, 0xFFFF, DefBadReadZ80, NULL); AddZ80AReadByte(-1, -1, NULL, NULL); AddZ80AWriteByte(0x8000, 0x8FFF, NULL, Z80ROM+0x008000); // Z80 RAM AddZ80AWriteByte(0x9000, 0x9001, YM2203ATaitoWriteZ80, NULL); // YM2203+BANK SELECT AddZ80AWriteByte(0xA000, 0xA001, tc0140syt_write_sub_z80, NULL); // 68000 COMM if(adpcm!=NULL){ AddZ80AWriteByte(0xB000, 0xB000, M6295_A_Write_Z80, NULL); // ADPCM CHANNEL A } AddZ80AWriteByte(0x0000, 0xFFFF, DefBadWriteZ80, NULL); AddZ80AWriteByte(-1, -1, NULL, NULL); AddZ80AReadPort(0x00, 0xFF, DefBadReadZ80, NULL); AddZ80AReadPort( -1, -1, NULL, NULL); AddZ80AWritePort(0xAA, 0xAA, StopZ80Mode2, NULL); AddZ80AWritePort(0x00, 0xFF, DefBadWriteZ80, NULL); AddZ80AWritePort( -1, -1, NULL, NULL); AddZ80AInit(); TaitoSoundSetBank(0,1); tc0140syt_reset(); // Setup M6295 // ----------- if(adpcm) M6295_Init(adpcm, adpcmsize); // ExecuteSoundFrame=&Taito2203_Frame; } // Diff Memory Map [L-System Fighting Hawk] void AddTaitoYM2203_B(UINT32 p1, UINT32 p2, UINT32 romsize, UINT8 *adpcm, UINT32 adpcmsize) { // Apply Speed Patch // ----------------- Z80ROM[p1+0]=0xD3; // OUTA (AAh) Z80ROM[p1+1]=0xAA; // SetStopZ80Mode2( (UINT16) p2); // Setup rom banking system // ------------------------ AddTaitoSoundBanking(Z80ROM, romsize); // Setup Z80 memory map // -------------------- AddZ80AROMBase(Z80ROM, 0x0038, 0x0066); AddZ80AReadByte(0x0000, 0x7FFF, NULL, NULL); // BANK ROM AddZ80AReadByte(0x8000, 0x9FFF, NULL, Z80ROM+0x008000); // Z80 RAM AddZ80AReadByte(0xF000, 0xF001, YM2203AReadZ80, NULL); // YM2203 AddZ80AReadByte(0xE000, 0xE001, tc0140syt_read_sub_z80, NULL); // 68000 COMM if(adpcm!=NULL){ AddZ80AReadByte(0xB000, 0xB000, M6295_A_Read_Z80, NULL); // ADPCM CHANNEL A } AddZ80AReadByte(0x0000, 0xFFFF, DefBadReadZ80, NULL); AddZ80AReadByte(-1, -1, NULL, NULL); AddZ80AWriteByte(0x8000, 0x9FFF, NULL, Z80ROM+0x008000); // Z80 RAM AddZ80AWriteByte(0xF000, 0xF001, YM2203ATaitoWriteZ80, NULL); // YM2203+BANK SELECT AddZ80AWriteByte(0xE000, 0xE001, tc0140syt_write_sub_z80, NULL); // 68000 COMM if(adpcm!=NULL){ AddZ80AWriteByte(0xB000, 0xB000, M6295_A_Write_Z80, NULL); // ADPCM CHANNEL A } AddZ80AWriteByte(0x0000, 0xFFFF, DefBadWriteZ80, NULL); AddZ80AWriteByte(-1, -1, NULL, NULL); AddZ80AReadPort(0x00, 0xFF, DefBadReadZ80, NULL); AddZ80AReadPort( -1, -1, NULL, NULL); AddZ80AWritePort(0xAA, 0xAA, StopZ80Mode2, NULL); AddZ80AWritePort(0x00, 0xFF, DefBadWriteZ80, NULL); AddZ80AWritePort( -1, -1, NULL, NULL); AddZ80AInit(); TaitoSoundSetBank(0,1); tc0140syt_reset(); // Setup M6295 // ----------- if(adpcm) M6295_Init(adpcm, adpcmsize); // ExecuteSoundFrame=&Taito2203_Frame; } void RemoveTaitoYM2203(void) { RemoveTaitoSoundBanking(); } /************************************************************/ /* Taito Z80 Banking interface */ /* --------------------------- */ /* For 99% of Taito sound Z80s */ /************************************************************/ // AddTaitoSoundBanking(): // Setup bank buffer void AddTaitoSoundBanking(UINT8 *romsrc, UINT32 romsize) { if (load_region[REGION_CPU2]) { z80_init_banks(0,REGION_CPU2,0x4000,0x4000); } else { int ta; // Make a copy of the rom banks ROMBANK = AllocateMem(romsize*2); if(romsize==0x08000){ for(ta=0;ta<2;ta++){ BANKLIST[ta+0] = ROMBANK+(ta*0x8000); BANKLIST[ta+2] = ROMBANK+(ta*0x8000); BANKLIST[ta+4] = ROMBANK+(ta*0x8000); BANKLIST[ta+6] = ROMBANK+(ta*0x8000); memcpy(BANKLIST[ta]+0x0000,romsrc, 0x4000); memcpy(BANKLIST[ta]+0x4000,romsrc+(ta*0x4000),0x4000); } } if(romsize==0x10000){ for(ta=0;ta<4;ta++){ BANKLIST[ta+0] = ROMBANK+(ta*0x8000); BANKLIST[ta+4] = ROMBANK+(ta*0x8000); memcpy(BANKLIST[ta]+0x0000,romsrc, 0x4000); memcpy(BANKLIST[ta]+0x4000,romsrc+(ta*0x4000),0x4000); } } if(romsize==0x20000){ for(ta=0;ta<8;ta++){ BANKLIST[ta] = ROMBANK+(ta*0x8000); memcpy(BANKLIST[ta]+0x0000,romsrc, 0x4000); memcpy(BANKLIST[ta]+0x4000,romsrc+(ta*0x4000),0x4000); } } } } // RemoveTaitoSoundBanking(): // Remove bank buffer void RemoveTaitoSoundBanking(void) { if (ROMBANK) { FreeMem(ROMBANK); ROMBANK=NULL; } } // TaitoSoundSetBank(): // switch the current rom bank (0-7) void TaitoSoundSetBank(UINT16 offset, UINT8 data) { if (load_region[REGION_CPU2]) { z80_set_bank(0,(data-1) & 7); } else { Z80ASetBank( BANKLIST[data&7] ); } } void YM2610SetBuffers(UINT8 *bufa, UINT8 *bufb, UINT32 sizea, UINT32 sizeb) { YM2610_Rompointers[0] = bufa; YM2610_Rompointers[1] = bufb; YM2610_Romsizes[0] = sizea; YM2610_Romsizes[1] = sizeb; } /**********************************************************/ // First OKI 6295 void M6295_A_Write_68k( UINT32 address, UINT16 data ) { OKIM6295_data_0_w( 0, data&0xFF ); } UINT16 M6295_A_Read_68k( UINT32 address ) { return 0; //OKIM6295_status_0_r( 0 ); } void M6295_A_WriteBank_68k(UINT32 address,UINT16 data) { // bankswitch OKIM6295_bankswitch(0,data); } // Second OKI 6295 void M6295_B_Write_68k( UINT32 address, UINT16 data ) { OKIM6295_data_1_w( 1, data&0xFF ); } UINT16 M6295_B_Read_68k( UINT32 address ) { return 0; //OKIM6295_status_1_r( 1 ); } void M6295_B_WriteBank_68k( UINT32 address, UINT16 data ){ OKIM6295_bankswitch(1,data); } /**********************************************************/ // First OKI 6295 void M6295_A_Write_Z80(UINT16 offset, UINT8 data) { OKIM6295_data_0_w( 0, data ); } UINT16 M6295_A_Read_Z80(UINT16 offset) { return OKIM6295_status_0_r( 0 ); } UINT16 M6295_A_ReadFree_Z80(UINT16 offset) { return(0x00); } void M6295_A_WriteBank_Z80(UINT16 offset, UINT8 data){ OKIM6295_bankswitch(0,data); }
9ff3e405bb15b0c50e30d08310408089ba373028
6ff85b80c6fe1b3ad5416a304b93551a5e80de10
/C/Typing/Format.c
0f311be151f88917c9eb7078756636a30952eefd
[ "MIT" ]
permissive
maniero/SOpt
c600cc2333e0a47ce013be3516bbb8080502ff2a
5d17e1a9cbf115eaea6d30af2079d0c92ffff7a3
refs/heads/master
2023-08-10T16:48:46.058739
2023-08-10T13:42:17
2023-08-10T13:42:17
78,631,930
1,002
136
MIT
2023-01-28T12:10:01
2017-01-11T11:19:24
C#
UTF-8
C
false
false
857
c
Format.c
#include <stdio.h> int main() { int idade = 0, cont50 = 0, espantalho = 0; float peso = 0.0, altura = 0.0, md = 0.0, mdpeso = 0.0; for (int i = 1; i < 3; i++) { printf("\nDigite a sua idade :"); scanf("%d", &idade); printf("Digite a sua altura :"); scanf("%f", &altura); printf("Digite seu peso :"); scanf("%f", &peso); if (idade > 50) cont50++; if (idade >= 10 && idade <= 20) md += altura / 2; if (peso < 40) espantalho++; mdpeso = (espantalho / 2.0) * 100; } printf("\nO total de pessoas com idade superior a 50 e %d", cont50); printf("\nA media das alturas de pessoas com idade entre 10 e 20 anos e %.1f", md); printf("\nA porcentagem de pessoas com peso inferior a 40 kg e %f porcento", mdpeso); } //https://pt.stackoverflow.com/q/127994/101
db04071b3c1dfe8b80d88ff0a7eba2290adf14bf
33cec2206eb49a1001af848dec4f7179036a4872
/demos/esp32_spi_flash/components/FlashDB/inc/fal_cfg.h
fa1342a3c1ed544e1373cc3b729fafc66ddff28a
[ "Apache-2.0" ]
permissive
armink/FlashDB
c38bc39d98fea14a97da2d019be6cb7df1512d3b
3e441f6c26590eb86051826830b19a715d3d7423
refs/heads/master
2023-08-23T03:11:32.516136
2023-08-17T10:01:48
2023-08-17T10:01:48
266,515,876
1,379
339
Apache-2.0
2023-08-17T10:01:49
2020-05-24T10:15:56
C
UTF-8
C
false
false
1,137
h
fal_cfg.h
/* * Copyright (c) 2022, kaans, <https://github.com/kaans> * * SPDX-License-Identifier: Apache-2.0 */ #ifndef _FAL_CFG_H_ #define _FAL_CFG_H_ //#define FAL_DEBUG 1 #define FAL_PART_HAS_TABLE_CFG #define NOR_FLASH_DEV_NAME "norflash0" //#define FAL_PART_TABLE_FLASH_DEV_NAME NOR_FLASH_DEV_NAME //#define FAL_PART_TABLE_END_OFFSET 65536 /* ===================== Flash device Configuration ========================= */ extern const struct fal_flash_dev nor_flash0; /* flash device table */ #define FAL_FLASH_DEV_TABLE \ { \ &nor_flash0, \ } /* ====================== Partition Configuration ========================== */ #ifdef FAL_PART_HAS_TABLE_CFG /* partition table */ #define FAL_PART_TABLE \ { \ {FAL_PART_MAGIC_WORD, "fdb_kvdb1", NOR_FLASH_DEV_NAME, 0, 16 * 1024, 0}, \ {FAL_PART_MAGIC_WORD, "fdb_tsdb1", NOR_FLASH_DEV_NAME, 16 * 1024, 16 * 1024, 0}, \ } #endif /* FAL_PART_HAS_TABLE_CFG */ #endif /* _FAL_CFG_H_ */
a961f9f03413c3e3679e51c52486e98619747acd
bb38c44037a99d0a12a12d92059678f2faebbc80
/src/include/executor/node/nodeHash.h
94768b5701cb73c3931fa6653e6dea479b354b0c
[ "LicenseRef-scancode-mulanpsl-2.0-en", "LicenseRef-scancode-unknown-license-reference", "PostgreSQL", "BSD-3-Clause", "LGPL-2.0-or-later", "LicenseRef-scancode-unicode", "LicenseRef-scancode-warranty-disclaimer", "curl", "GPL-1.0-or-later", "LGPL-2.1-or-later", "LGPL-2.1-only", "CC-BY-4.0", "LicenseRef-scancode-protobuf", "OpenSSL", "LicenseRef-scancode-generic-export-compliance", "X11-distribute-modifications-variant", "LicenseRef-scancode-other-permissive", "MIT", "NCSA", "Python-2.0", "LicenseRef-scancode-openssl", "LicenseRef-scancode-ssleay-windows", "CC-BY-3.0", "LicenseRef-scancode-other-copyleft", "GPL-2.0-only", "BSL-1.0", "Apache-2.0", "LGPL-2.0-only", "LicenseRef-scancode-public-domain", "BSD-2-Clause", "Zlib" ]
permissive
opengauss-mirror/openGauss-server
a9c5a62908643492347830826c56da49f0942796
310e84631c68c8bf37b004148b66f94064f701e4
refs/heads/master
2023-07-26T19:29:12.495484
2023-07-17T12:23:32
2023-07-17T12:23:32
276,117,477
591
208
MulanPSL-2.0
2023-04-28T12:30:18
2020-06-30T14:08:59
C++
UTF-8
C
false
false
2,729
h
nodeHash.h
/* ------------------------------------------------------------------------- * * nodeHash.h * prototypes for nodeHash.c * * * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * src/include/executor/nodeHash.h * * ------------------------------------------------------------------------- */ #ifndef NODEHASH_H #define NODEHASH_H #include "nodes/execnodes.h" #include "nodes/relation.h" #define MIN_HASH_BUCKET_SIZE 32768 /* min bucketsize for hash join */ #define BUCKET_OVERHEAD 8 extern HashState* ExecInitHash(Hash* node, EState* estate, int eflags); extern Node* MultiExecHash(HashState* node); extern void ExecEndHash(HashState* node); extern void ExecReScanHash(HashState* node); extern HashJoinTable ExecHashTableCreate(Hash* node, List* hashOperators, bool keepNulls, List *hash_collations); extern void ExecHashTableDestroy(HashJoinTable hashtable); extern void ExecHashTableInsert(HashJoinTable hashtable, TupleTableSlot* slot, uint32 hashvalue, int planid, int dop, Instrumentation* instrument = NULL); extern bool ExecHashGetHashValue(HashJoinTable hashtable, ExprContext* econtext, List* hashkeys, bool outer_tuple, bool keep_nulls, uint32* hashvalue); extern void ExecHashGetBucketAndBatch(HashJoinTable hashtable, uint32 hashvalue, int* bucketno, int* batchno); extern bool ExecScanHashBucket(HashJoinState* hjstate, ExprContext* econtext); extern void ExecPrepHashTableForUnmatched(HashJoinState* hjstate); extern bool ExecScanHashTableForUnmatched(HashJoinState* hjstate, ExprContext* econtext); extern void ExecHashTableReset(HashJoinTable hashtable); extern void ExecHashTableResetMatchFlags(HashJoinTable hashtable); extern void ExecChooseHashTableSize(double ntuples, int tupwidth, bool useskew, int* numbuckets, int* numbatches, int* num_skew_mcvs, int4 localWorkMem, bool vectorized = false, OpMemInfo* memInfo = NULL); extern double ExecChooseHashTableMaxTuples(int tupwidth, bool useskew, bool vectorized, double hash_table_bytes); extern int ExecHashGetSkewBucket(HashJoinTable hashtable, uint32 hashvalue); extern void ExecHashTableStats(HashJoinTable hashtable, int planid); extern int ExecSonicHashGetAtomTypeSize(Oid typeOid, int typeMod, bool isHashKey); extern int64 ExecSonicHashGetAtomArrayBytes( double ntuples, int m_arrSize, int m_atomSize, int64 atomTypeSize, bool hasNullFlag); extern void ExecChooseSonicHashTableSize(Path* inner_path, List* hashclauses, int* inner_width, bool isComplicateHashKey, int* numbuckets, int* numbatches, int4 localWorkMem, OpMemInfo* memInfo, int dop); extern uint8 EstimateBucketTypeSize(int nbuckets); #endif /* NODEHASH_H */